java 键盘监听 按一次键监听到两次
publicgameWin()//构造方法{for(inti=0;i<10;i++){for(intj=0;j<18;j++){map[i][j]=0;}}for(int...
public gameWin()//构造方法
{
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 18; j++) {
map[i][j] = 0;
}
}
for (int i = 0; i < fangkuai.length; i++) {
fangkuai[i] = new gamefangkuai();
}
setLayout(new FlowLayout(FlowLayout.RIGHT));
this.add(newgame);
this.add(endgame);
newgame.addActionListener(this);
endgame.addActionListener(this);
addKeyListener(this);
}
public void keyPressed(KeyEvent e) //键盘监听部分代码
{
// TODO Auto-generated method stub
if (start){
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:
down();
break;
case KeyEvent.VK_UP:
//move(0,1);
break;
case KeyEvent.VK_LEFT:
System.out.println("anjian1ci");//发现按一次键 打印2次 键盘没坏
move(-1,0);
break;
case KeyEvent.VK_RIGHT:
move(1,0);
break;
default:
break;
}
}
} 展开
{
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 18; j++) {
map[i][j] = 0;
}
}
for (int i = 0; i < fangkuai.length; i++) {
fangkuai[i] = new gamefangkuai();
}
setLayout(new FlowLayout(FlowLayout.RIGHT));
this.add(newgame);
this.add(endgame);
newgame.addActionListener(this);
endgame.addActionListener(this);
addKeyListener(this);
}
public void keyPressed(KeyEvent e) //键盘监听部分代码
{
// TODO Auto-generated method stub
if (start){
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:
down();
break;
case KeyEvent.VK_UP:
//move(0,1);
break;
case KeyEvent.VK_LEFT:
System.out.println("anjian1ci");//发现按一次键 打印2次 键盘没坏
move(-1,0);
break;
case KeyEvent.VK_RIGHT:
move(1,0);
break;
default:
break;
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询