jdk/src/demo/share/applets/GraphicsTest/GraphicsTest.java
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 25859 3317bb8137f4
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments Reviewed-by: attila, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2011, 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
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8970
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    47
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    48
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
class GraphicsPanel extends Panel {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    50
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    ActionListener al;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    ItemListener il;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public GraphicsCards cards;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    55
    GraphicsPanel(EventListener listener) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    56
        al = (ActionListener) listener;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    57
        il = (ItemListener) listener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        add("Center", cards = new GraphicsCards());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        //p.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        Button b = new Button("next");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        b.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        p.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        b = new Button("previous");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        b.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        p.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        p.add(new Label("go to:", Label.RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        Choice c = new Choice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        c.addItemListener(il);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        p.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        c.addItem("Arc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        c.addItem("Oval");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        c.addItem("Polygon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        c.addItem("Rect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        c.addItem("RoundRect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        add("North", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        setSize(400, 400);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    91
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return new Dimension(200, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    97
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
    98
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
public class GraphicsTest extends Applet
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   100
        implements ActionListener, ItemListener {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   101
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    GraphicsPanel mainPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   104
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        add("Center", mainPanel = new GraphicsPanel(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   110
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void destroy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        remove(mainPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   115
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        String arg = e.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if ("next".equals(arg)) {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   120
            ((CardLayout) mainPanel.cards.getLayout()).next(mainPanel.cards);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   121
        } else if ("previous".equals(arg)) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   122
            ((CardLayout) mainPanel.cards.getLayout()).previous(mainPanel.cards);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   126
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public void itemStateChanged(ItemEvent e) {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   128
        ((CardLayout) mainPanel.cards.getLayout()).show(mainPanel.cards,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   129
                (String) e.getItem());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        AppletFrame.startApplet("GraphicsTest", "Graphics Test", args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   136
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public String getAppletInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return "An interactive demonstration of some graphics.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}   // end class GraphicsTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   143
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
class GraphicsCards extends Panel {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public GraphicsCards() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        setLayout(new CardLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        add("Arc", new ArcCard());
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   149
        add("Oval", new ShapeTest(new OvalShape()));
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   150
        add("Polygon", new ShapeTest(new PolygonShape()));
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   151
        add("Rect", new ShapeTest(new RectShape()));
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   152
        add("RoundRect", new ShapeTest(new RoundRectShape()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}   // end class GraphicsCards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   157
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
class ArcCard extends Panel {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   159
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public ArcCard() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setLayout(new GridLayout(0, 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        add(new ArcPanel(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        add(new ArcPanel(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        add(new ArcDegreePanel(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        add(new ArcDegreePanel(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
}   // end class ArcCard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   170
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
class ArcDegreePanel extends Panel {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   172
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    boolean filled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public ArcDegreePanel(boolean filled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this.filled = filled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    void arcSteps(Graphics g,
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   180
            int step,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   181
            int x,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   182
            int y,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   183
            int w,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   184
            int h,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   185
            Color c1,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   186
            Color c2) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   187
        int a1 = 0;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   188
        int a2 = step;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   189
        int progress = 0;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   190
        g.setColor(c1);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   191
        for (; (a1 + a2) <= 360; a1 = a1 + a2, a2 += 1) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   192
            if (g.getColor() == c1) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   193
                g.setColor(c2);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   194
            } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   195
                g.setColor(c1);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   196
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   198
            if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   199
                g.fillArc(x, y, w, h, a1, a2);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   200
            } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   201
                g.drawArc(x, y, w, h, a1, a2);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   202
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   204
            progress = a1 + a2;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   205
        }  // end for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   207
        if (progress != 360) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   208
            if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   209
                g.fillArc(x, y, w, h, a1, 360 - progress);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   210
            } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   211
                g.drawArc(x, y, w, h, a1, 360 - progress);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   212
            }
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   213
        }  // end if
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   214
    }  // end arcSteps()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   216
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        arcSteps(g, 3, 0, 0, r.width, r.height, Color.orange, Color.blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        arcSteps(g,
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   223
                2,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   224
                r.width / 4,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   225
                r.height / 4,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   226
                r.width / 2,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   227
                r.height / 2,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   228
                Color.yellow,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   229
                Color.green);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        arcSteps(g,
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   232
                1,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   233
                (r.width * 3) / 8,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   234
                (r.height * 3) / 8,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   235
                r.width / 4,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   236
                r.height / 4,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   237
                Color.magenta,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   238
                Color.white);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   240
    }  // end paint()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
}   // end class ArcDegreePanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   244
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
class ArcPanel extends Panel {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   246
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    boolean filled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public ArcPanel(boolean filled) {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   250
        this.filled = filled;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   251
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   253
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   254
    public void paint(Graphics g) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   255
        Rectangle r = getBounds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   257
        g.setColor(Color.yellow);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   258
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   259
            g.fillArc(0, 0, r.width, r.height, 0, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   260
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   261
            g.drawArc(0, 0, r.width, r.height, 0, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   262
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   264
        g.setColor(Color.green);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   265
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   266
            g.fillArc(0, 0, r.width, r.height, 90, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   267
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   268
            g.drawArc(0, 0, r.width, r.height, 90, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   269
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   271
        g.setColor(Color.orange);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   272
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   273
            g.fillArc(0, 0, r.width, r.height, 135, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   274
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   275
            g.drawArc(0, 0, r.width, r.height, 135, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   276
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   278
        g.setColor(Color.magenta);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   280
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   281
            g.fillArc(0, 0, r.width, r.height, -225, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   282
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   283
            g.drawArc(0, 0, r.width, r.height, -225, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   284
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   286
        g.setColor(Color.yellow);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   287
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   288
            g.fillArc(0, 0, r.width, r.height, 225, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   289
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   290
            g.drawArc(0, 0, r.width, r.height, 225, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   291
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   293
        g.setColor(Color.green);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   294
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   295
            g.fillArc(0, 0, r.width, r.height, -135, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   296
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   297
            g.drawArc(0, 0, r.width, r.height, -135, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   298
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   300
        g.setColor(Color.orange);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   301
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   302
            g.fillArc(0, 0, r.width, r.height, -45, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   303
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   304
            g.drawArc(0, 0, r.width, r.height, -45, -45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   305
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   307
        g.setColor(Color.magenta);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   308
        if (filled) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   309
            g.fillArc(0, 0, r.width, r.height, 315, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   310
        } else {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   311
            g.drawArc(0, 0, r.width, r.height, 315, 45);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   312
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   314
    }  // end paint()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}   // end class ArcPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   318
abstract class Shape {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   319
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   320
    abstract void draw(Graphics g, int x, int y, int w, int h);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   321
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   322
    abstract void fill(Graphics g, int x, int y, int w, int h);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   323
}
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   324
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   325
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   326
class RectShape extends Shape {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   327
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   328
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   329
    void draw(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   330
        g.drawRect(x, y, w, h);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   331
    }
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   332
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   333
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   334
    void fill(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   335
        g.fillRect(x, y, w, h);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   336
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   340
class OvalShape extends Shape {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   342
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   343
    void draw(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   344
        g.drawOval(x, y, w, h);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   345
    }
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   346
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   347
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   348
    void fill(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   349
        g.fillOval(x, y, w, h);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   350
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   354
class RoundRectShape extends Shape {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   356
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   357
    void draw(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   358
        g.drawRoundRect(x, y, w, h, 10, 10);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   359
    }
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   360
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   361
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   362
    void fill(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   363
        g.fillRoundRect(x, y, w, h, 10, 10);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   364
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   368
class PolygonShape extends Shape {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   369
    // class variables
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   371
    Polygon p;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   372
    Polygon pBase;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   374
    public PolygonShape() {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   375
        pBase = new Polygon();
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   376
        pBase.addPoint(0, 0);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   377
        pBase.addPoint(10, 0);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   378
        pBase.addPoint(5, 15);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   379
        pBase.addPoint(10, 20);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   380
        pBase.addPoint(5, 20);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   381
        pBase.addPoint(0, 10);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   382
        pBase.addPoint(0, 0);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   383
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   385
    void scalePolygon(float w, float h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   386
        p = new Polygon();
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   387
        for (int i = 0; i < pBase.npoints; ++i) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   388
            p.addPoint((int) (pBase.xpoints[i] * w),
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   389
                    (int) (pBase.ypoints[i] * h));
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   390
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   392
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   394
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   395
    void draw(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   396
        Graphics ng = g.create();
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   397
        try {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   398
            ng.translate(x, y);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   399
            scalePolygon(((float) w / 10f), ((float) h / 20f));
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   400
            ng.drawPolygon(p);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   401
        } finally {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   402
            ng.dispose();
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   403
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   406
    @Override
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   407
    void fill(Graphics g, int x, int y, int w, int h) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   408
        Graphics ng = g.create();
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   409
        try {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   410
            ng.translate(x, y);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   411
            scalePolygon(((float) w / 10f), ((float) h / 20f));
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   412
            ng.fillPolygon(p);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   413
        } finally {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   414
            ng.dispose();
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   415
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   420
@SuppressWarnings("serial")
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   421
class ShapeTest extends Panel {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   422
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   423
    Shape shape;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   424
    int step;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   426
    public ShapeTest(Shape shape, int step) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   427
        this.shape = shape;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   428
        this.step = step;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   429
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   431
    public ShapeTest(Shape shape) {
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   432
        this(shape, 10);
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   433
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   435
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        int cx, cy, cw, ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        Color color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   443
        for (color = Color.red, cx = bounds.x, cy = bounds.y,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   444
                cw = bounds.width / 2, ch = bounds.height;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   445
                cw > 0 && ch > 0;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   446
                cx += step, cy += step, cw -= (step * 2), ch -= (step * 2),
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   447
                color = ColorUtils.darker(color, 0.9)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            shape.draw(g, cx, cy, cw, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   452
        for (cx = bounds.x + bounds.width / 2, cy = bounds.y,
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   453
                cw = bounds.width / 2, ch = bounds.height;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   454
                cw > 0 && ch > 0;
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   455
                cx += step, cy += step, cw -= (step * 2), ch -= (step * 2)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (g.getColor() == Color.red) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                g.setColor(Color.blue);
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   458
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                g.setColor(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            shape.fill(g, cx, cy, cw, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }  // end for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }  // end paint()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
}   // end class ShapeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   467
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
class ColorUtils {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   469
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    static Color brighter(Color c, double factor) {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   471
        return new Color(Math.min((int) (c.getRed() * (1 / factor)), 255),
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   472
                Math.min((int) (c.getGreen() * (1 / factor)), 255),
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   473
                Math.min((int) (c.getBlue() * (1 / factor)), 255));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    static Color darker(Color c, double factor) {
8970
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   477
        return new Color(Math.max((int) (c.getRed() * factor), 0),
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   478
                Math.max((int) (c.getGreen() * factor), 0),
9e16ce7c2da2 7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents: 5506
diff changeset
   479
                Math.max((int) (c.getBlue() * factor), 0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
}