public void keyPressed(final KeyEvent k){
  if (k.getKeyCode() == KeyEvent.VK_SPACE) {
  }
  if (k.getKeyCode() != KeyEvent.VK_SPACE) {
  }
  repaint();
}

public void keyPressed ( final KeyEvent k ) { if ( k . getKeyCode ( ) == KeyEvent . VK_SPACE ) { } if ( k . getKeyCode ( ) != KeyEvent . VK_SPACE ) { } repaint ( ) ; }
task to perform when keyboard button is pressed .
