我有一个JButton,让我们把它称为“按钮”,并添加一个ActionListener它:更改一个JLabel文本的同时,JButton的监听工作
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
call();
}
});
它是正确添加到我的框架等。在JFrame的我也有一个JLabel,我想在JButton方法工作的时候改变它的文本(因为它需要30秒才能完成)。我怎么做?我必须使用一些多线程的东西吗? 下面是基本原理(JLabel的被称为输出):
public void call(){
output.setText("test1");
try { Thread.sleep(1000);
} catch (InterruptedException e) {}
output.setText("test2");
}
这将导致在“输出”标记在一秒之后被改变到“TEST2”。我怎样才能让它立即显示“test1”?
删除'output.setText(“test1”);'... – Reimeus