package 跑;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class JinZhi extends JFrame implements ActionListener{
JLabel jl1,jl2,jl3,jl4;
JTextField jt1,jt2,jt3,jt4;
public JinZhi(){
super("十進制轉換");
setBounds(200,100,200,100);
setLayout(new GridLayout(4,2));
add(new JLabel("十進制"));
jt1=new JTextField("1023");
jt1.addActionListener(this);
add(jt1);
add(new JLabel("二進制"));
jt2=new JTextField("1111111111");
jt2.setEditable(false);
add(jt2);
add(new JLabel("八進制"));
jt3=new JTextField("1777");
jt3.setEditable(false);
add(jt3);
add(new JLabel("十六進制"));
jt3=new JTextField("3ff");
jt4.setEditable(false);
add(jt4);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String s=jt1.getText();
int a=Integer.parseInt(s);
jt2.setText(Integer.toBinaryString(a));
jt3.setText(Integer.toOctalString(a));
jt4.setText(Integer.toHexString(a));
}
public static void main(String []args){
new JinZhi();
}
}
jt3=new JTextField("3ff");
應該是jt4