From 87338c948431608237a1f0161cb82254a81b187b Mon Sep 17 00:00:00 2001 From: iryupnik Date: Sat, 29 Feb 2020 19:25:39 +0100 Subject: [PATCH] Appending next layer for Dialog Menu --- src/main/java/WindowOfFreeMove.java | 40 ++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/WindowOfFreeMove.java b/src/main/java/WindowOfFreeMove.java index dab1554..a4e455a 100644 --- a/src/main/java/WindowOfFreeMove.java +++ b/src/main/java/WindowOfFreeMove.java @@ -8,40 +8,63 @@ public class WindowOfFreeMove extends JFrame { static final int CANVAS_WIDTH = 20; static final int CANVAS_HEIGHT = 20; + private static boolean isMoveablePerson; + static final int KEY_LEFT = 37; static final int KEY_UP = 38; static final int KEY_RIGHT = 39; static final int KEY_DOWN = 40; private Canvas canvas; + private static JPanel dialogBar; + private JLayeredPane lp; private static Map map; public static Map getMap() { return map; } + public static JPanel getDialogBar() { return dialogBar; } + + public static void setIsMoveablePerson(boolean isMoveablePerson) { + WindowOfFreeMove.isMoveablePerson = isMoveablePerson; + } + + public static void setDialogBar(JPanel dialogBar) { WindowOfFreeMove.dialogBar = dialogBar; } public static void setMap(Map map){ WindowOfFreeMove.map = map; } public static void paintMapOnWindow() {WindowOfFreeMove.map.createMap();} public WindowOfFreeMove() { - setTitle("Ahoj"); - setDefaultCloseOperation(EXIT_ON_CLOSE); + isMoveablePerson = true; + lp = getLayeredPane(); canvas = new Canvas(); canvas.setBackground(Color.white); canvas.setPreferredSize(new Dimension( - CELL_SIZE * CANVAS_WIDTH - 10, - CELL_SIZE * CANVAS_HEIGHT - 10)); + CELL_SIZE * CANVAS_WIDTH, + CELL_SIZE * CANVAS_HEIGHT)); + canvas.setBounds(0,0,CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH); + + dialogBar = new JPanel(); + dialogBar.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4); + dialogBar.setBackground(Color.BLACK); + dialogBar.setVisible(false); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - map.getPerson().setDirection(e.getKeyCode()); + if (isMoveablePerson) + map.getPerson().setDirection(e.getKeyCode()); } }); - add(canvas); - pack(); + lp.add(dialogBar, JLayeredPane.PALETTE_LAYER); + lp.add(canvas, JLayeredPane.PALETTE_LAYER); + + setTitle("Ahoj"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + setBounds(0,0,CELL_SIZE*CANVAS_WIDTH + 15, CELL_SIZE*CANVAS_HEIGHT + 40); setLocationRelativeTo(null); - setResizable(false); + setResizable(true); setVisible(true); + } @@ -75,7 +98,6 @@ public class WindowOfFreeMove extends JFrame { while (true) { map.getPerson().move(); canvas.repaint(); - //sleep(); } }