PDA

View Full Version : New Jframe java



Geir102
May 8th, 2008, 12:26 PM
Hi i'm doing a GUI project in netbeans. And i have my main Jframe, any one know how i can get another one. Like when I press a button a new Jframe pops
up.

Zugzwang
May 8th, 2008, 12:43 PM
You can just instantiate any Frame and call the setVisible(true) method of it, just like it is done in the pre-generated main() method of a JFrame:


new YourFrame().setVisible(true);


For making it open when you press a button, double click onto the "actionPerformed" event of the button and Netbeans will make a method (in the frame class) for you that is called when you press the button.

Geir102
May 8th, 2008, 12:48 PM
Ok thaks...just one more question. I see when i create a new Jframe its set up whit a main. Is it suppose to?

achelis
May 8th, 2008, 01:10 PM
Depending on what you need it for it sounds like you might benefit from using a JDialog instead of a JFrame.

I'm not sure what you mean by it's set up with a main?

Zugzwang
May 8th, 2008, 01:53 PM
Ok thaks...just one more question. I see when i create a new Jframe its set up whit a main. Is it suppose to?

Of course it is supposed to - otherwise Netbeans wouldn't do it. ;-) No, just kidding. The automatically included main(...)-function is just for convenience. It is good practice to delete it if it isn't needed.

Geir102
May 8th, 2008, 01:59 PM
thanks alott for the quick answers:)