import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Observer implements ActionListener { private JTextField outputField; private boolean toDeg; public Observer(boolean toDeg) { this.toDeg = toDeg; } public void setOutputField(JTextField f) { outputField = f; } public void actionPerformed(ActionEvent ev) { try { float temp = Float.parseFloat(ev.getActionCommand()); if (toDeg) { temp -= 32f; temp *= 5f/9f; } else { temp *= 9f/5f; temp += 32f; } outputField.setText(Float.toString(temp)); } catch (NumberFormatException ex) { outputField.setText("???"); } } }