actionPerformed一般是用来给Button监听的,你用到TextField上是什么意思

解决方案 »

  1.   

    你的paint(Graphics g)的逻辑有点乱,你是不是要显示排序的过程,如果我的猜测是对的话,可以这样修改,我只修该了paint(Graphics g)成员函数: //<APPLET CODE=Gm HEIGHT=500 WIDTH=500></APPLET>
    import java.awt.*;
               import java.applet.*;
               import java.awt.event.*;
               
               public class Gm extends Applet implements ActionListener{
               Label p1;
               TextField input1;
               Label p2;
               TextField input2;
               Label p3;
               TextField input3;
               int a,b,c,d;
           
               public void init(){
               p1=new Label("Enter the first num:");
               input1=new TextField(4);
               p2=new Label("Enter the second num:");
               input2=new TextField(4);
              p3=new Label("Enter the second num:");
               input3=new TextField(4);
               add(p1);
               add(input1);
               add(p2);
               add(input2);
               add(p3);
               add(input3);
               input1.addActionListener(this);
               input2.addActionListener(this);
               input3.addActionListener(this);
               }           public void paint(Graphics g){
               g.drawString("the result is:",25,60);
       if(a>b){
       d=a;a=b;b=d;
       }
       g.drawString(a+" "+b+" "+c,25,80);
       if(b>c){
       d=b;b=c;c=d;
       }
       g.drawString(a+" "+b+" "+c,25,100);
       if(a>b){
       d=a;a=b;b=d;
       }
       g.drawString(a+" "+b+" "+c,25,120);
                     
            }
                public void actionPerformed(ActionEvent e){
                 a=Integer.parseInt(input1.getText());
                 input1.setText("");
                 b=Integer.parseInt(input2.getText());
                 input2.setText("");
                 c=Integer.parseInt(input3.getText());
                input3.setText("");
                repaint();
             }
       }