public void run(){
    while (flag)
    {
         Thread.sleep(1000);
    }
}開始:
flag=true;
mythread.start();暫停:
flag=false;停止:
mythread.stop();

解决方案 »

  1.   

    供参考
    public TreadTest extends Thread{
    private boolean stop = false;
    private boolean pause = false;
    private long count = 0;
    private button pauseButton = new Button("pasue");
    private button stopButton = new Button("stop");
    public ThreadTest(){
    JFrame frame = new JFrame();
    JPanel panel = new Jpanel();
    frame.getContentPane.add(panel);
    panel.add(pauseButton);
    panel.add(stopButton);
    init();
    this.start();
    frame.setDefaultCloseOpertion(JFrame.EXIT_ON_CLOSED);
    frame.show();
    }private void init(){
            pauseButton.addActionListener(new ActionListener(){
             public void actionPerfromed(ActionEvent ae){
                  pause = true;
             }
            });
     stopButton.addActionListener(new ActionListener(){
             public void actionPerfromed(ActionEvent ae){
                  stop = true;
             }
            });        public void run(){
           while(!stop){
              while(!pause){
                try{
                        sleep(1000)
                        count ++;
                   }catch(Excpetion exp){};
              }
           }
        }
    }
    public static void main(String[] args){
     ThreadTest test = new ThreadTest();
    }
    }
      

  2.   

    回jackkui(六级木匠):  无法通过编译.