Appending next layer for Dialog Menu
This commit is contained in:
parent
7af14c4637
commit
87338c9484
@ -8,40 +8,63 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
static final int CANVAS_WIDTH = 20;
|
static final int CANVAS_WIDTH = 20;
|
||||||
static final int CANVAS_HEIGHT = 20;
|
static final int CANVAS_HEIGHT = 20;
|
||||||
|
|
||||||
|
private static boolean isMoveablePerson;
|
||||||
|
|
||||||
static final int KEY_LEFT = 37;
|
static final int KEY_LEFT = 37;
|
||||||
static final int KEY_UP = 38;
|
static final int KEY_UP = 38;
|
||||||
static final int KEY_RIGHT = 39;
|
static final int KEY_RIGHT = 39;
|
||||||
static final int KEY_DOWN = 40;
|
static final int KEY_DOWN = 40;
|
||||||
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
|
private static JPanel dialogBar;
|
||||||
|
private JLayeredPane lp;
|
||||||
private static Map map;
|
private static Map map;
|
||||||
|
|
||||||
public static Map getMap() { return 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 setMap(Map map){ WindowOfFreeMove.map = map; }
|
||||||
public static void paintMapOnWindow() {WindowOfFreeMove.map.createMap();}
|
public static void paintMapOnWindow() {WindowOfFreeMove.map.createMap();}
|
||||||
|
|
||||||
public WindowOfFreeMove() {
|
public WindowOfFreeMove() {
|
||||||
setTitle("Ahoj");
|
isMoveablePerson = true;
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
lp = getLayeredPane();
|
||||||
|
|
||||||
canvas = new Canvas();
|
canvas = new Canvas();
|
||||||
canvas.setBackground(Color.white);
|
canvas.setBackground(Color.white);
|
||||||
canvas.setPreferredSize(new Dimension(
|
canvas.setPreferredSize(new Dimension(
|
||||||
CELL_SIZE * CANVAS_WIDTH - 10,
|
CELL_SIZE * CANVAS_WIDTH,
|
||||||
CELL_SIZE * CANVAS_HEIGHT - 10));
|
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() {
|
addKeyListener(new KeyAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
map.getPerson().setDirection(e.getKeyCode());
|
if (isMoveablePerson)
|
||||||
|
map.getPerson().setDirection(e.getKeyCode());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
add(canvas);
|
lp.add(dialogBar, JLayeredPane.PALETTE_LAYER);
|
||||||
pack();
|
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);
|
setLocationRelativeTo(null);
|
||||||
setResizable(false);
|
setResizable(true);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +98,6 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
while (true) {
|
while (true) {
|
||||||
map.getPerson().move();
|
map.getPerson().move();
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
//sleep();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user