1
|
|
package example;
|
2
|
|
|
3
|
|
import java.awt.*;
|
4
|
|
import java.awt.event.*;
|
5
|
|
|
6
|
|
import abbot.Log;
|
7
|
|
import abbot.tester.ComponentTester;
|
8
|
|
|
9
|
|
public class AWTCode {
|
10
|
|
|
11
|
|
private static class PopupListener extends MouseAdapter {
|
12
|
|
PopupMenu menu;
|
13
|
0
|
public PopupListener(PopupMenu menu) {
|
14
|
0
|
this.menu = menu;
|
15
|
|
}
|
16
|
0
|
private void showPopup(MouseEvent e) {
|
17
|
0
|
menu.show(e.getComponent(), e.getX(), e.getY());
|
18
|
|
}
|
19
|
0
|
public void mousePressed(MouseEvent e) {
|
20
|
0
|
if (e.isPopupTrigger())
|
21
|
0
|
showPopup(e);
|
22
|
|
}
|
23
|
0
|
public void mouseReleased(MouseEvent e) {
|
24
|
0
|
if (e.isPopupTrigger())
|
25
|
0
|
showPopup(e);
|
26
|
|
}
|
27
|
|
}
|
28
|
|
|
29
|
0
|
public static void main(String[] args) {
|
30
|
0
|
args = Log.init(args);
|
31
|
0
|
Frame frame = new Frame("AWT Code");
|
32
|
0
|
MenuBar mb = new MenuBar() {
|
33
|
0
|
protected void processEvent(AWTEvent e) {
|
34
|
0
|
Log.debug("Got " + ComponentTester.toString(e));
|
35
|
0
|
super.processEvent(e);
|
36
|
|
}
|
37
|
|
};
|
38
|
0
|
Menu menu = new Menu("File") {
|
39
|
0
|
protected void processEvent(AWTEvent e) {
|
40
|
0
|
Log.debug("Got " + ComponentTester.toString(e));
|
41
|
0
|
super.processEvent(e);
|
42
|
|
}
|
43
|
|
};
|
44
|
0
|
MenuItem mi = new MenuItem("Open") {
|
45
|
0
|
protected void processEvent(AWTEvent e) {
|
46
|
0
|
Log.debug("Got " + ComponentTester.toString(e));
|
47
|
0
|
super.processEvent(e);
|
48
|
|
}
|
49
|
|
};
|
50
|
0
|
menu.add(mi);
|
51
|
0
|
menu.add(new CheckboxMenuItem("Check Me"));
|
52
|
0
|
mb.add(menu);
|
53
|
0
|
TextField tf = new TextField("Text Field");
|
54
|
0
|
TextArea ta = new TextArea("Text Area with wide/long text"
|
55
|
|
+ "\n\n\n\n\n\n\n");
|
56
|
0
|
ta.setSize(200, 100);
|
57
|
|
|
58
|
0
|
Panel pane = new Panel();
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
0
|
Choice choice = new Choice();
|
63
|
0
|
choice.add("One"); choice.add("Two");
|
64
|
0
|
List list = new List();
|
65
|
0
|
list.add("One"); list.add("Two"); list.add("Three");
|
66
|
0
|
ScrollPane sp = new ScrollPane();
|
67
|
0
|
Canvas canvas = new Canvas();
|
68
|
0
|
canvas.setSize(500, 500);
|
69
|
0
|
sp.add(canvas);
|
70
|
0
|
sp.setSize(100, 100);
|
71
|
|
|
72
|
0
|
pane.add(new Button("Button"));
|
73
|
0
|
pane.add(sp);
|
74
|
0
|
pane.add(new Checkbox("Checkbox"));
|
75
|
0
|
pane.add(choice);
|
76
|
0
|
Label label = new Label("Label");
|
77
|
0
|
pane.add(label);
|
78
|
0
|
pane.add(list);
|
79
|
0
|
pane.add(tf);
|
80
|
0
|
pane.add(new Scrollbar());
|
81
|
0
|
pane.add(ta);
|
82
|
|
|
83
|
0
|
PopupMenu popup = new PopupMenu("MyPopupMenu");
|
84
|
0
|
popup.add(mi = new MenuItem("first"));
|
85
|
0
|
mi.addActionListener(new ActionListener() {
|
86
|
0
|
public void actionPerformed(ActionEvent e) {
|
87
|
0
|
System.out.println("Got first popup item");
|
88
|
|
}
|
89
|
|
});
|
90
|
0
|
popup.add(new MenuItem("second"));
|
91
|
0
|
popup.add(new CheckboxMenuItem("check me"));
|
92
|
0
|
pane.add(popup);
|
93
|
0
|
pane.addMouseListener(new PopupListener(popup));
|
94
|
|
|
95
|
0
|
frame.setMenuBar(mb);
|
96
|
0
|
frame.add(pane);
|
97
|
0
|
frame.addWindowListener(new WindowAdapter() {
|
98
|
0
|
public void windowClosing(WindowEvent e) {
|
99
|
0
|
System.exit(0);
|
100
|
|
}
|
101
|
|
});
|
102
|
|
|
103
|
0
|
frame.pack();
|
104
|
0
|
frame.setSize(300, 400);
|
105
|
0
|
frame.show();
|
106
|
|
}
|
107
|
|
}
|
108
|
|
|