【发布时间】:2024-01-09 10:24:01
【问题描述】:
按下按钮后,actionPerformed 被调用。像这样开始一个新的Thread:
public void actionPerformed(ActionEvent evt) {
try {
Runnable r = new Runnable() {
public void run() {
try {
mylabel.setText("new text");
mylabel.revalidate();
mylabel.repaint();
} catch (Exception x) {
x.printStackTrace();
}
}
};
Thread thread = new Thread(r);
thread.start();
MyFunction();
// ...
在myLabel 之后,字符串new text 不会出现,只是在actionPerformed 运行之后。
【问题讨论】:
标签: java multithreading swing user-interface label