我在编程的Java桌面应用新的,所以我希望得到一些帮助...显示一个JFrame或JDialog的(摇摆)
我添加了建设者框架的组成部分。
当我在我的主框架的按钮点击,我显示的对话框是这样的:
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
}
我的问题是:
这是启动帧/对话框的正确方法吗? (它的工作原理,但我想,以确保它是否是最好的方式......)
当我删除在
main
的invokeLater()
,似乎相同的方式工作。我要好好保存或我可以删除它吗?删除它有什么后果?
在此先感谢!
另请参阅此替代方法[方法](http://stackoverflow.com/a/2561540/230513)。 – trashgod