- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- public class Zhuanhuan extends Frame{
- MenuBar menuBar =new MenuBar();
- Panel p1 = new Panel();
- Panel p2 = new Panel();
- Menu m = new Menu("Application");
- Label l1 = new Label("Enter Decimal:");
- Label l2 = new Label("Converted Value:");
- TextField t1 = new TextField(40);
- TextField t2 = new TextField(50);
- Button b1 = new Button("Binary");
- Button b2 = new Button("Octal");
- Button b3 = new Button("Hex");
- Button b4 = new Button("Base36");
- public Zhuanhuan (){
- this.setMenuBar(menuBar);
- menuBar.add(m);
- this.setLayout(new FlowLayout());
- this.add(l1);
- this.add(t1);
- this.add(l2);
- this.add(t2);
- this.add(p2);
- p2.setLayout(new GridLayout(1,4));
- p2.add(b1);
- p2.add(b2);
- p2.add(b3);
- p2.add(b4);
- this.setSize(500,200);
- this.setLocationRelativeTo(null);
- this.setVisible(true);
- this.addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent e){
- Zhuanhuan.this.dispose();
- }
- });
- }
- public void addactionlistener(){
- b1.addActionListener(buttonhandler);
- b2.addActionListener(buttonhandler);
- b3.addActionListener(buttonhandler);
- b4.addActionListener(buttonhandler);
- }
- ActionListener buttonhandler = new ActionListener(){
- public void actionPerformed(ActionEvent e){
- if(e.getSource() == b1){
- int tz1 = Integer.parseInt(t1.getText());
- //t2.setEditable(true);
- t2.setText(Integer.toString(tz1,2));
- }
- else if(e.getSource() == b2){
- int tz1 = Integer.parseInt(t1.getText());
- t2.setText(Integer.toString(tz1,8));
- }
- else if(e.getSource() == b3){
- int tz1 = Integer.parseInt(t1.getText());
- t2.setText(Integer.toString(tz1,16));
- }
- else if(e.getSource() == b4){
- int tz1 = Integer.parseInt(t1.getText());
- t2.setText(Integer.toString(tz1,36));
- }
- }
- };
- public static void main(String[] args) {
- new Zhuanhuan();
- }
- }
复制代码 |
|