diff --git a/src/GameFrame.java b/src/GameFrame.java index 523b1e2..afd250f 100644 --- a/src/GameFrame.java +++ b/src/GameFrame.java @@ -28,6 +28,7 @@ public class GameFrame extends JFrame{ try { game = (GamePanel)FileManager.readObjectFromFile("local/game_state", Arrays.asList("Any")); game.gameFrame = main; + game.addUserInterface(); game.startThread(); } catch (IOException | ClassNotFoundException | ClassCastException | SecurityException e) { System.out.println(e); diff --git a/src/GamePanel.java b/src/GamePanel.java index 4f8214e..6b35af5 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -102,6 +102,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ } player = new Player(GAME_WIDTH/2, GAME_HEIGHT/2, playerSpriteArray); //create a player controlled player, set start location to middle of screenk // the height of 35 is set because it is half of the original tile height (i.e., 70px) + addUserInterface(); + this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT)); + } + + public void addUserInterface() { this.setFocusable(true); //make everything in this class appear on the screen this.addKeyListener(this); //start listening for keyboard input // request focus when the CardLayout selects this game @@ -138,7 +143,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ player.mouseMoved(e); } }); - this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT)); } // startThread is to be called after the game has started to avoid any issues TODO: better explanation @@ -146,7 +150,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ //make this class run at the same time as other classes (without this each class would "pause" while another class runs). By using threading we can remove lag, and also allows us to do features like display timers in real time! gameThread = new Thread(this); gameThread.start(); - System.out.println(gameFrame); + System.out.println(gameThread); } //paint is a method in java.awt library that we are overriding. It is a special method - it is called automatically in the background in order to update what appears in the window. You NEVER call paint() yourself @@ -197,6 +201,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ } } for(int i=0; i