Escape exit

This commit is contained in:
iryupnik 2020-03-31 13:45:48 +02:00
parent ebc662ffa0
commit 810b051145

View File

@ -10,6 +10,7 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.util.LinkedList;
public class WindowOfFreeMove extends JFrame {
@ -28,7 +29,9 @@ public class WindowOfFreeMove extends JFrame {
public static final int KEY_RIGHT = 39;
public static final int KEY_DOWN = 40;
public static final int KEY_EVENT = 69;
public static final int KEY_FULLSCREEN = 115;
public static final int KEY_ESCAPE = 27;
private Canvas canvas;
private DialogBar dialogBar;
@ -47,6 +50,10 @@ public class WindowOfFreeMove extends JFrame {
canvas.repaint();
}
private WindowOfFreeMove windowOfFreeMove(){
return this;
}
public static void setCanPersonMove(boolean canPersonMove) {
WindowOfFreeMove.canPersonMove = canPersonMove;
}
@ -110,6 +117,10 @@ public class WindowOfFreeMove extends JFrame {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KEY_ESCAPE){
dispatchEvent(new WindowEvent(windowOfFreeMove(), WindowEvent.WINDOW_CLOSING));
}
if (e.getKeyCode() == KEY_FULLSCREEN){
if (getExtendedState() == MAXIMIZED_BOTH)
setExtendedState(NORMAL);