Hi!
I am reading a book of java…
I try to run an example :
**
- Write a description of class GamePanel here.
- @author (your name)
-
@version (a version number or a date)
*/
import javax.swing.JPanel;
public class GamePanel extends JPanel implements Runnable{
// instance variables - replace the example below with your own
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 ;
/**
* Constructor for objects of class GamePanel
*/
public GamePanel()
{
// initialise instance variables
//SetBackground(Color.white);
SetPreferredSize(new Dimension(PWIDTH,PHEIGHT));
}
public void addNotify(){
super.addNotify();
startgame();
}
private 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);
}//end run
private void gameUpadate() {
if (!gameOver){
// agiorna lo stato del gioco
}
}
}// end of class
This need a Frame ora an applet which caontain it , I know… but why when I check error I found more problem ?
I cant compile it!
Thank to all !
And sorry if is a stupid error… :-[