一道简单的多线程题, 给个思路好吗? public void run(){ while (flag) { Thread.sleep(1000); }}開始:flag=true;mythread.start();暫停:flag=false;停止:mythread.stop(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 供参考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();}} 回jackkui(六级木匠): 无法通过编译. lucene-2.1.0-src.tar.gz 他这个扩展名是什么意思。。 linux下如何实现应用程序不显示界面 HttpClient问题 初学Java ,碰到一个不解的问题,请教一下高手,关于classpath ResultSet把值存到数组取出问题!新手,大家帮帮我啊!~~~ 高手快来帮助我这个菜鸟啊!! 关于在startup.bat中设置环境变量的问题 FileDialog和JFileChooser,判断文件名为非法字符 错为啥有错 javassit 获取方法参数错位 在线等待求助Java~! 关于异常的几点疑惑 请进!!
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();
}
}