7 Replies - 2010 Views - Last Post: 30 March 2007 - 10:44 AM Rate Topic: -----

#1 LoganLooker   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 01-February 07

Why doesn't my GamePanel work?

Posted 25 February 2007 - 02:34 PM

Ok here's another newb question lol from the one and only LoganLooker!?!

"Why Doesn't My GamePanel Work?"

public class GamePanel extends Jpanel implements runnable
{
 private static final int PWIDTH = 500;
 private static final int PHIEGTH = 500;

 private Thread animator;
 private volatile boolean running = false;

 private volatile boolean gameOver = false;

 public GamePanel();
{

  setBackground(Color.white);
  setPreferredSize( new Dimension(PWIDTH, PHEIGTH));
}

public void addNotify()
/* Wait for the JPanel to be added to the
   JFrame/JApplet before starting. */
{
  super.addNotify();
  startGame();
}

private void startGame()
{
  if (animator == null || !running) {
	animator = new Thread(this);
	animator.start();
  }
}

public void stopGame()
{  running = false;  }


public void run()
/* Repeatedly update, render, sleep */
{
  running = true;
  while(running) {
	gameUpdate();
	gameRender();
	repaint();

	try {
	  Thread.sleep(20);
	}
	catch(InterruptedException ex){}
  }
  System.exit(0);
}


private void gameUpdate()
{ if (!gameOver)

}


}


This should be correct wrote this down straight from the book?

Is This A Good Question/Topic? 0
  • +

Replies To: Why doesn't my GamePanel work?

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Why doesn't my GamePanel work?

Posted 25 February 2007 - 06:38 PM

Can you provide a description as to the meaning of 'does not work'? Does it not work as expected? If that is the case, what is the undesired behaviour? Or the missing desired behaviour? Does it not compile?
Was This Post Helpful? 0
  • +
  • -

#3 LoganLooker   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 01-February 07

Re: Why doesn't my GamePanel work?

Posted 26 February 2007 - 09:44 AM

View PostAmadeus, on 25 Feb, 2007 - 06:38 PM, said:

Can you provide a description as to the meaning of 'does not work'? Does it not work as expected? If that is the case, what is the undesired behaviour? Or the missing desired behaviour? Does it not compile?


The program doesn't compile it says this

GamePanel().59 still prasing
}
^

What is this and how do i correct?
Was This Post Helpful? 0
  • +
  • -

#4 Spider   User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Why doesn't my GamePanel work?

Posted 02 March 2007 - 04:55 AM

the problem is here:
private void gameUpdate()
{ if (!gameOver)

}


After your if statement, the program is expecting either a single command, or brackets to contain multiple commands. You have neither of these.
If you just add a pair of empty curly brackets it should compile fine.
Was This Post Helpful? 0
  • +
  • -

#5 LoganLooker   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 01-February 07

Re: Why doesn't my GamePanel work?

Posted 04 March 2007 - 09:07 PM

so i change this to
private void gameUpdate()
{ if (!gameOver)

}


This?
private void gameUpdate()
{ if (!gameOver)

}
{}


is this correct?
Was This Post Helpful? 0
  • +
  • -

#6 realNoName   User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 343
  • Joined: 04-December 06

Re: Why doesn't my GamePanel work?

Posted 04 March 2007 - 10:35 PM

 private void gameUpdate()
{
  if (!gameOver)
  {
  }
}

Was This Post Helpful? 0
  • +
  • -

#7 Liontrue1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 48
  • View blog
  • Posts: 811
  • Joined: 20-May 06

Re: Why doesn't my GamePanel work?

Posted 30 March 2007 - 09:24 AM

View PostrealNoName, on 5 Mar, 2007 - 01:35 AM, said:

 private void gameUpdate()
{
  if (!gameOver)
  {
  }
}


The above code is correct. Do not get mixed up in block scopes! An easy trick I use is adding tabs in the code:

private void gameUpdate(){
	if (!gameOver){

	}
}



I hope it makes some sense to you. This is a beginner thing everyone should understand. You can nest a lot of if's in a block, so you should definitly use tabs. Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#8 LoganLooker   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 01-February 07

Re: Why doesn't my GamePanel work?

Posted 30 March 2007 - 10:44 AM

thank you for that it really helps me!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1