0

I am playing about with GUI builder and i was wondering if there is an easy way to open the register window through the current main window (in reference to the page below). I am trying to do this through the menu bar.

I've been trying all day, because GUI Builder generates some code, its not possible to edit this code.

enter image description here

Thanks For the help!

Marcello
  • 423
  • 1
  • 5
  • 12

2 Answers2

2

Create a separate class which extends JDialog class and add your GUI components:

public Register extends JDialog {
   //Make GUI
   setModalityType(ModalityType.APPLICATION_MODAL); //Make it modal
}

Add ActionListener to that menu item which is supposed to open a register window:

mnuItmRegisteration.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        Register r = new Register();
        r.setVisible(true);
    }
});
Branislav Lazic
  • 14,388
  • 8
  • 60
  • 85
  • You are welcome. And, oh...get rid of that GUI builder if you want to learn swing. – Branislav Lazic Dec 16 '12 at 16:09
  • Thanks, but i only use GUI builder because its so easy to position things like buttons and text fields, its really hard to do this from scratch. :) – Marcello Dec 16 '12 at 17:29
  • @Marcello No its not! I used to create GUI apps with NetBeans GUI builder...until I realized I have no clue about Java swing. Also..have a look at that question from Andrews comment, because you are going to create a very unfriendly UI. – Branislav Lazic Dec 16 '12 at 17:37
  • Okie dokie, i shall take this challenge. – Marcello Dec 16 '12 at 17:48
1

Right click on that shortcut button, click Events, click ActionPreformed.
There you should write codes to make your register window appear.
An example:

  private void RegisterationEventActionPerformed(java.awt.event.ActionEvent evt) { 
    JFrame Register = new Register();
    Register.setVisible(true);
  }

Remember to make another JFrame called ("Register" assuming u are using the code i gave) at the same package as your current JFrame Maybe u would probably should use the run button (The button with a Green Triangle or Arrow), run it try to press the menu item, it should appear the register window.

junyi00
  • 792
  • 3
  • 8
  • 28