Results 1 to 8 of 8
Thread: Create extra GUI interface
- 03-27-2011, 09:10 AM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Create extra GUI interface
Hie guys, may I please have your help if you will.
I have a school assignment I am working on. It is a supermarket GUI checkout which allows users to buy goods, pay, get change and print receipts. Quite basic.
Now the issue is this. The program is now working perfectly well except for one little thing.
I want to be able to create a new instance of the program i.e another GUI with a fresh instance of all the associated classes. So one user will be able to buy and maintain his own basket whilst another user does the same.
There is no inventory system so there is no need for sharing anything between the two. They can be completely different.
My main method is in a class called ShoppingCartDisplay
I already have a button (picture below) in the GUI for performing this action but I am at a complete loss as to how to execute this. How can I make the computer start a completely fresh instance of this program when the button is clicked.
- 03-27-2011, 09:22 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Just have the button create a new instance of the GUI.
If it's called ShoppingCart have the button listener be
Java Code:new ShoppingCart(/*args*/);
- 03-27-2011, 09:32 AM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
I have tried doing that but the GUI does not appear. Could it be that the GUI is actually created but I just can't see it?
- 03-27-2011, 09:36 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Do you call setVisible in the constructor or main? If you call it in main, consider switching that line and the line for setting the size inside the constructor.
Also post your code for the main method please.
- 03-27-2011, 09:43 AM #5
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Main method
Java Code:public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ShoppingCartDisplay().setVisible(true); } }); }
- 03-27-2011, 09:48 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Alright, so you can do two things.
1) put setVisible(true); in the constructor and have the button call new ShoppingCart()
2) have the button call new ShoppingCart().setVisible(true);
- 03-27-2011, 10:04 AM #7
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Thanks for that boss, it's working. Stands up and does an african dance :D
- 03-27-2011, 10:05 AM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
Reading extra /n on file.
By gicp89 in forum New To JavaReplies: 9Last Post: 02-08-2011, 12:48 PM -
Extra Sun Voucher available
By PriyaK in forum Reviews / AdvertisingReplies: 4Last Post: 01-15-2010, 06:41 AM -
Create interface from my code
By Lyricid in forum AWT / SwingReplies: 1Last Post: 11-18-2009, 05:39 PM -
extra line in GridLayout
By aznboarder in forum SWT / JFaceReplies: 3Last Post: 03-25-2009, 05:36 AM -
Extra bracket
By CrazyShells Slam in forum New To JavaReplies: 5Last Post: 05-16-2008, 06:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks