我環顧了一下,我似乎無法找到我的問題的答案...據我所知,這應該工作正常,但我顯然缺少的東西。如何讓keyevent在applet中工作?
我有這一點的代碼,當我按下時,當我釋放回車鍵,但似乎沒有工作,這應該打印一些東西到控制檯。請有人可能幫助我嗎?謝謝!
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) {
}
}
爲什麼要編寫一個小程序?如果由於規格而到期。由老師,請參考[爲什麼CS老師應該停止教Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/)。 –