线程实在搞不定了!!!help!!!
/*
我想向您请教一个关于JAVA线程的问题,就是我的这个程序运行时什么反应也没有,我想让一个文本框里面的数每10毫秒自增加1,可是当START按下去之后却起不来了,看了好长时间却不知道是什么地方出错了,感激不尽!!!!
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class dis extends JFrame
{
JTextField t;
JButton b1;
JButton b2;
Thread th;
public boolean runFlag = true;
int count = 0;
public dis()
{
try
{
b1=new JButton();
b2=new JButton();
b1.addActionListener(new on());
b2.addActionListener(new off());
b1.setText("START");
b2.setText("STOP");
t=new JTextField(10);
th=new Thread();
th.start();
this.getContentPane().setLayout(null);
t.setSize(130,30);
b1.setBounds(2,50,80,20);
b2.setBounds(89,50,70,20);
getContentPane().add(t);
getContentPane().add(b1);
getContentPane().add(b2);
this.setBounds(100,100,190,130);
this.setVisible(true);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void go()
{
for(int a=1;;a++)
{
try {
if(runFlag==true)
{
t.setText(Integer.toString(a));
}
th.sleep(100);
}
catch (Exception t)
{
System.out.println(t.getMessage());
}
}
}
class on implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
go();
}
}
class off implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
runFlag=!runFlag;
}
}
}
public class mythread
{
public static void main(String args[])
{
new dis();
}
}