import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.*;
import javax.swing.JOptionPane;
public class changeNumto extends Frame{
Button b = new Button("Change");
Label l1 = new Label("Decimal");
Label l2 = new Label("binary");
Label l3 = new Label("octal");
Label l4 = new Label("hex");
int binary1,octal1,hex1;
int x, y;
TextField tf1 = new TextField(null, 10);
TextField tf2 = new TextField(null, 10);
TextField tf3 = new TextField(null, 10);
TextField tf4 = new TextField(null, 10);
public changeNumto() {
super("changeNum");
setLayout(new FlowLayout(FlowLayout.LEFT));
add(l1);
add(tf1);
add(l2);
add(tf2);
add(l3);
add(tf3);
add(l4);
add(tf4);
add(b);
pack();
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());
}
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (tf1.getText() != null) {
try {
x = Integer.parseInt(tf1.getText());
tf2.setText("" + Integer.toBinaryString(x));
tf3.setText("" + Integer.toOctalString(x));
tf4.setText("" + Integer.toHexString(x));
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(l1, "You input is not a int, please input a int");
}
}
}
}
public static void main(String[] args) {
new changeNumto();
}
}