我在編程的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