我正在尝试编写一个 Java 应用程序来监听用户的键输入。这是我的代码...
import java.awt.event.KeyEvent;
public class DashExplorerMain {
public static void main(String[] args) {
DashExplorerMain dashExplorer = new DashExplorerMain();
dashExplorer.keyPressed(e);
}
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
switch( keyCode ) {
case KeyEvent.VK_UP:
// handle up
break;
case KeyEvent.VK_DOWN:
// handle down
break;
case KeyEvent.VK_LEFT:
// handle left
break;
case KeyEvent.VK_RIGHT :
// handle right
System.out.println("-");
break;
}
}
}
}
当我尝试编译我的代码时,我收到以下错误...
Exception in thread "main" java.lang.Error: Unresolved compilation problem: e cannot be resolved to a variable
at DashExplorerMain.main(DashExplorerMain.java:11)
你能帮我理解这个问题吗?