import java.applet.*; import java.awt.*;
import java.awt.event.*;
public class Example18_3 extends Applet implements KeyListener
{ Button b;
int x,y;
public void init()
{ b=new Button("1");
b.addKeyListener(this);
add(b);
}
public void KeyPressed(KeyEvent e)
{ x=b.getBounds().x;
y=b.getBounds().y;
if(e.getKeyCode()==KeyEvent.VK_UP)
{ y=y-2;
if(y<=0) y=0;
b.setLocation(x,y);
}
}
public void KeyTyped(KeyEvent e) {}
public void KeyReleased(KeyEvent e) {}
}
这段程序为什么不能通过啊,没发现什么问题啊?提示第三行有错:
Example18_3 is not abstract and does not override abstract method KeyTyped(java.awt.event.KeyEvent) in java.awt.event.KeyListener 帮帮我啊,我是初学者!
import java.awt.event.*;
public class Example18_3 extends Applet implements KeyListener
{ Button b;
int x,y;
public void init()
{ b=new Button("1");
b.addKeyListener(this);
add(b);
}
public void KeyPressed(KeyEvent e)
{ x=b.getBounds().x;
y=b.getBounds().y;
if(e.getKeyCode()==KeyEvent.VK_UP)
{ y=y-2;
if(y<=0) y=0;
b.setLocation(x,y);
}
}
public void KeyTyped(KeyEvent e) {}
public void KeyReleased(KeyEvent e) {}
}
这段程序为什么不能通过啊,没发现什么问题啊?提示第三行有错:
Example18_3 is not abstract and does not override abstract method KeyTyped(java.awt.event.KeyEvent) in java.awt.event.KeyListener 帮帮我啊,我是初学者!
KeyPressed -> keyPressed
KeyTyped -> keyTyped
KeyReleased -> keyReleased
所以就说没有实现接口KeyListener的方法
楼主仔细了!