我有一个 JFrame 子类,它管理我的 UI 并调用 Item Object 的方法来在我的数据库中导入项目:
public TestGUI() throws IOException
{
initComponents();
Item.importItems(progressBar); // static method that execute a new thread to import item witouth freeze my UI (I update a progressBar in it)
table.refresh(); //Metodh that I need to execute only after "importItems()" methods is completed
}
Item对象实现Runnable在新的Thread中执行导入操作
public Item implements Runnable
{
private JProgressBar progressBar;
public void importItems (JProgressBar progressBar) throws IOException //Metodo per importare articoli da un file esterno. Usa i Thread.
{
this.progressBar = progressBar;
Thread importThread = new Thread (new RefreshTable(),"Importer Thread");
importThread.start();
}
void run ()
{
// I execute here all the DB operation that i need. I also update the progress bar here
}
}
如何修改该代码以table.refresh()
仅在Item.importImtes(progressBar)
其执行结束后执行?谢谢!