我想将任何文本或键从摆动屏幕键盘写到任何插入符号位置,例如浏览器记事本办公室字词。我得到一些示例布局,但不知道如何使用系统插入符号。请教我它的工作原理。
此示例代码
public class keyboard extends JFrame {
private JPanel contentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
keyboard frame = new keyboard();
frame.setVisible(true);
frame.setAlwaysOnTop(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public keyboard() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
contentPane.setLayout(new GridLayout(3, 3));
for(int i = 1; i <= 9; i++) {
createButton(Integer.toString(i));
}
pack();
}
private void createButton(String label)
{
JButton btn = new JButton(label);
btn.setFocusPainted(false);
btn.setPreferredSize(new Dimension(100, 100));
contentPane.add(btn);
}
public void actionPerformed(ActionEvent e)
{
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
}
});
}
}