Close a frame from another class
An OO question.
Goal: i want to dispose the Frame or setvisibility to false to the Frame in class two (StartHandler)
Only i don't know how i can close the active frame. An instance won't work, it will be a new instance.
The code:
1. Method in class One - Button panel,
Code:
class RestartButtonHandler implements ActionListener
{
/*
* @type: function
* @param: Actionevent
*/
public void actionPerformed(ActionEvent e)
{
}
}
2. Method in class Two - StartHandler, starting two panels in one frame.
Code:
public void startGame(String name, int levelId)
{
this.naam = name;
this.levelId = levelId;
this.playgroundId = 3;
if(checkNaam(this.naam))
{
Game game = new Game(this.name);
game.setLevelActive(this.levelId);
game.setPlaygroundActive(this.playgroundId);
//maak panel rechts voor knoppen
ButtonPanel panelEast = new ButtonPanel();
panelEast.setLayout(new GridLayout(4, 4));
panelEast.setFocusable(true);
//maak panel links midden voor het speelveld
PlaygroundPanel panelCenter = new PlaygroundPanel(game.getPlayground(), 30, 30, 21, 21, false);
panelCenter.setFocusable(true);
//maak parent panel
JPanel parent = new JPanel();
parent.setLayout(new BorderLayout());
parent.add(panelEast, BorderLayout.EAST);
parent.add(panelCenter, BorderLayout.CENTER);
JFrame frame = new JFrame("Game: Sokoban - Level: " + game.level.getNaam() + " - Grameground: " + game.playground.getNaam() + " - Speler: " + spel.getPlayernaam());
frame.setSize(750, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.add(parent);
}
}