【发布时间】:2016-09-19 19:40:26
【问题描述】:
我想从另一个类(主类)创建一个 Jframe,然后我想仅在主方法中没有错误时才显示 Jframe。否则,我想通过传递相同的 jframe 来创建和显示对话框。 我在任何地方都忘记了线程概念给我解决方案,我尝试了下面的代码,打印“abcde”但不显示完整的框架程序。
注意:JFrame od ErrorDialog 中没有 main 方法。它们只是自定义容器。
public class Start{
public static Main mf=null;
public static void main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
mf = new Main();
}
});
try {
// Some extra code
System.out.println("abcde"); // this is print and then program complete
mf.setVisible(true); // this line will not run
} catch (Exception e) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ErrorDialog(mf, true).setVisible(true);;
}
});
}
}
}
【问题讨论】:
-
1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) 你的问题是“How to X?”?如果是这样,请将其添加为edit to the question。如果没有,请考虑一个特定的问题并做同样的事情(编辑)。
-
您似乎误解的关键概念是“稍后”的含义
标签: java multithreading swing jframe main