结果不就应该是very good!,no,please try again,Excellent,wrong.try once more,nice work,don't give up,keep up ths good work,no,keep trying这些话中的一句吗?

解决方案 »

  1.   

    懂你的意思了:在applet第一次加载并运行时,paint()方法会被调用,此时就会执行switch(d4){......}这段代码,得到的自然是这些话中的一句了
      

  2.   

    你可以在paint()方法中首先判断applet是不是第一次加载运行,也就是说paint()是不是第一次被调用,若不是第一次调用,才执行switch代码段
      

  3.   

    在类z(你这种类的命名法是不规范的)中加入boolean变量firstUse,在init()方法中将firstUse=true,paint()方法:
    if (!firstUse){
      switch(d4){
        ……
      }
      firstUse = false;
    }
      

  4.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class z extends JApplet implements ActionListener
    { JLabel l,l1,l2;
      JTextField t,t1,t2;
      int a;
      int d1=1+(int)(Math.random()*10);
      int d2=1+(int)(Math.random()*10);
      boolean firstUse;
      public void init()
      { firstUse=true;
        Container c=getContentPane();
        c.setLayout(new FlowLayout());
        l=new JLabel("result");
        c.add(l);
        t=new JTextField(10);
        t.addActionListener(this);
        c.add(t);
        l1=new JLabel("how much ");
        c.add(l1);
        t1=new JTextField(10);
        t1.setEditable(false);
        t1.setText(Integer.toString(d1));
        c.add(t1);
        l2=new JLabel("times");
        c.add(l2);
        t2=new JTextField(10);
        t2.setEditable(false);
        t2.setText(Integer.toString(d2));
        c.add(t2);
      } 
      public void actionPerformed(ActionEvent e)
      { int x=Integer.parseInt(e.getActionCommand());
        a=x;
      }
      public int Abcd()
      { int d3,z,x;
        z=Integer.parseInt(t1.getText());
        x=Integer.parseInt(t2.getText());
        d3=z*x;
        return d3;
      }
      public void paint(Graphics g)
      { int d4=1+(int)(Math.random()*4);
        if (!firstUse)
        {
         switch(d4)
          {case 1:
              if(a==Abcd())
                 showStatus("very good!");
              else
                 showStatus("no,please try again.");
                 break;
           case 2:
              if(a==Abcd())
                 showStatus("Excellent");
              else
                 showStatus("wrong.try once more.");
                 break;
           case 3:
              if(a==Abcd())
                 showStatus("nice work!");
              else
                 showStatus("don't give up!");
                 break;
           case 4:
              if(a==Abcd())
                 showStatus("keep up ths good work!");
              else
                 showStatus("no,keep trying.");
                 break;
           }
           firstUse = false;  
        } 
      }
    }
      

  5.   

    那就将现在写在paint()方法里的动作不要写在paint()里了,另外写成个方法,在actionPerformed()中调用,试试
      

  6.   

    jiangnanyuzi(江南愚子)兄的我试了,没用,请高手们再帮我看看