I am learning Java (The Gaming Side). I bought a book and it has a code in which I tried to copy and test it. The only problem is that it occurs with errors when trying to compile it.
C:\Users\James\Desktop\Java>Javac GamePanel.java GamePanel.java:57: illegal start of expression private void gameUpdate() ^ GamePanel.java:57: illegal start of expression private void gameUpdate() ^ GamePanel.java:57: ';' expected private void gameUpdate() ^ GamePanel.java:64: reached end of file while parsing }โ ^ 4 errors
Code:
public class GamePanel extends JPanel implements Runnable { private static final int PWIDTH = 500; private static final int PHEIGHT = 400; private Thread animator; private volatile boolean running = false; private volatile boolean gameOver = false; public GamePanel() { setBackground(Color.white); setPreferredSize( newDimension(PWIDTH, PHEIGHT)); } public void addNotify() { super.addNotify(); startGame(); } public void startGame() { if (animator == null || !running) { animator = new Thread(this); animator.start(); } } public void stopGame() { running = false; } public void run() { running = true; while(running) { gameUpdate(); gameRender(); repaint(); try { Thread.sleep(20); } catch(InterruptedException ex) { } System.exit(0); } private void gameUpdate() { if (gameOver == false) { } } }
I know that I'm probably doing something wrong, but I checked it again and again, can someone please enlighten me on what I am doing wrong?
source share