I am trying to close the current window in a Java Swing. I referred to some questions and I used the code posted as an answer, but when I use that code mentioned below and run it, it has no effect, and the window turns to appear as shown in the picture.
Code
btn_Ok.addActionListener(new ActionListener() { //ActionListener für Button Bsave
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == btn_Ok) {
System.out.println("Button Ok Pressed");
setVisible(true);
dialogdatei.dispose();
dialogdatei.dispatchEvent(new WindowEvent(dialogdatei, WindowEvent.WINDOW_CLOSING));
dialogdatei.setDefaultCloseOperation(EXIT_ON_CLOSE);