-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonscreen.java
77 lines (71 loc) · 1.57 KB
/
onscreen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class onscreen extends JPanel implements
ActionListener
{
static final String st = "!@#$%^&*()-
=+/789qwertyuiop[]{}456asdfghjkl_;:'\"123zxcvbnm,.<>?`~0";
JButton buttonList[];
String buffer = "";
JLabel i;
JTextField text;
JButton backspace, spaceBar;
public void key()
{
text = new JTextField(68);
text.setActionCommand(""+ buffer);
add(text);
int n = st.length();
buttonList = new JButton[n];
for (int i = 0; i < n; i++) {
buttonList[i] = new JButton( "" + st.charAt(i) );
setBackground(Color.LIGHT_GRAY);
16
add(buttonList[i],"Center");
buttonList[i].addActionListener(this);
}
spaceBar = new JButton("Spacebar Key");
add(spaceBar);
spaceBar.addActionListener(this);
backspace = new JButton("BackSpace Key");
add(backspace);
backspace.addActionListener(this);
}
public void actionPerformed( ActionEvent e) {
int n = st.length();
if (e.getSource() == backspace) {
buffer = buffer.substring(0,buffer.length()-1);
text.setText("" + buffer);
}
else if (e.getSource() == spaceBar){
buffer += " ";
}
else{
for (int i = 0; i < n; i++){
if (e.getSource() == buttonList[i]){
buffer += st.toLowerCase().charAt(i);
text.setText(""+ buffer);
break;
17
}
}
}
}
public onscreen(){
JPanel pane = new JPanel();
add(pane);
}
public static void main(String s[])
{
JFrame frame = new JFrame("ONSCREEN KEYBOARD");
onscreen keys= new onscreen();
frame.getContentPane().add(keys,"Center");
keys.key();
Image
icon=Toolkit.getDefaultToolkit().getImage("src\\logo.png");
frame.setIconImage(icon);
frame.setSize(800,240);
frame.setVisible(true);
}
}