"this so confusing always , do have some examples "
I'm not so sure what is so confusing. Your program should only have one launching class with a main
method. Netbeans will create a main
method for you in JDialog
forms, so just delete the main
method. The only main
method you need is your main JFrame
form.
You have your JDialog
form
public class MyDialog extends javax.swing.JDialog {
public MyDialog(final Frame parent, boolean modal) {
super(parent, model);
initComponents();
}
private void initiComponent() {
...
}
// delete the auto-generated main method
}
You have your JFrame form with JMenuItem
. Add a listener to the JmenuItem
to open the MyDialog
public class MyFrame extends javax.swing.JFrame {
private javax.swing.JMenuItem jMenuItem1;
public MyFrame() {
initComponents();
}
/* Auto-generated code */
private void initComponents() {
jMenuItem1 = new JMenuItem();
jMenuItem1.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
}
/* Auto-generated method */
private jmenuItemActionPerformed(java.awt.event.ActionEvent evt) {
/* Your hand written code */
MyDialog dialog = new MyDialog(MyFrame.this, true);
}
public static void main(String[] args) {
}
}
" How to combine to different components in these situations ? "
What does that even mean?
Side Note
- I'd recommend going through Swing Tutotials and learning to hand code before jumping in to GUI Builder tools.