问题
I did everything that was correct and for some reason Eclipse
thinks that the the method gameRender()
is undefined for the type GamePanel
:
package Game_Package;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;
public class GamePanel extends JPanel implements Runnable{
private static final int PWIDTH = 900;
private static final int PHIEGHT = 900;
private Thread animator;
private volatile boolean running = false;
private volatile boolean gameOver = false;
public void gamepanel()
{
setBackground(Color.white);
setPreferredSize( new Dimension(900, 900));
}
public void addNotify( )
/* Wait for the JPanel to be added to the
JFrame/JApplet before starting. */
{
super.addNotify( ); // creates the peer
startGame( ); // start the thread
}
private void startGame( )
// initialise and start the thread
{
if (animator == null || !running) {
animator = new Thread(this);
animator.start( );
}
}
public void stopGame( )
// called by the user to stop execution
{
running = false;
}
public void run( )
/* Repeatedly update, render, sleep */
{
running = true;
while(running) {
gameUpdate( ); // game state is updated
gameRender( ); // render to a buffer
repaint( ); // paint with the buffer
try {
Thread.sleep(20); // sleep a bit
}
catch(InterruptedException ex){
}
}
System.exit(0); // so enclosing JFrame/JApplet exits
}
private void gameUpdate( )
{
if (!gameOver);
}
}
来源:https://stackoverflow.com/questions/20111392/the-method-gamerender-is-undefined-for-the-type-gamepanel