Java – how do I prevent WindowClosing from actually closing the window

I’ve just tried this minimal test case: import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.WindowConstants; public class Test { public static void main(String[] args) { final JFrame frame = new JFrame(“Test”); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { //frame.dispose(); } }); frame.setVisible(true); } } If I keep the dispose call commented, and hit … Read more

How to capture a JFrame’s close button click event?

import javax.swing.JOptionPane; import javax.swing.JFrame; /*Some piece of code*/ frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { if (JOptionPane.showConfirmDialog(frame, “Are you sure you want to close this window?”, “Close Window?”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION){ System.exit(0); } } }); If you also want to prevent the window from closing unless the user chooses ‘Yes’, you can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)