java阻止人们关闭

Har*_*and 2 java swing

嗨,我有一个全屏程序,我不希望人们关闭,除非他们有密码,我现在有这个代码

public void windowClosing(WindowEvent arg0)
{
    System.out.println("HERE");
    String inputValue = JOptionPane.showInputDialog("Please input the closeword");

    if (inputValue != "closeplz")
    {

    }
} 
Run Code Online (Sandbox Code Playgroud)

在if语句中我希望它停止方法,以便程序能够关闭.任何帮助将是非常好的感谢谢谢

Mic*_*rdt 7

你必须打电话

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Run Code Online (Sandbox Code Playgroud)

JFrame实例上(或内部).然后除非你手动完成,否则框架不会关闭,但windowClosing()仍会被调用.在里面,你可以有条件地打电话

System.exit(1);
Run Code Online (Sandbox Code Playgroud)

这将结束申请.务必先做任何必要的清理工作.