I'm trying to close a JFrame from a button on a JPanel which is in my JFrame. I searched around and everything I tried doesn't work.
Here is my code in my JPanel:
public class warningPanel extends JPanel{
//Klassen
warning warningClass = new warning();
loginGeneral loginGen = new loginGeneral();
//Buttons
buttons btnOk;
//JLabels
JLabel lblText;
public warningPanel(){
setLayout(null);
this.setBounds(0, 0, 300, 150);
btnOk = new button.buttons(110, 100, 60, 30, "000003006", "120090040", "255255255");
btnOk.setText("OK");
btnOk.setFont(new Font("default", Font.BOLD, 12));
add(btnOk);
btnOk.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
warningClass.close();
}
public void mouseEntered(MouseEvent e) {
btnOk.setBackground(loginGen.clGold);
}
public void mouseExited(MouseEvent e) {
btnOk.setBackground(loginGen.clDarkBlue);
}
});
}
}
Then here's my JFrame
public class warning extends JFrame{
public void warningMessage(String warningtext){
this.setSize(300, 150);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setBackground(new Color(1, 10, 19));
this.setUndecorated(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
warningPanel panel = new warningPanel();
panel.setOpaque(false);
panel.setBounds(0, 0, 300, 150);
this.setVisible(true);
this.add(panel);
}
public void close(){
this.setVisible(false);
this.dispose();
}
}
I really have no idea why this doesn't work