简体   繁体   中英

How to manage multiple windows system - Java(Swing)

I'm working on my 2nd year Project and I need your help. I want to create a DIY Store System that will contain multiple windows. All the screens are done, just need the idea how they will be managed all together There is a login window with the company logo, address, textfields etc that will pop up when the system is started. Then the tricky part begins, there are 3 types of users (admin, sales and stock user) and every one of them will have a different main menu(GUI).

Any ideas how to deal with this problem?

suggest you use objects on the user account to determine which panel to display ie

admin gets an admin panel which extends from Jpanel (and maybe a base panel all user panels share/extend) then you would check to see which user account is logging in and load the correct panel or portions of a panel, re use as much of the gui panels as possible to cut down on the amount of code bulk. this might help later on as if you are working with the panels and user groups you could do is instance of...

               Jpanel
                 |
         some base gui panel
        |           |           |
adminPanel  salesPanel    userPanel
Here is my idea for this:
to create a MainGUI.java file (JFrame) that contains
3 constructors(+ default constr) with separate GUI for each user. In the main method
I would call a login object(JDialog) and check what type of user
I'm dealing with and then create an appropriate mainGUI
object.    

(pseudo code) Please comment.

    class mainGUI
    //variables
    public mainGui() // default constructor
    //body
    public mainGUI(var1, var2, va3) // type1 user constructor
    //body
    public mainGUI(var1, var3, var2) // type2 user constructor
    //body
    public mainGUI(var2, var1. var3) //type3 user constructor

    main method()
    mainGui m = new mainGUI();
    Login l1 = new Login(m);
    if(l1.getPassword() == some array value) // type1 User passwords are stored in Array1 (eg. Admin)
    then
    mainGUI m1 = new mainGUI(var1, var2, var3); // creates appropriate user gui
    else if(l1.getPassword() == some array value ) // user type2 (e.g. Sales Staff)
    then
    mainGUI m1 = new mainGUI(var1, var3, var2);
    and so on...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM