I'm new at programming java desktop applications, so I would appreciate some help...
I added the components of the frame with the builder.
When I click in a button of my main frame, I am showing the dialog like this:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
BehaviorDialog behavDialog = new BehaviorDialog(this, rootPaneCheckingEnabled);
behavDialog.setVisible(true);
}
And my BehaviorDialog
class is like this:
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
}
My questions are:
This is the correct way to start frames/dialog? (It works, but I would like to be sure if it is the best way...)
When I remove the
invokeLater()
in themain
, it seems to work the same way... Should I keep it or can I remove it? What are the consequences of removing it?