I’m currently working on a java game which opens up with a “start screen” frame. In the startscreen, I have a button called buttonLogin. Once you press buttonLogin, a login dialog launched by a LoginDialog class will pop up asking you for a username and password. In the dialog there are two buttons, login and cancel. Once you press login, my game will open, but the start screen is still visible.
My problem is that I do not know how to write code in the actionPerformed method of my LoginDialog class to close the existing StartScreen window.
Keep in mind that I am writing in the LoginDialog class and not the StartScreen class.
Depending on what you want to achieve, you can use the
setVisiblemethod or thedisposemethod.If needed, you can just pass your
StartScreeninstance as a parameter to yourLoginDialogclass.Another approach would be to give your
LoginDialogclass a setter for an ‘after-login’ action. TheStartScreencan then create and set an action which disposes the startscreen.Edit
To make the ‘after-login’ action a bit more clear, I meant something along the lines of