62,614
社区成员
发帖
与我相关
我的任务
分享
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jlText.setText("1");
}
});
//执行代码
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jlText.setText("2");
}
});
//执行代码
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jlText.setText("3");
}
});
//执行代码
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jlText.setText("4");
}
});
//执行代码
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jlText.setText("5");
}
});
} catch (InterruptedException e1) {
e1.printStackTrace();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
}
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Frame5 extends JFrame {
private JLabel lab;
public Frame5() {
init();
}
private void init() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(100,100);
this.setLocationRelativeTo(null);
lab = new JLabel();
Container cont = this.getContentPane();
cont.add(lab);
}
public void startThread() {
ThreadShow th = new ThreadShow();
new Thread(th, "").start();
}
class ThreadShow implements Runnable {
public void run() {
try {
lab.setText("1");
Thread.sleep(1000);
lab.setText("2");
Thread.sleep(1000);
lab.setText("3");
Thread.sleep(1000);
lab.setText("4");
Thread.sleep(1000);
lab.setText("5");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Frame5 frame = new Frame5();
frame.setVisible(true);
frame.startThread();
}
}