This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes On click of button go to another class in core java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "On click of button go to another class in core java" Watch "On click of button go to another class in core java" New topic
Author

On click of button go to another class in core java

Mayur Saparia
Greenhorn

Joined: Feb 13, 2013
Posts: 19

I am doing a project where i want to display another frame when i click on it.
FOr eg. I have page named add customer record which has the button home, when i click on it it should display the home class ?
How can I do this ? Also am using netbeans GUI Builder so please consider that.


Thanks In advance

Regards
Mayur.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

How to Use Buttons, ... and How to Write an Action Listener would be a good place to start.

Moving the thread to Swing forum.

Welcome to the Ranch!


The quieter you are, the more you are able to hear.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2380
    
    7

Welcome to the ranch.

First you mentioned Netbeans GUI builder... don't use it for your own good. It's better to learn the Swing/AWT API through coding. To get started with Swing check out the Swing tutorial here.

As for your question, buttons have a thing called action/event listener, which you use it to control what that button do (eg new frame pop-up, enable/disable something, etc).

Of course before you get there, learn the basics first such as layout managers, the available components (JFrame, JButton, JLabel, JTable, JXXXX etc).


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I am doing a project where i want to display another frame when i click on it.

almost *always* a bad idea - the secondary display generally should be a JDialog (modal, if required)
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2380
    
    7

Michael Dunn wrote:> I am doing a project where i want to display another frame when i click on it.

almost *always* a bad idea - the secondary display generally should be a JDialog (modal, if required)


Or it can be a JInternalFrame. Depends on the purpose.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

K. Tsang wrote:Welcome to the ranch.

First you mentioned Netbeans GUI builder... don't use it for your own good. It's better to learn the Swing/AWT API through coding. To get started with Swing check out the Swing tutorial here.

As for your question, buttons have a thing called action/event listener, which you use it to control what that button do (eg new frame pop-up, enable/disable something, etc).

Of course before you get there, learn the basics first such as layout managers, the available components (JFrame, JButton, JLabel, JTable, JXXXX etc).



Always get the ones "Don't use the gui builder" "don't use IDEs they CHEAT!!!" Kawmon really.. Instead it should say "you should learn how to code the gui work, before going to the gui builder, as understanding the code behind it is the most important thing.... IF you get stuck without knowing what to do it's a bad bad thing."


I personally think the netbeans gui builder is one of the best tools out there... It's a lot better than Scene Builder >( I had to build 136 menu, sub menu, and sub sub menus, and with the gui builder took 6 hours.... Would have taken 10x that coding by hand. Why waste time and "be cool" hard coding things when there are tools to not only do it, but do it great?


As mentioned above you shouldn't have multiple Jframes as that is the top level. I would use JInternalFrames as suggested, or when customer records come in you should pop up a dialog to enter the customer data, then after clicking ok, sends you back to the home page.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2249
    
  47
Jay Orsaw wrote:Always get the ones "Don't use the gui builder" "don't use IDEs they CHEAT!!!" Kawmon really.. Instead it should say "you should learn how to code the gui work, before going to the gui builder, as understanding the code behind it is the most important thing...

That's what K. Tsang did say. To quote "It's better to learn the Swing/AWT API through coding".
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Tony Docherty wrote:
Jay Orsaw wrote:Always get the ones "Don't use the gui builder" "don't use IDEs they CHEAT!!!" Kawmon really.. Instead it should say "you should learn how to code the gui work, before going to the gui builder, as understanding the code behind it is the most important thing...

That's what K. Tsang did say. To quote "It's better to learn the Swing/AWT API through coding".


Yes, I know, it's how he said it, and saying "don't use it for your own good," again, isn't the correct way to phrase it, to which I said above, use it while learning how the code works, and how to fully utilize the gui builder and netbeans itself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: On click of button go to another class in core java