关于JAVA的简单问题(NO1)

来源:互联网 发布:沃尔沃北极星软件 编辑:程序博客网 时间:2024/05/19 02:30

        最新学JAVA GUI  学着做!!!

        可是有点问题 高手帮我一下吧 谢谢!!!

        源代码如下:

       import java.awt.*;
       import java.awt.event.*;

       class GG1 {

       public static void main(String[] args)

                   {
                   new frame1("小游戏");

                   }

       }

       class frame1 extends Frame implements WindowListener {

        private static final long serialVersionUID = 4829859849379317456L;

        double k;

        double a = (double) Math.random() * 100;

        TextField t1;  TextField t2;  TextField t3;

        Button b1;

        frame1(String s) {
        setSize(50, 100);

        t1 = new TextField("请输入数字:");
        t2 = new TextField("次数");
        t3 = new TextField("判断");

        b1 = new Button("Enter");
        setLocation(100, 100);
        addWindowListener(this);

        add(t1, BorderLayout.NORTH);

        add(t2, BorderLayout.CENTER);
        add(t3, BorderLayout.SOUTH);
        add(b1, BorderLayout.EAST);
        setVisible(true);

         t1.addActionListener((ActionListener) this);
         t2.addActionListener((ActionListener) this);
         t3.addActionListener((ActionListener) this);
         b1.addActionListener((ActionListener) this);

         }

        public void actionPerformed(ActionEvent e) {
        if (e.getSource() == b1) {
                   try {
                         k = Double.parseDouble(t1.getText());
                        }

                  catch (Exception ee) {
                            ee.getStackTrace();
                        }

                     if (k > a)
                     t3.setText("大了");
                     if (k < a)
                     t3.setText("小了");
                     if (k > a)
                     t3.setText("正确");
                     }
        }

 public void windowActivated(WindowEvent arg0) {

 }

 public void windowClosed(WindowEvent arg0) {

 }

 public void windowClosing(WindowEvent arg0) {
  System.exit(0);

 }

 public void windowDeactivated(WindowEvent arg0) {

 }

 public void windowDeiconified(WindowEvent arg0) {

 }

 public void windowIconified(WindowEvent arg0) {

 }

 public void windowOpened(WindowEvent arg0) {

 }
}

 

为什么总是不能响应呢?

高手指点一下吧!!!

 

原创粉丝点击