此方法应该将术语表中两个条目的定义合并为一个。它创建 GlossaryEntryMergeUI 类(JFrame 的扩展)的实例,引导用户完成合并过程。用户单击按钮提交,然后窗口关闭。 merge 方法提取合并的定义并返回组合的术语表条目。
使合并方法等待 MergeUI 响应的最佳方法是什么?我尝试使用 InvokeAndWait,但我不知道如何使其工作。
public GlossaryEntry merge(GlossaryEntry otherEntry){
//First, merge the definitions
GlossaryEntryMergeUI thisMerge = new GlossaryEntryMergeUI(this,otherEntry,mergeSignal);
thisMerge.setVisible(true);
thisMerge.setAlwaysOnTop(true);
GlossaryEntry combined = new GlossaryEntry(word);
combined.addDefinitions(thisMerge.getDefinitions());
return combined;
}
最佳答案
考虑寻找CardLayout而不是在两个或多个窗口之间切换
如果有Serialized或Observate,那么最好将代码包装到invokeAndWait()中,为了在两个Windows之间进行简单切换,有invokeLater()
我建议不要同时使用两个 JFrame,一个 JFrame 和另一个 Window 将是 JDialod 或 JWindow,因为(例如,如果有 BackGroung 任务)有时很难将焦点从一个 JFrame 切换到另一个 JFrame ,不要将 JFrame 移动到Front() ...
关于java - 使用invokeLater或invokeAndWait等待来自另一个GUI的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7688730/