Reputation: 3743
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.
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.
Upvotes: 1
Views: 2033
Reputation: 81
You should use a JDialog for the login part and then start your app in a new JFrame
Upvotes: 2
Reputation: 347194
I'd use some kind of model/controller that is capable of reacting to changes within the separate parts of the program.
I'd interface this controller so you can replace the implementation without effecting the rest of the application
Basically this would mean that the login pane and the home panes wouldn't care about how they are being displayed
Upvotes: 1
Reputation: 4347
I think you have 2 options here:
Upvotes: 3