我是 Java 桌面应用程序编程的新手,所以我会很感激一些帮助......
我用构建器添加了框架的组件。
当我单击主框架的按钮时,我将显示如下对话框:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
BehaviorDialog behavDialog = new BehaviorDialog(this, rootPaneCheckingEnabled);
behavDialog.setVisible(true);
}
我的BehaviorDialog
课是这样的:
public class BehaviorDialog extends javax.swing.JDialog {
/**
* Creates new form BehaviorDialog
*/
public BehaviorDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
setTitle("Add behavior");
setLocationRelativeTo(this);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
//....
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
BehaviorDialog dialog = new BehaviorDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
//...
// End of variables declaration
}
我的问题是:
这是启动框架/对话框的正确方法吗?(它有效,但我想确定它是否是最好的方法......)
当我删除
invokeLater()
in 时main
,它似乎以相同的方式工作......我应该保留它还是可以删除它?删除它有什么后果?
提前致谢!