00001 package jpl.test;
00002
00008 import java.awt.*;
00009 import java.awt.event.*;
00010 import javax.swing.*;
00011
00012 public class CelsiusConverter implements ActionListener {
00013 JFrame converterFrame;
00014 JPanel converterPanel;
00015 JTextField tempCelsius;
00016 JLabel celsiusLabel, fahrenheitLabel;
00017 JButton convertTemp;
00018 public CelsiusConverter() {
00019 this(0, 0);
00020 }
00021 public CelsiusConverter(int left, int top) {
00022
00023 converterFrame = new JFrame("Convert Celsius to Fahrenheit");
00024 converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00025 converterFrame.setSize(new Dimension(120, 40));
00026 converterFrame.setLocation(left, top);
00027
00028 converterPanel = new JPanel(new GridLayout(2, 2));
00029
00030 tempCelsius = new JTextField(2);
00031 celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT);
00032 celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
00033
00034 convertTemp = new JButton("Convert");
00035 fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);
00036
00037 convertTemp.addActionListener(this);
00038
00039 converterPanel.add(tempCelsius);
00040 converterPanel.add(celsiusLabel);
00041 converterPanel.add(convertTemp);
00042 converterPanel.add(fahrenheitLabel);
00043 fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
00044 converterFrame.getRootPane().setDefaultButton(convertTemp);
00045
00046 converterFrame.getContentPane().add(converterPanel, BorderLayout.CENTER);
00047
00048 converterFrame.pack();
00049 converterFrame.setVisible(true);
00050 }
00051 public void actionPerformed(ActionEvent event) {
00052
00053 double tC = (Double.parseDouble(tempCelsius.getText()));
00054
00055
00056
00057
00058
00059 int tempFahr = ((jpl.Float) jpl.Query.oneSolution("TF is ? * 1.8 + 32", new jpl.Term[] {new jpl.Float(tC)}).get("TF")).intValue();
00060
00061
00062 fahrenheitLabel.setText(tempFahr + " Fahrenheit");
00063 }
00064 public static void spawnGUI(final int left, final int top) {
00065
00066 javax.swing.SwingUtilities.invokeLater(new Runnable() {
00067 int x = left;
00068 int y = top;
00069 public void run() {
00070 new CelsiusConverter(x, y);
00071 }
00072 });
00073 }
00074 public static void main(String[] args) {
00075
00076 jpl.Query.allSolutions("between(1, 5, N), X is 10*N, Y is 20*N, jpl_call('jpl.test.CelsiusConverter', spawnGUI, [X,Y], _)");
00077 }
00078 }