Call a method on dispose() or EXIT of a JFrame
Hey.
Basically what I want to do is call a method when clicking on the close button in the JFrame (the default one in the top corner).
I don't know if it's possible to override the DISPOSE_ON_CLOSE - or if it's the easiest to do.
Anyway, I'll give you a few stumps of code:
MainFrame:
Code:
package gui;
import ...
public class MainFrame extends JFrame {
private JButton btnAdmConf;
private Controller controller;
public MainFrame() {
...
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
...
controller = new Controller();
...
refreshButtons();
this.setVisible(true);
}
public void refreshButtons() {
...
}
public JFrame getFrame() {
return this;
}
private class Controller implements ActionListener
{
public void actionPerformed(ActionEvent e){
if (e.getSource() == btnAdmConf) {
new ConferenceFrame(getFrame());
}
}
}
}
And...
ConferenceFrame:
Code:
package gui;
import ...
public class ConferenceFrame extends JFrame{
private MainFrame fromFrame;
private Controller controller;
public ConferenceFrame(JFrame fromFrame)
{
...
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
...
this.fromFrame = (MainFrame)fromFrame;
...
controller = new Controller();
...
this.setVisible(true);
}
public MainFrame getFromFrame() {
return fromFrame;
}
public JFrame getFrame() {
return this;
}
private class Controller implements ActionListener
{
public void actionPerformed(ActionEvent e){
...
}
}
}
Sorry if I wrote any incorrect brackets - ignore it if you can.
So, on my my ConferenceFrame, I want to call getFromFrame.refreshButtons() when I dispose the frame.
Any suggestions?