java键盘事件 空格键

 

public void keyPressed(KeyEvent e) {//键盘按键按下事件
  // TODO Auto-generated method stub
  switch(e.getKeyCode())
  {
  case KeyEvent.VK_RIGHT:
   dx=5;dy=0;
   break;
  case KeyEvent.VK_LEFT:
   dx=-5;dy=0;
   break;
  case KeyEvent.VK_UP:
   dx=0;dy=-5;
   break;
  case KeyEvent.VK_DOWN:
   dx=0;dy=5;
   break;
  case KeyEvent.VK_SPACE:
   dx=0;dy=0;
   bx=x+13;
   by=y-5;
   flag=1;
   default:
    dx=0;dy=0;   
  }
  x=x+dx;
  y=y+dy;
  
 }
 refurl: http://zhidao.baidu.com/question/248878965.html

 

 

你可能感兴趣的:(java)