public class Calc extends Frame implements ActionListener {
TextField text1, text3, text4, text5;
Button btn;
public Calc() {
setLayout(new GridLayout(7, 3));
// 第一行
text1 = new TextField(10);
add(text1);
btn = new Button("do");
btn.addActionListener(this);
add(btn);
text3 = new TextField(30);
add(text3);
text4 = new TextField(30);
add(text4);
text5 = new TextField(30);
add(text5);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(btn)) {
text3.setText("二进制数是:" + String.valueOf(Integer.toBinaryString(Integer.valueOf(text1.getText()))));
text4.setText("八进制数是:" + String.valueOf(Integer.toOctalString(Integer.valueOf(text1.getText()))));
text5.setText("十六进制数是:" + String.valueOf(Integer.toHexString(Integer.valueOf(text1.getText()))).toUpperCase());
}
}
public static void main(String[] agrs) {
Calc my = new Calc();
my.setSize(250, 150);
my.setVisible(true);
}
}