0

I have a designed a control-frame on 1 class which has jbutton components, I have coded like on action event of these components diff-diff frame get initialized.

For each frame there is a class. now when I press second jbutton from control-frame then have to close the frame (which has opened when I pressed first jbutton from control-frame).

Rajshri
  • 4,163
  • 2
  • 15
  • 17

2 Answers2

0

Just keep track of frame instance as instance variable in main class. Then close that instance on clicking close button.

public void open(ActionEvent e) {
    frame = new  something.. // your frame
}

public void close(ActionEvent e) {
    frame.dispose();
}

Note: JFrame frame is global variable.

Mohan Raj B
  • 1,015
  • 7
  • 14
0

write this in your button click linstener

 yourFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Biswajit
  • 2,434
  • 2
  • 28
  • 35