Im using swing in java to make a quiz for my coursework. I have made my main class, a tabbed frame that holds separate jpanels as tabs for example the login page, and im using sqlite to get my data. However Im struggling to see how i can communicate between say my login jpanel and my main class.
mainJFrame.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent arg0) {
LoginPanel loginEntry = new LoginPanel();
welcomePanel.add(loginEntry);
welcomePanel.setBounds(0,0,728,390);
//So here i would like an if statement so that on successful login, the other tabs are added and can be seen. But are not available if you are not logged in.
tabbedPane.addTab("Quick Guide", null, quickGuidePanel, null);
tabbedPane.addTab("Examples", null, examplePanel, null);
tabbedPane.addTab("Run Quiz", null, runQuizPanel, null);
tabbedPane.addTab("Exams", null, examPanel, null);
tabbedPane.addTab("View Performance", null, viewPerfPanel, null);
tabbedPane.addTab("Settings", null, settingsPanel, null);
}
});
I tried creating a getter and setter and tried to getSuccessfulLogin() but that wasn’t working 🙁
thanks
I good way to populate your loginInformation in the Application would be a Singleton Pattern.
For example:
Via the static getInstance()-method you can get an Instance of exact the same object everywhere in your Appliaction without the need to carry the Object trough all constructros or methods.
You can hold all your authentification-related Data there and even some Methods, that do the login-work.
The getCurrentUser() could return null if no succelsful logged in user exists.
If it is possible to login from more then one client at the same time you will need to hold different UserInformations for different sessions in your AuthService.