设置文本我有一个Java应用程序中,我呼吁的线程来执行一些东西:在主窗体上的JLabel从螺纹
public class ThreadTest implements Runnable {
private final int functionNumber;
public static mainForm main = new mainForm();
private final int time2start;
public static YourClass obj = new YourClass();
public ThreadTest(int functionNumber, int time2start, YourClass obj){
this.functionNumber = functionNumber;
this.time2start = time2start;
}
@Override
public void run(){
try{Thread.sleep(time2start);}catch(Exception ex){}//Time Delay before executing methods
switch(functionNumber){
case 1:
obj.runFirst();
break;
case 2:
obj.runSecond();
main.appendText("Something");
break;
case 3:
{
try {
obj.runThird();
} catch (IOException ex) {
Logger.getLogger(ThreadTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
break;
这是我与Swing GUI的主要形式,方法上,我想从线索附加文字:
void appendText(String text){
generalStatus.setText(text);
}
这是如何实现的?我猜我需要使用重绘或其他东西?
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/。永远不要使用事件分派线程以外的线程中的Swing组件。 SwingUtilities.invokeLater()是你的朋友。 – 2014-10-04 09:52:56