APL/APL2.1/TP12/Degrés/Observer.java
2022-04-12 17:16:22 +02:00

35 lines
814 B
Java

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("???");
}
}
}