Results 1 to 2 of 2
- 02-28-2012, 04:59 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 49
- Rep Power
- 0
What is a good design to click button and go to new page?
I have created two jframes and have buttons that are actionlisteners. Each button should go to a different page of the application. However, I realized that the way that I'm creating my event handling, every time a user would press the button to go to the new screen they can create a new instantiation of the new screen object. Obviously I only want a single instantiation of each page, but I'm not sure how to go about that. Here is the code that I have for my actionPerformed method.
The user would press this button to go to the quotes list page from the mainscreen. Other buttons on the same jframe will be added to this method by the way.Java Code:@Override public void actionPerformed(ActionEvent e){ Object source = e.getSource(); if(source == item1){ QuotesList quote1 = new QuotesList(); quote1.quote();
-
Re: What is a good design to click button and go to new page?
Consider getting your control code out of your GUI code making the control code more "centralized". Give the GUI's public methods that would allow the control class(es) to change its state. For instance if you're using CardLayout to swap JPanels, consider giving each JPanel a name String (via setName) and using that String when adding the JPanel to the CardLayout-using container. Then give the main GUI a public method, say swapView(String name), that accepts a String and that the control can call to tell the CardLayout to swap views to a different JPanel.
Similar Threads
-
return value on a button click
By wotupduck in forum New To JavaReplies: 1Last Post: 03-24-2011, 01:09 PM -
Button click GUI question
By ZambonieDrivor in forum New To JavaReplies: 2Last Post: 11-29-2010, 07:48 AM -
SaveAs button click
By kasiram.p@gmail.com in forum AWT / SwingReplies: 2Last Post: 07-06-2010, 08:35 AM -
Warning: Page has Expired on click of back button
By bhupendra in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-27-2008, 07:42 PM -
i click on it,then first time error page comes,second time click then product page co
By 82rathi.angara in forum New To JavaReplies: 21Last Post: 08-01-2008, 11:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks