[英]How can I show a JDialog at the start of my main JFrame form?
晚上好,
我有一个简单的Java应用程序,我正在努力。 我已经卡住了,我需要一些帮助。 这是我们在Java Programming类中开展的一个项目。
我已经创建了一个JFrame表单和几个JDialog表单,我使用位于JFrame表单上的按钮成功调用。 对于其中一个JDialog表单( dlg_create_company ),我希望在应用程序启动时立即弹出作为模态窗口。 到目前为止,我已经尝试从JFrame表单的main方法调用代码,但我遇到了“无法在静态上下文中调用非静态变量”错误。
这是我正在尝试的:
//Create a new instance of my JDialog "dlg_create_company" and assign it to "dialog"
//Then set it's visibility to true.
dlg_create_company dialog = new dlg_create_company(new javax.swing.JFrame(), true, current_company);
dialog.my_parent = this; //sets form frm_repair_shop as the parent via the my_parent reference.
dialog.setVisible(true);
当然,您无法在非静态上下文中访问静态变量。 这是因为静态变量“一直存在”,而非静态对象可能存在或不存在。 您需要在JFrame
的构造函数中显示该对话框,并使它们都可见。 首先是JFrame
,之后是JDialog
。
请发布SSCCE而不是链接到ZIP文件。 也许明天人们会开始链接到他们的Github,要求我们调试它。
public MyJFrame(){
// add components
// call pack and stuff
// instantiate the JDialog
// make JFrame visible
// make the JDialog visible
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.