2010-12-16 36 views
5

我需要一種方法來阻止人們在我的Java程序運行時使用其他程序。即阻止人們切換標籤,按下ALT + F4 ...Java全屏程序(Swing)-Tab/ALT F4

謝謝:)

+0

我不認爲你可以這樣做,而不訴諸依賴於平臺的JNI。一個很好的問題。 – 2010-12-16 15:37:35

+3

你爲什麼要這麼做?運行多任務操作系統的重點在於人們可以做到這一點。 – DJClayworth 2010-12-16 15:54:59

+0

看看:http://stackoverflow.com/questions/6127709/remove-the-possibility-of-using-alt-f4-and-alt-tab-in-java-gui?lq=1 – seewip 2012-07-25 14:06:57

回答

9

爲了使程序全屏使用;

window.setExtendedState(Frame.MAXIMIZED_BOTH); //maximise window 

window.setUndecorated(true); //remove decorations e.g. x in top right 

並使窗口始終處於最佳使用狀態(阻止使用其他正在運行的程序的人員);

window.setAlwaysOnTop(true); 
+0

謝謝Ste T :) – 2010-12-16 15:41:10

+0

最大化窗口是否阻止訪問窗口任務欄?如果你的窗口始終處於最佳狀態,它是否會掩蓋後面可能會出現的任何模態對話框? – Curtis 2010-12-16 15:41:16

+3

如果窗口失去焦點,任務欄確實變得可見,但是您可以使用機器人在窗口失去焦點時單擊以進行修復:D – 2010-12-16 15:45:27

7

您不能在Java級別上做到這一點 - 您需要將操作系統設置爲某種「Kiosk模式」。

不請自來的評論 - 你是否需要這個,是因爲你(或你的客戶)討厭你的用戶,並希望他們永遠詛咒你?您是否打算將「關閉計算機」功能添加到您的程序中?

+9

+1爲未經請求的評論。我會很快卸載這樣一個程序。 – 2010-12-16 15:42:58

+6

也許這是某種公共終端或某種程序。我很難想象爲什麼在普通的臺式電腦或筆記本電腦上需要這樣的程序。 – 2010-12-16 15:56:56

6

如果您正在尋找全屏支持,這是我使用的代碼。應該足以讓你走了。您只需要一個全局布爾變量來說明應用程序是否全屏。你可以用它來修補它,讓它顯示你喜歡的。

 
/** 
    * Method allows changing whether this window is displayed in fullscreen or 
    * windowed mode. 
    * @param fullscreen true = change to fullscreen, 
    *     false = change to windowed 
    */ 
    public void setFullscreen(boolean fullscreen) 
    { 
     //get a reference to the device. 
     GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
     DisplayMode dispMode = device.getDisplayMode(); 
     //save the old display mode before changing it. 
     dispModeOld = device.getDisplayMode(); 

     if(this.fullscreen != fullscreen) 
     { //are we actually changing modes. 
      //change modes. 
      this.fullscreen = fullscreen; 
      // toggle fullscreen mode 
      if(!fullscreen) 
      { 
       //change to windowed mode. 
       //set the display mode back to the what it was when 
       //the program was launched. 
       device.setDisplayMode(dispModeOld); 
       //hide the frame so we can change it. 
       setVisible(false); 
       //remove the frame from being displayable. 
       dispose(); 
       //put the borders back on the frame. 
       setUndecorated(false); 
       //needed to unset this window as the fullscreen window. 
       device.setFullScreenWindow(null); 
       //recenter window 
       setLocationRelativeTo(null); 
       setResizable(true); 

       //reset the display mode to what it was before 
       //we changed it. 
       setVisible(true); 

      } 
      else 
      { //change to fullscreen. 
       //hide everything 
       setVisible(false); 
       //remove the frame from being displayable. 
       dispose(); 
       //remove borders around the frame 
       setUndecorated(true); 
       //make the window fullscreen. 
       device.setFullScreenWindow(this); 
       //attempt to change the screen resolution. 
       device.setDisplayMode(dispMode); 
       setResizable(false); 
       setAlwaysOnTop(false); 
       //show the frame 
       setVisible(true); 
      } 
      //make sure that the screen is refreshed. 
      repaint(); 
     } 
    } 
 
+0

不錯:)感謝很多朋友... – 2010-12-16 15:41:51

+0

這是一個非常廣泛的應用程序全屏幕的方式。大多數其他指南只包括'device.setFullScreenWindow(this);'但這可能會留下不需要的邊緣。我會親自刪除'setLocationRelativeTo(null);'雖然窗口似乎記得它的舊位置,並會返回到它。 – Finnboy11 2014-05-01 14:15:24