Reputation: 1
This is my first java swing application and I have some questions about the organization.
I need to create a application that after log in redirect the user to (let's call it) "Normal user page", "Admin Page" or "Super user page". After reading some articles I figured out that java swing applications, use one JFrame and panels to hide or show content (some thing like single page application).
My questions are now:
Do I need to create 4 "main classes" (log in, normal user, admin, super) and each one extends one jframe because they are particularly different applications and this jframes have their own classes (panles), with them I hide/show content on them
OR, Log in is my main Jframe and after log in i show a different panel (normal user, admin or super) in a different window or dialog, and they have their panels to hide show content
When my first questions is right is this a good folder structure:
Folder app: Log in, normal, admin, super user class(frame) Folder noram user: classes/panels related to him . . .
Thanks in advance :))
Upvotes: 0
Views: 150
Reputation: 285450
Questions/Answers:
Do I need to create 4 "main classes" (log in, normal user, admin, super) and each one extends one jframe because they are particularly different applications and this jframes have their own classes (panles), with them I hide/show content on them
If you're creating a decent Swing GUI, likely none of your classes will extend JFrame, and in fact it is rare that you'll ever want to do this. More commonly your GUI classes will be geared towards creating JPanels, which can then be placed into JFrames or JDialogs, or JTabbedPanes, or swapped via CardLayouts, wherever needed. This will greatly increase the flexibility of your GUI coding.
You will likely have one master View class/JPanel, and could swap its content with other sub-view classes that will correspond to the different states of your non-GUI model class, whether it would be a normal user, admin, or super user.
OR, Log in is my main Jframe and after log in i show a different panel (normal user, admin or super) in a different window or dialog, and they have their panels to hide show content
I usually use a dialog to log in such as a JDialog, and then after verifying credentials, show the main GUI, again with the correct view sub-type based on the state of the model.
When my first questions is right is this a good folder structure:
Folder app: Log in, normal, admin, super user class(frame) Folder noram user: classes/panels related to him . .
Much more important I think is to separate your packages into model, view, control, and main. Then you could use sub-packages for the various sub-portions of your program.
I strongly urge you to read up on Model-View-Control pattern of GUI structure, and then study up on the many useful variants of this.
Upvotes: 3