import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.Robot;
import java.awt.Event;
import java.awt.AWTException;
public class keyboard implements ActionListener
{
int i;
String s[] = {"esc","F1","F2","F3","F4","F5",
"F6","F7","F8","F9","F10","F11","F12",
"psc","slk","pau","A","B","C","D","E",
"F"};
String g = "";
Object b;
JMenuBar m = new JMenuBar();
JMenu m1 = new JMenu("File");
JMenu m2 = new JMenu("Keyboard");
JMenu m3 = new JMenu("Setting");
JMenu m4 = new JMenu("Help");
JMenuItem m11 = new JMenuItem("Exit");
JMenuItem m21 = new JMenuItem("StandardKeyboard");
JMenuItem m22 = new JMenuItem("ExtendedKeyboard");
JMenuItem m26 = new JMenuItem("RegularLayout");
JMenuItem m23 = new JMenuItem("101");
JMenuItem m24 = new JMenuItem("102");
JMenuItem m25 = new JMenuItem("106");
JMenuItem m31 = new JMenuItem("Always On Top");
JMenuItem m41 = new JMenuItem("About On-Screen Keyboard");
JFrame f = new JFrame();
JButton j[] = new JButton[(s.length)];
Robot r;
keyboard()
{
m1.add(m11);
m2.add(m21);
m2.add(m22);
m2.addSeparator();
m2.add(m26);
m2.addSeparator();
m2.add(m23);
m2.add(m24);
m2.add(m25);
m3.add(m31);
m4.add(m41);
m.add(m1);
m.add(m2);
m.add(m3);
m.add(m4);
m41.addActionListener(this);
for(i=0;i<s.length;i++)
{
j[i] = new JButton(s[i]);
j[i].setBackground(new Color(255,255,255));
j[i].addActionListener(this);
}
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.setSize(630,200);
Container c = f.getContentPane();
c.setBackground(new Color(33,66,119));
f.setTitle("On-Screen Keyboard");
f.setJMenuBar(m);
for(i=0;i<s.length;i++)
c.add(j[i],JFrame.LEFT_ALIGNMENT);
f.isMaximumSizeSet();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.setFocusableWindowState(false);
try{
Robot r = new Robot();
r.delay(500);
r.keyPress(KeyEvent.VK_7);
}
catch (AWTException e) {
e.printStackTrace();
}
}
public static void main(String args[])
{
keyboard k = new keyboard();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == m41)
JOptionPane.showMessageDialog(null
,"Project By\nPirZada(20)\n"+
"Salman Sayar(22)\n "+
"Wajahat Kareem(16)","About On-Screen Keyboard",
JOptionPane.INFORMATION_MESSAGE);
if(e.getSource() == j[16])
{
}
}
}
Dear all user's please help , i am making on screen keyboard like XP one but i am confused , i want it to behave it like keyboard when i press button 'A' then it write that on the notepad or else , i tried robot class but it always give me an error so please kindly see my this project and help me what can i do to solve this problem