编程语言

img heizao1981

哪为前辈指点一下~~我写的抽奖循环不知道该如何跳出

发表于2004/11/2 10:28:00  454人阅读

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

public class CheckNumber implements ActionListener, KeyListener{
  Frame f = new Frame();
  TextField t = new TextField();
  public CheckNumber(){

    Label lb=new Label("手机号抽取");
    Panel p = new Panel();

   t.setColumns(20);
    p.add(t);
    Panel p1 = new Panel();
   p1.setLayout(new GridLayout(1,2));
    Button b0 = new Button("开始抽奖");
    b0.setActionCommand("Start");
    Button b1 = new Button("停止");
    b1.setActionCommand("Stop");
    p1.add(b0);
    p1.add(b1);
   b0.addActionListener(this);
   b1.addActionListener(this);
   f.add(lb,"North");
    f.add(p,"Center");
    f.add(p1,"South");
    f.addKeyListener(this);
   f.setSize(200,150);
   f.setVisible(true);

 //窗口关闭
    f.addWindowListener(new WindowAdapter(){
       public void windowClosing(WindowEvent e){
       System.exit(0);
       }
    });
  }
  public static void main(String[] args){
    CheckNumber ck=new CheckNumber();
  }
  public void actionPerformed(ActionEvent e){
   String[] a;
   a=new String[1000];
   a[0]="13810092000";a[1]="13114292001";a[2]="13700152002";
   a[3]="13810092003";a[4]="15489957226";a[5]="13359875005";
   a[6]="45678167889";a[7]="13454687787";a[8]="13878946512";
   a[9]="12457848897";

    if(e.getActionCommand().equals("Start")){
     for(;true;){
        int i=0;
        while(i<=9){
          t.setText(a[i]); 
              if(e.getActionCommand().equals("Stop"))
              break last;
          try{
              Thread.sleep (40); //休眠40毫秒 
           } catch (InterruptedException ex){}
           i++;             
        }
     } 
    }
  }
}

阅读全文
0 0

相关文章推荐

img
取 消
img