Swapping between different logical views
I am designing an applet that has several logical views, such as Login, Registration, Waiting Area, and Game. I am very new to applets and Swing, and I can't figure out how to have each of these designed separately and then swap between them. Ideally, this is what I would like:
1) Each view can be designed separately using NetBeans IDE, preferably in different classes for neatness.
2) When certain conditions are met (such as successful login), then all content in the applet window will be removed and replaced with that of a new view.
I attempted to use setContentPane to achieve this, but it doesn't seem to repaint correctly except when called initially. Otherwise, the setting the content pane and calling repaint will pain the screen blank. If you resize the window (only possible via applet viewers, not via web page applet) then the content displays properly. It seems like I need to somehow force the applet to repaint, but neither the repaint method nor manually modifying items, such as changing text on the new screen via setText, will not force it to display.
When I used setContentPane(myLoginGUI.getContentPane) in an event-dispatching thread during init, it correctly displays the login page.
Here's some of the code I was using, involving classes Client, LoginGUI, and RegisterGUI, which all extend japplet:
//in Client.java:
//called during init from an event dispatching thread
//also called in RegisterGUI from button handler for goBackToLogin button
publicvoid createLoginGUI(){
myLoginGUI =new LoginGUI();
this.setContentPane(myLoginGUI.getContentPane());
repaint();
}
//called when user clicks register button from login page. button handler
//is in LoginGUI
publicvoid createRegisterGUI(){
myRegisterGUI =new RegisterGUI();
this.setContentPane(myRegisterGUI.getContentPane());
repaint();
}
Thanks for reading this and any insights you may have.
Message was edited by:
bubonics

