PHP expert |
|
Heeft iemand een site waar die vragen beter kunnen dan hier?? Tot dit tijd heb ik een vraag:
class Input implements KeyListener
{
// Variables to store the keylistener and player in
protected Player p;
// Constuctor that takes the keylistener and playerobject as argument
Input( Player p )
{
// Store Player object
this.p = p;
// Init keyListener
addKeyListener(this);
}
// keyTypep event
public void keyTyped( KeyEvent e ) { }
// keyReleased event
public void keyReleased( KeyEvent e ) { }
// KeyPress event
public void keyPressed( KeyEvent e )
{
switch( e.getKeyCode( ) )
{
case KeyEvent.VK_LEFT:
this.p.setPos( -10, 'x' );
break;
case KeyEvent.VK_RIGHT:
this.p.setPos( 10, 'x' );
break;
case KeyEvent.VK_UP:
this.p.setPos( -10, 'y' );
break;
case KeyEvent.VK_DOWN:
this.p.setPos( 10, 'y' );
break;
}
repaint();
}
}
class Input implements KeyListener { // Variables to store the keylistener and player in protected Player p; // Constuctor that takes the keylistener and playerobject as argument Input( Player p ) { // Store Player object this.p = p; // Init keyListener addKeyListener(this); } // keyTypep event public void keyTyped( KeyEvent e ) { } // keyReleased event public void keyReleased( KeyEvent e ) { } // KeyPress event public void keyPressed( KeyEvent e ) { switch( e.getKeyCode( ) ) { case KeyEvent.VK_LEFT: this.p.setPos( -10, 'x' ); break; case KeyEvent.VK_RIGHT: this.p.setPos( 10, 'x' ); break; case KeyEvent.VK_UP: this.p.setPos( -10, 'y' ); break; case KeyEvent.VK_DOWN: this.p.setPos( 10, 'y' ); break; } repaint(); } }
Alleen is addKeyListener(this); en repaint hier fout. Iemand een oplossing?
|