Results 1 to 8 of 8
  1. #1
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default 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.



  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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*/);

  3. #3
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    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?

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.

  5. #5
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Main method

    Java Code:
    public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ShoppingCartDisplay().setVisible(true);
                }
            });
        }

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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);

  7. #7
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Thanks for that boss, it's working. Stands up and does an african dance :D

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Haha, glad to have helped you out. Please mark your thread solved with the thread tools.

Similar Threads

  1. Reading extra /n on file.
    By gicp89 in forum New To Java
    Replies: 9
    Last Post: 02-08-2011, 12:48 PM
  2. Extra Sun Voucher available
    By PriyaK in forum Reviews / Advertising
    Replies: 4
    Last Post: 01-15-2010, 06:41 AM
  3. Create interface from my code
    By Lyricid in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 05:39 PM
  4. extra line in GridLayout
    By aznboarder in forum SWT / JFace
    Replies: 3
    Last Post: 03-25-2009, 05:36 AM
  5. Extra bracket
    By CrazyShells Slam in forum New To Java
    Replies: 5
    Last Post: 05-16-2008, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •