im using java swing for my coursework to make a quiz. Below is my main frame class which makes new panels which i have as separate classes. But for example if i have a login panel, and the user hits the login button how can i signal my main tabbedquiz class that someone has logged in?
public class TabbedQuiz {
private JFrame jF;
private JTabbedPane tP;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TabbedQuiz w = new TabbedQuiz();
w.jF.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public TabbedQuiz() {
initialize();
}
private void initialize() {
tp= new JFrame();
tp.setTitle("welcome to ...");
final JPanel mainPanel= new JPanel();
final JPanel anotherPanel= new JPanel();
final JPanel examplePanel = new JPanel();
final JPanel quizPanel = new JPanel();
final JPanel examPanel = new JPanel();
final JPanel viewPerfPanel = new JPanel();
final JPanel settingsPanel = new JPanel();
//set up the panels
tF.setBounds(100, 100, 764, 470);
tF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tF.getContentPane().setLayout(null);
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(10, 11, 728, 410);
tF.getContentPane().add(tabbedPane);
tabbedPane.addTab("Welcome", null, mainPanel, null);
// set up other tabs
If your goal is to prevent access to the quiz until someone has logged in, hide other panels or frames until a user has logged in.
Here’s an example using CardLayout: