【发布时间】:2011-08-02 22:03:28
【问题描述】:
所以在这部分代码中,我想基本上告诉 GUI 禁用按钮并在不再运行线程时弹出一个弹出窗口(即调用的方法已完成)。
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();
if (Thread.activeCount() == 0)
{
btnConvertDocuments.setEnabled(false);
//Validation message ensuring completion of the step.
JOptionPane.showMessageDialog(this, "Step 1 Complete!", "Validation", JOptionPane.INFORMATION_MESSAGE);
}
}
为什么if (Thread.activeCount() == 0) 似乎从来没有被调用过?这不是我想要做的事情来实现我的目标吗?提前感谢您的任何意见!
【问题讨论】:
-
作为直接使用线程的替代方法,您可能需要查看
ExecutorService和Future<T>。
标签: java multithreading user-interface events