001: package example;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005:
006: import abbot.Log;
007: import abbot.tester.ComponentTester;
008:
009: public class AWTCode {
010:
011: private static class PopupListener extends MouseAdapter {
012: PopupMenu menu;
013:
014: public PopupListener(PopupMenu menu) {
015: this .menu = menu;
016: }
017:
018: private void showPopup(MouseEvent e) {
019: menu.show(e.getComponent(), e.getX(), e.getY());
020: }
021:
022: public void mousePressed(MouseEvent e) {
023: if (e.isPopupTrigger())
024: showPopup(e);
025: }
026:
027: public void mouseReleased(MouseEvent e) {
028: if (e.isPopupTrigger())
029: showPopup(e);
030: }
031: }
032:
033: public static void main(String[] args) {
034: args = Log.init(args);
035: Frame frame = new Frame("AWT Code");
036: MenuBar mb = new MenuBar() {
037: protected void processEvent(AWTEvent e) {
038: Log.debug("Got " + ComponentTester.toString(e));
039: super .processEvent(e);
040: }
041: };
042: Menu menu = new Menu("File") {
043: protected void processEvent(AWTEvent e) {
044: Log.debug("Got " + ComponentTester.toString(e));
045: super .processEvent(e);
046: }
047: };
048: MenuItem mi = new MenuItem("Open") {
049: protected void processEvent(AWTEvent e) {
050: Log.debug("Got " + ComponentTester.toString(e));
051: super .processEvent(e);
052: }
053: };
054: menu.add(mi);
055: menu.add(new CheckboxMenuItem("Check Me"));
056: mb.add(menu);
057: TextField tf = new TextField("Text Field");
058: TextArea ta = new TextArea("Text Area with wide/long text"
059: + "\n\n\n\n\n\n\n");
060: ta.setSize(200, 100);
061:
062: Panel pane = new Panel();
063: // Button, Canvas, Checkbox, Choice, Label, List, Scrollbar
064: // TextComponent, TextField, TextArea
065: // Container, Panel, ScrollPane, Window, Frame, Dialog
066: Choice choice = new Choice();
067: choice.add("One");
068: choice.add("Two");
069: List list = new List();
070: list.add("One");
071: list.add("Two");
072: list.add("Three");
073: ScrollPane sp = new ScrollPane();
074: Canvas canvas = new Canvas();
075: canvas.setSize(500, 500);
076: sp.add(canvas);
077: sp.setSize(100, 100);
078:
079: pane.add(new Button("Button"));
080: pane.add(sp); // canvas within scrollpane
081: pane.add(new Checkbox("Checkbox"));
082: pane.add(choice);
083: Label label = new Label("Label");
084: pane.add(label);
085: pane.add(list);
086: pane.add(tf);
087: pane.add(new Scrollbar());
088: pane.add(ta);
089:
090: PopupMenu popup = new PopupMenu("MyPopupMenu");
091: popup.add(mi = new MenuItem("first"));
092: mi.addActionListener(new ActionListener() {
093: public void actionPerformed(ActionEvent e) {
094: System.out.println("Got first popup item");
095: }
096: });
097: popup.add(new MenuItem("second"));
098: popup.add(new CheckboxMenuItem("check me"));
099: pane.add(popup);
100: pane.addMouseListener(new PopupListener(popup));
101:
102: frame.setMenuBar(mb);
103: frame.add(pane);
104: frame.addWindowListener(new WindowAdapter() {
105: public void windowClosing(WindowEvent e) {
106: System.exit(0);
107: }
108: });
109:
110: frame.pack();
111: frame.setSize(300, 400);
112: frame.setVisible(true);
113: }
114: }
|