jdk/src/share/demo/applets/DrawTest/DrawTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 8962 8833da0e7bc9
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.applet.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class DrawTest extends Applet{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    DrawPanel panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    DrawControls controls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        panel = new DrawPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        controls = new DrawControls(panel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        add("Center", panel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        add("South",controls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public void destroy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        remove(panel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        remove(controls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        Frame f = new Frame("DrawTest");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        DrawTest drawTest = new DrawTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        drawTest.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        drawTest.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        f.add("Center", drawTest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        f.setSize(300, 300);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        f.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public String getAppletInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return "A simple drawing program.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final int LINES = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final int POINTS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    int    mode = LINES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    Vector lines = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    Vector colors = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    int x1,y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    int x2,y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public DrawPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        setBackground(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        addMouseMotionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        addMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void setDrawMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        switch (mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
          case LINES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
          case POINTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            this.mode = mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        switch (mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            case LINES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                x2 = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                y2 = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            case POINTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                colors.addElement(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                lines.addElement(new Rectangle(x1, y1, e.getX(), e.getY()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                x1 = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                y1 = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        switch (mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            case LINES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                x1 = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                y1 = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                x2 = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            case POINTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                colors.addElement(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                lines.addElement(new Rectangle(e.getX(), e.getY(), -1, -1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                x1 = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                y1 = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        switch (mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            case LINES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                colors.addElement(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                lines.addElement(new Rectangle(x1, y1, e.getX(), e.getY()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                x2 = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            case POINTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        int np = lines.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        /* draw the current lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        g.setColor(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        for (int i=0; i < np; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            Rectangle p = (Rectangle)lines.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            g.setColor((Color)colors.elementAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (p.width != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                g.drawLine(p.x, p.y, p.width, p.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                g.drawLine(p.x, p.y, p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (mode == LINES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            g.setColor(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if (x2 != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                g.drawLine(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
class DrawControls extends Panel implements ItemListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    DrawPanel target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public DrawControls(DrawPanel target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        setLayout(new FlowLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        setBackground(Color.lightGray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        target.setForeground(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        CheckboxGroup group = new CheckboxGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        Checkbox b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        add(b = new Checkbox(null, group, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        b.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        b.setForeground(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        add(b = new Checkbox(null, group, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        b.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        b.setForeground(Color.green);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        add(b = new Checkbox(null, group, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        b.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        b.setForeground(Color.blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        add(b = new Checkbox(null, group, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        b.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        b.setForeground(Color.pink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        add(b = new Checkbox(null, group, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        b.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        b.setForeground(Color.orange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        add(b = new Checkbox(null, group, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        b.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        b.setForeground(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        target.setForeground(b.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Choice shapes = new Choice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        shapes.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        shapes.addItem("Lines");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        shapes.addItem("Points");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        shapes.setBackground(Color.lightGray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        add(shapes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        g.setColor(Color.lightGray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        g.draw3DRect(0, 0, r.width, r.height, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        int n = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        for(int i=0; i<n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            Component comp = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if (comp instanceof Checkbox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                Point loc = comp.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                Dimension d = comp.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                g.setColor(comp.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                g.drawRect(loc.x-1, loc.y-1, d.width+1, d.height+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  public void itemStateChanged(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    if (e.getSource() instanceof Checkbox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      target.setForeground(((Component)e.getSource()).getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    } else if (e.getSource() instanceof Choice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      String choice = (String) e.getItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
      if (choice.equals("Lines")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        target.setDrawMode(DrawPanel.LINES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      } else if (choice.equals("Points")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        target.setDrawMode(DrawPanel.POINTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}