我今天写了个程序,实现的功能是在JTEXTFIELD中连续显示顺序数字,但是我写了好久,功能却始终不能实现,调试很久也不行,求助
import java.awt.BorderLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
class ThreadTest1 extends JFrame {
JTextField l;
private static int count = 0;
private Test12 m;
public ThreadTest1() {
super();
this.setSize(300, 400);
this.setLayout(new BorderLayout());
JPanel m1 = new JPanel();
l = new JTextField(10);
l.addActionListener(new Thread1());
m = new Test12(l);
m1.add(l, BorderLayout.SOUTH);
this.add(m1);
}
class Thread1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
m = new Test12(l);
m.start();
}
}
}
public class ThreadTest {
public static void main(String[] args) {
ThreadTest1 l = new ThreadTest1();
l.setVisible(true);
}
}
------------------------------------
import javax.swing.JTextField;
public class Test12 extends Thread {
private JTextField m;
private static int count=0;
public Test12(JTextField k)
{
this.m=k;
}
public void run()
{
try{
m.setText(Integer.toString(count));
count = count + 1;
Thread.sleep(3000);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
------解决方案--------------------
按多次回车的话会报错.