我环顾四周,似乎找不到问题的答案……据我所知,这应该可以正常工作,但是我显然遗漏了一些东西。
我有这段代码,当我按下和释放回车键时,它应该在控制台上打印一些东西,但这似乎不起作用。有人可以帮我吗?谢谢!
import java.applet.Applet;
import java.awt.event.KeyEvent;
public class test extends Applet implements Runnable {
public static final long serialVersionUID = 1L;
public void start() {
setSize(500, 500);
}
public void run() {
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER) {
System.out.println("You are pressing ENTER!");
}
}
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER) {
System.out.println("You are releasing ENTER!");
}
}
public void keyTyped(KeyEvent e) {
}
}