消除了在Java GUI中使用Alt-F4和Alt-TAB的可能性[重复]

问题描述

|                                                                                                                   这个问题已经在这里有了答案:                                                      

解决方法

要停止Alt-F4:
yourframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
要停止Alt-Tab,您可以做一些更具侵略性的事情。
public class AltTabStopper implements Runnable
{
     private boolean working = true;
     private JFrame frame;

     public AltTabStopper(JFrame frame)
     {
          this.frame = frame;
     }

     public void stop()
     {
          working = false;
     }

     public static AltTabStopper create(JFrame frame)
     {
         AltTabStopper stopper = new AltTabStopper(frame);
         new Thread(stopper,\"Alt-Tab Stopper\").start();
         return stopper;
     }

     public void run()
     {
         try
         {
             Robot robot = new Robot();
             while (working)
             {
                  robot.keyRelease(KeyEvent.VK_ALT);
                  robot.keyRelease(KeyEvent.VK_TAB);
                  frame.requestFocus();
                  try { Thread.sleep(10); } catch(Exception) {}
             }
         } catch (Exception e) { e.printStackTrace(); System.exit(-1); }
     }
}