[英]Java Swing GUI Hidden Input
I made a simple JFrame with Swing. 我用Swing制作了一个简单的JFrame。 I want to know how I would go about making a non-visible input that would open up another JFrame I have in another class.
我想知道如何进行不可见的输入,以打开另一个类中的另一个JFrame。 (Like cheat codes in video games, you enter a combination and something happens.) I am not sure how to capture the user input without a text field.
(就像视频游戏中的作弊代码一样,您输入一个组合就会发生某些事情。)我不确定如何在没有文本字段的情况下捕获用户输入。
You should use keybinding attached to your JFrame. 您应该使用附加到JFrame的键绑定 。 You would want to store keystrokes as a String internally and after each keystroke, see whether the user has entered a recognizable cheat code or just listen for a return keypress as a delimiter for the code.
您可能希望将击键内部存储为String,并且在每次击键之后,查看用户是否输入了可识别的作弊代码,或者只是侦听返回的按键作为该代码的定界符。
Keep in mind that if a component within that JFrame has focus and also implements the same key bindings, then that component will take precedence over the JFrame, effectively intercepting the keystrokes. 请记住,如果该JFrame中的某个组件具有焦点并且还实现了相同的键绑定,则该组件将优先于JFrame,从而有效地拦截了击键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.