[英]KeyListener doesn't work on java .awt.Window
I am using a java.awt.Window
for my CDC application. 我正在为CDC应用程序使用
java.awt.Window
。 Now I have opted java.awt.Window because, I wanted a non draggable, non resizeable window for my app and frame.setUndecorated()
is not available in CDC apis. 现在,我选择了java.awt.Window,因为我希望为我的应用程序提供一个不可拖动的,不可调整大小的窗口,并且
frame.setUndecorated()
在CDC api中不可用。
Now the problem is any keypress doesn't work on my window. 现在的问题是任何按键都无法在我的窗口上工作。 I have implemented
keyListener
and override all methods. 我已经实现了
keyListener
并覆盖了所有方法。 still no clue why it behaves so. 仍然不知道为什么会这样。 :(
:(
Note : I am developing this app in J2ME - CDC with Personal profile and not in Java 注意:我正在使用个人配置文件而不是Java在J2ME-CDC中开发此应用程序
This problem is solved! 这个问题解决了! Discovered that KeyListener on a java.awt.Window works only if following conditions are met:
发现只有满足以下条件,才能在java.awt.Window上使用KeyListener:
The owning window/frame of the present Window(which has to handle events) has to be setVisible(true) 当前Window的拥有窗口/框架(必须处理事件)必须设置为Visible(true)
The owning window/frame need to have at least one focusable component. 拥有的窗口/框架需要至少具有一个可聚焦的组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.