-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathKeyPad.java
More file actions
executable file
·77 lines (70 loc) · 1.9 KB
/
Copy pathKeyPad.java
File metadata and controls
executable file
·77 lines (70 loc) · 1.9 KB
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
package javaforce.webui;
import javaforce.webui.event.*;
/** KeyPad for TextComponent
*
* @author pquiring
*/
public class KeyPad extends PopupPanel implements Click {
private TextComponent field;
private Table table;
private static String[][] cols = {
{"<", "/", "*", "-"},
{"7", "8", "9", "+"},
{"4", "5", "6",null},
{"1", "2", "3","Ent"},
{"0",null, ".",null},
};
public KeyPad(String title, int px) {
super(title);
table = new Table(px, px, 4, 5);
setTitleBarSize(px);
add(table);
for(int col=0;col<cols.length;col++) {
String[] rowchs = cols[col];
for(int row=0;row<rowchs.length;row++) {
String key = rowchs[row];
if (key == null) continue;
Button b = new Button(rowchs[row]);
b.addClickListener(this);
switch (key) {
case "0":
b.setSize(px*2, px);
table.add(b, row, col, 2, 1);
break;
case "Ent":
case "+":
b.setSize(px, px*2);
table.add(b, row, col, 1, 2);
break;
default:
b.setSize(px, px);
table.add(b, row, col);
}
}
}
}
public void show(TextComponent field) {
this.field = field;
field.requestPos();
field.addMovedListener((comp, x, y) -> {
setPosition(field.x, field.y + field.height);
setVisible(true);
});
}
public void onClick(MouseEvent e, Component c) {
Button b = (Button)c;
String txt = b.getText();
if (txt.equals("Ent")) {
setVisible(false);
return;
}
if (txt.equals("<")) {
String oldtxt = field.getText();
if (oldtxt.length() == 0) return;
field.setText(oldtxt.substring(0, oldtxt.length() - 1));
return;
}
String newtxt = field.getText() + txt;
field.setText(newtxt);
}
}