简体   繁体   English

如何在Java中集成虚拟键盘

[英]how to integrate virtual keyboard in java

I want to use virtual keyboard in my java SE application to input some details in various Text Fields. 我想在Java SE应用程序中使用虚拟键盘在各种“文本字段”中输入一些详细信息。 In the same time, I want to integrate the used keyboard in the application. 同时,我想将使用过的键盘集成到应用程序中。 So I want to ask two question: 所以我想问两个问题:

  1. Is there any way to integrate any virtual keyboard in java SE application ? 有没有办法在Java SE应用程序中集成任何虚拟键盘?
  2. If yes, how can I do this integration ? 如果是,我该如何进行集成?

This is all on windows. 这些都在Windows上。

Thanks in advance 提前致谢

I would suggest making multiple buttons for each key. 我建议为每个按键设置多个按钮。 Have an action listener object, and add the instance to every button. 有一个动作侦听器对象,并将实例添加到每个按钮。

actionlistenerclass actionlistenerobj = new actionlistenerclass();
Jbutton z = new JButton ("z")
z.addActionListener(actionlistenerobj)

(obviously you would want to add actionlistenerclass ) (显然,您希望添加actionlistenerclass

Next, have the letter that corresponds to the button get printed each time the button is hit. 接下来,使每次单击按钮时都打印对应于该按钮的字母。 To do this, there are many approaches. 为此,有许多方法。 For example, inside the textbox declaration append the string the user enters: 例如,在文本框声明内添加用户输入的字符串:

JTextField letters = new JTextField(

StringBuilder sb = new StringBuilder();
sb.append("lettervariable")


);

Something like that would take every letter the user enters using on screen gui, and add it into textfield letters. 这样的事情将占用用户在屏幕gui上使用输入的每个字母,并将其添加到文本字段字母中。

~ { Rich }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM