一个关于线程控制的问题。急!!!!!!!!! 你的flag在第一次 MyThread mt=new MyThread(flag);传出,然后再改时是不能传出去的.试试下法: while(TestThread.flag)... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 帮你修改了一下,可以运行import java.awt.*;import java.awt.event.*;import javax.swing.*;class TestThread extends JFrame{ static boolean flag; JButton jb=new JButton("click"); TestThread() { Container contentPane=getContentPane(); contentPane.add(jb); jb.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ flag=false; } }); } public static void main(String[] args) { flag=true; TestThread t=new TestThread(); t.setBounds(100,100,200,200); t.setVisible(true); t.setDefaultCloseOperation(EXIT_ON_CLOSE); MyThread mt=t.new MyThread(); mt.start(); } class MyThread extends Thread { int i=0; MyThread() { } public void run() { while(flag) { System.out.println("flag="+flag+" "+i++); if(i>3)i=0; try{ Thread.sleep(200); synchronized(this){ while(!flag){ wait(); } } }catch(Exception e){} } } }} 解析大量数据的excel2007怎么获取列的类型 Java语言博客群发软件开发 分享一个文件编辑器 各位看看我这程序错在哪里? 循环和依次执行 io问题 上转型对象的问题(见扫描) 学JAVA也累,可以边学边赚钱! JTable 和数据库连用的问题!!急,在线等待! Orion是不是真的完全免费呀?(快来得分!) 免费邮件服务! 怎么样取出一个数据表中的字段的数据与非数据库中的数据比较
import java.awt.event.*;
import javax.swing.*;
class TestThread extends JFrame
{
static boolean flag;
JButton jb=new JButton("click"); TestThread()
{
Container contentPane=getContentPane();
contentPane.add(jb);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
flag=false;
}
});
}
public static void main(String[] args)
{
flag=true;
TestThread t=new TestThread();
t.setBounds(100,100,200,200);
t.setVisible(true);
t.setDefaultCloseOperation(EXIT_ON_CLOSE);
MyThread mt=t.new MyThread();
mt.start();
} class MyThread extends Thread
{
int i=0;
MyThread()
{
}
public void run()
{
while(flag)
{
System.out.println("flag="+flag+" "+i++);
if(i>3)i=0;
try{
Thread.sleep(200);
synchronized(this){
while(!flag){
wait();
}
}
}catch(Exception e){}
}
}
}
}