I just started working with Swing. I'm starting to get the hold of it.
However I got a question regarding screen navigation in swing.
This is how I have structured the app.
- public class MainFrame extends JFrame
- public class LoginPanel extends JPanel
- public class HomeScreenPanel extends JPanel
in Mainframe I have the following code:
public class MainFrame extends JFrame {
public MainFrame() {
initUI();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MainFrame ex = new MainFrame();
ex.setVisible(true);
}
});
}
private void initUI(){
InputScreenPanel inputScreenPanel = new InputScreenPanel();
getContentPane().add(inputScreenPanel);
Dimension dim = new Dimension(400, 300);
setMinimumSize(dim);
}
}
In LoginPanel I initialize the screen and add a button and a textbox. I wrote the event handler for the button click event. I want to get the value from the textbox and redirect the user to HomeScreenPanel. How can I switch the panel when at the time this button click is executing the context is the LoginPanel and there I have no reference to the frame so I can switch the panels.
CardLayout
as well and just switch between the panels – Robin