JApplet Not Stopping or Reacting to Keyboard Input

青春壹個敷衍的年華 提交于 2019-12-24 20:17:11

问题


I've been messing around with awt/swing lately trying to learn how to do applets.

I have written the following short JApplet example code, which on the surface seems to work.

The problems I have occur when I try to exit it:

  1. Pressing ESC does nothing, in fact line 38 is never reached when I run it in the debugger (nor is line 94 - it seems as if the overridden function processKeyEvent(KeyEvent e) is not being called by the applet runner upon keypress at all). However, mouse events do seem to be processed (via the debugger I can see line 99 being reached when i move the mouse).
  2. Trying to close/quit eclipse's applet runner causes it to hang, meaning i have to kill the process. That didn't happen when running another applet through it.
  3. the printed '@' is not at the right size, and I suspect it is not drawing using the fixed width font I set it up to use in line 74.

Any idea what I'm doing wrong?

-Ido.


回答1:


It seems that you have not given focus to the applet. When i run it in eclipse, pressing escape does nothing. but when i have clicked inside the grid, pressing escape works just fine. it outputs "not running" in the console. Also closing the applet in eclipse works just fine. Which eclipse version are you running and what Java version?



来源:https://stackoverflow.com/questions/1053673/japplet-not-stopping-or-reacting-to-keyboard-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!