author | sundar |
Mon, 31 Aug 2015 17:51:02 +0530 | |
changeset 32434 | 769b3d81ae69 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 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 | 3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
|
5 |
* modification, are permitted provided that the following conditions |
|
6 |
* are met: |
|
7 |
* |
|
8 |
* - Redistributions of source code must retain the above copyright |
|
9 |
* notice, this list of conditions and the following disclaimer. |
|
10 |
* |
|
11 |
* - Redistributions in binary form must reproduce the above copyright |
|
12 |
* notice, this list of conditions and the following disclaimer in the |
|
13 |
* documentation and/or other materials provided with the distribution. |
|
14 |
* |
|
5506 | 15 |
* - Neither the name of Oracle nor the names of its |
2 | 16 |
* contributors may be used to endorse or promote products derived |
17 |
* from this software without specific prior written permission. |
|
18 |
* |
|
19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
20 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
21 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
22 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
23 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
24 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
25 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
26 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
27 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
28 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
29 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 |
*/ |
|
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 | 41 |
|
42 |
import java.awt.*; |
|
43 |
import java.util.*; |
|
44 |
import java.awt.event.*; |
|
45 |
import java.applet.Applet; |
|
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 | 49 |
class GraphicsPanel extends Panel { |
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
50 |
|
2 | 51 |
ActionListener al; |
52 |
ItemListener il; |
|
53 |
public GraphicsCards cards; |
|
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 | 58 |
|
59 |
setLayout(new BorderLayout()); |
|
60 |
||
61 |
add("Center", cards = new GraphicsCards()); |
|
62 |
||
63 |
Panel p = new Panel(); |
|
64 |
//p.setLayout(new BorderLayout()); |
|
65 |
||
66 |
Button b = new Button("next"); |
|
67 |
b.addActionListener(al); |
|
68 |
p.add(b); |
|
69 |
||
70 |
b = new Button("previous"); |
|
71 |
b.addActionListener(al); |
|
72 |
p.add(b); |
|
73 |
||
74 |
p.add(new Label("go to:", Label.RIGHT)); |
|
75 |
||
76 |
Choice c = new Choice(); |
|
77 |
c.addItemListener(il); |
|
78 |
p.add(c); |
|
79 |
||
80 |
c.addItem("Arc"); |
|
81 |
c.addItem("Oval"); |
|
82 |
c.addItem("Polygon"); |
|
83 |
c.addItem("Rect"); |
|
84 |
c.addItem("RoundRect"); |
|
85 |
||
86 |
add("North", p); |
|
87 |
||
88 |
setSize(400, 400); |
|
89 |
} |
|
90 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
91 |
@Override |
2 | 92 |
public Dimension getPreferredSize() { |
93 |
return new Dimension(200, 100); |
|
94 |
} |
|
95 |
} |
|
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 | 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 | 102 |
GraphicsPanel mainPanel; |
103 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
104 |
@Override |
2 | 105 |
public void init() { |
106 |
setLayout(new BorderLayout()); |
|
107 |
add("Center", mainPanel = new GraphicsPanel(this)); |
|
108 |
} |
|
109 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
110 |
@Override |
2 | 111 |
public void destroy() { |
112 |
remove(mainPanel); |
|
113 |
} |
|
114 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
115 |
@Override |
2 | 116 |
public void actionPerformed(ActionEvent e) { |
117 |
String arg = e.getActionCommand(); |
|
118 |
||
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 | 123 |
} |
124 |
} |
|
125 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
126 |
@Override |
2 | 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 | 130 |
} |
131 |
||
132 |
public static void main(String args[]) { |
|
133 |
AppletFrame.startApplet("GraphicsTest", "Graphics Test", args); |
|
134 |
} |
|
135 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
136 |
@Override |
2 | 137 |
public String getAppletInfo() { |
138 |
return "An interactive demonstration of some graphics."; |
|
139 |
} |
|
140 |
} // end class GraphicsTest |
|
141 |
||
142 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
143 |
@SuppressWarnings("serial") |
2 | 144 |
class GraphicsCards extends Panel { |
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
145 |
|
2 | 146 |
public GraphicsCards() { |
147 |
setLayout(new CardLayout()); |
|
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 | 153 |
} |
154 |
} // end class GraphicsCards |
|
155 |
||
156 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
157 |
@SuppressWarnings("serial") |
2 | 158 |
class ArcCard extends Panel { |
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
159 |
|
2 | 160 |
public ArcCard() { |
161 |
setLayout(new GridLayout(0, 2)); |
|
162 |
add(new ArcPanel(true)); |
|
163 |
add(new ArcPanel(false)); |
|
164 |
add(new ArcDegreePanel(true)); |
|
165 |
add(new ArcDegreePanel(false)); |
|
166 |
} |
|
167 |
} // end class ArcCard |
|
168 |
||
169 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
170 |
@SuppressWarnings("serial") |
2 | 171 |
class ArcDegreePanel extends Panel { |
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
172 |
|
2 | 173 |
boolean filled; |
174 |
||
175 |
public ArcDegreePanel(boolean filled) { |
|
176 |
this.filled = filled; |
|
177 |
} |
|
178 |
||
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 | 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 | 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 | 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 | 215 |
|
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
216 |
@Override |
2 | 217 |
public void paint(Graphics g) { |
218 |
Rectangle r = getBounds(); |
|
219 |
||
220 |
arcSteps(g, 3, 0, 0, r.width, r.height, Color.orange, Color.blue); |
|
221 |
||
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 | 230 |
|
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 | 239 |
|
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
240 |
} // end paint() |
2 | 241 |
} // end class ArcDegreePanel |
242 |
||
243 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
244 |
@SuppressWarnings("serial") |
2 | 245 |
class ArcPanel extends Panel { |
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
246 |
|
2 | 247 |
boolean filled; |
248 |
||
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 | 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 | 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 | 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 | 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 | 277 |
|
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
278 |
g.setColor(Color.magenta); |
2 | 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 | 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 | 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 | 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 | 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 | 313 |
|
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
314 |
} // end paint() |
2 | 315 |
} // end class ArcPanel |
316 |
||
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 | 337 |
} |
338 |
||
339 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
340 |
class OvalShape extends Shape { |
2 | 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 | 351 |
} |
352 |
||
353 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
354 |
class RoundRectShape extends Shape { |
2 | 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 | 365 |
} |
366 |
||
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 | 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 | 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 | 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 | 391 |
|
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
392 |
} |
2 | 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 | 404 |
} |
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 | 416 |
} |
417 |
} |
|
418 |
||
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 | 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 | 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 | 434 |
|
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
435 |
@Override |
2 | 436 |
public void paint(Graphics g) { |
437 |
Rectangle bounds = getBounds(); |
|
438 |
||
439 |
int cx, cy, cw, ch; |
|
440 |
||
441 |
Color color; |
|
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 | 448 |
g.setColor(color); |
449 |
shape.draw(g, cx, cy, cw, ch); |
|
450 |
} |
|
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 | 456 |
if (g.getColor() == Color.red) { |
457 |
g.setColor(Color.blue); |
|
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
458 |
} else { |
2 | 459 |
g.setColor(Color.red); |
460 |
} |
|
461 |
||
462 |
shape.fill(g, cx, cy, cw, ch); |
|
463 |
} // end for |
|
464 |
} // end paint() |
|
465 |
} // end class ShapeTest |
|
466 |
||
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
467 |
|
2 | 468 |
class ColorUtils { |
8970
9e16ce7c2da2
7027683: /applets/GraphicsTest demo needs to be improved
mrkam
parents:
5506
diff
changeset
|
469 |
|
2 | 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 | 474 |
} |
475 |
||
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 | 480 |
} |
481 |
} |