Running a Class from another Class Method
843789Nov 12 2009 — edited Nov 13 2009Hey there all.
I currently have a small problem with my code. Here is the action listener to a button that I created in a JFrame within a class called WelcomeScreen:
public void createFinalActionPerformed(java.awt.event.ActionEvent evt) {
Room = createRoomText.getText();
User = createUserText.getText();
new ChatRoom();
welcome.setVisible(false);
}
Now I have another class called ChatRoom, and In this code I am wanting to create a new instance of the ChatRoom class.
Further in the code, in the WelcomeScreen there are 2 Text Boxes (createRoomText & createUserText). The 2 public Strings (User & Room) Are Used in the ChatRoom class for applying the User Name and Chat Room Name to the class itself (by gathering the text from createRoomText & createUserText). As you can gather, ChatRoom extends WelcmeScreen.
My problem is that when this code is run, the 2 variables do not interact into the ChatRoom class, and for some reason the WelcomeScreen class is re-rendered, as well as the ChatRoom class rendered with no public variables applied.
Obviously the WelcomeScreen class is re-rendered and that is why the variables are not applied to the ChatRoom class (because the variables are reset).
The guilty code is:
new ChatRoom();
Why would this code re-render the WelcomeScreen class? and how could I stop this from happening?