Reputation: 653
I am building an application in java that has 2 JFrames. 1st frame has a button that upon clicking should open the next JFrame while the previous one should close. I know how to display the next frame but: How do I close the previous JFrame automatically when the next JFrame opens ?
I tried thie following code:
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
new GUI();//next frame
this.dispose();//compile-time-error
}
Upvotes: 3
Views: 6280
Reputation: 19820
Where you call this.dispose()
, the object referred by this
is an instance of ActionListener
. To invoke the instance of GUI type GUI.this.dispose()
instead.
Upvotes: 8