所以在这一块的代码:如何在Java中延迟MessageDialogBox?
//Actions performed when an event occurs.
public void actionPerformed(ActionEvent event)
{
String command = event.getActionCommand();
//If btnConvertDocuments is clicked, the FileConverter method is called and the button is then disabled [so as to prevent duplicates].
if (command.equals("w"))
{
new Thread(new Runnable()
{
public void run()
{
FileConverter fc = new FileConverter();
}
}).start();
btnConvertDocuments.setEnabled(false);
//Validation message ensuring completion of the step.
JOptionPane.showMessageDialog(this, "Step 1 Complete!", "Validation", JOptionPane.INFORMATION_MESSAGE);
}
好像在消息对话框弹出太快了,甚至没有完被调用FileConverter方法之前。我想知道JOptionPane的位置是否正确,或者在方法完成处理之前是否有延迟消息的方法?
SwingWorker不是Swing的预建类吗?当我尝试在eclipse中使用它时,它给了我一个编译器错误,指出SwingWorker无法解析为类型。 –
它自Java 6以来已包含在Swing中。 – perp
是的,我有最新版本,但仍无法导入SwingWorker。 –