Мне нужен способ остановить людей, использующих другие программы, в то время как моя программа Java работает. т.е. останавливая людей переключать вкладки и нажимая Alt-F4.
Прекращение использования Tab/Alt-F4 в полноэкранной программе на Java/Swing
Ответы (3)
Чтобы программа использовалась в полноэкранном режиме;
window.setExtendedState(Frame.MAXIMIZED_BOTH); //maximise window
window.setUndecorated(true); //remove decorations e.g. x in top right
И сделать так, чтобы окно всегда было сверху (Чтобы люди не пользовались другими запущенными программами);
window.setAlwaysOnTop(true);
Вы не сможете сделать это на уровне Java — вам нужно перевести операционную систему в какой-то «режим киоска».
Нежелательный комментарий. Вам это нужно, потому что вы (или ваш клиент) ненавидите своих пользователей и хотите, чтобы они вечно проклинали вас? Планируете ли вы добавить в свою программу такие функции, как «выключить компьютер»?
Если вам нужна полноэкранная поддержка, я использую этот код. Должно быть достаточно, чтобы вы начали. Вам просто нужна глобальная логическая переменная, чтобы сказать, является ли приложение полноэкранным или нет. Вы можете повозиться с ним, чтобы он отображал то, что вам нравится.
/**
* 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();
}
}