为什么setText(Integer.toString(count++));有什么错误???import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class ThreadTest3 extends JFrame{
private final int maxsize=5;
private boolean runFlag=true;
private boolean started=false;
StartTask[] st;

  private JButton start=new JButton("start");
//private JTextField t=new JTextField(10);
public ThreadTest3(){
super("testing thread");
st=new StartTask[maxsize];
for(int i=0;i<maxsize;i++)st[i]=new StartTask();
Container c=getContentPane();
c.setLayout(new FlowLayout());
//c.add(t);c.add(test);
c.add(start);
start.addActionListener(new StartL());
//test.addActionListener(new TestL());
setSize(300,100);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class StartTask extends Thread{
private JButton b=new JButton("control");
private JTextField tf=new JTextField(10);

private int count=0;
private boolean runFlag=true;
StartTask(){
b.addActionListener(new TestL());
JPanel p=new JPanel();
p.add(tf);
p.add(b);
getContentPane().add(p);
}
public void run(){
while(true){
try{Thread.sleep(100);}
catch(InterruptedException e){
System.err.println("Interrupted");
}
if(runFlag){
//String s="Integer.toString(count++)";
tf.setText(Integer.toString(count++));
}
}

}

}
//private StartTask st=null;
public class StartL implements ActionListener{
public void actionPerformed(ActionEvent e){
if(!started){
started=true;
for(int i=0;i<maxsize;i++)st[i].start();
}
}
}
public class TestL implements ActionListener{
public void actionPerformed(ActionEvent e){
runFlag=!runFlag;
}
}
public static void main(String[] args){
ThreadTest3 tt=new ThreadTest3();
}

}

解决方案 »

  1.   

    --------------------Configuration: <Default>--------------------
    C:\Documents and Settings\Administrator\My Documents\ThreadTest3.java:48: toString() in java.lang.Object cannot be applied to (int)
                                            tf.setText(Integer.toString(count++));
                                                              ^
    1 errorProcess completed.
      

  2.   

    刚刚试了一下,一切正常啊。你看一下名字什么有没有出错的地。另外,你的setsize设置的小了点……
      

  3.   

    顺便说一下,我用的编译器是Jcreator