44 import java.awt.event.*;
45 import java.applet.Applet;
48 @SuppressWarnings(
"serial")
56 al = (ActionListener) listener;
57 il = (ItemListener) listener;
59 setLayout(
new BorderLayout());
63 Panel p =
new Panel();
66 Button b =
new Button(
"next");
67 b.addActionListener(al);
70 b =
new Button(
"previous");
71 b.addActionListener(al);
74 p.add(
new Label(
"go to:", Label.RIGHT));
76 Choice c =
new Choice();
77 c.addItemListener(il);
84 c.addItem(
"RoundRect");
93 return new Dimension(200, 100);
98 @SuppressWarnings(
"serial")
100 implements ActionListener, ItemListener {
106 setLayout(
new BorderLayout());
117 String arg = e.getActionCommand();
119 if (
"next".equals(arg)) {
120 ((CardLayout) mainPanel.
cards.getLayout()).next(mainPanel.
cards);
121 }
else if (
"previous".equals(arg)) {
122 ((CardLayout) mainPanel.
cards.getLayout()).previous(mainPanel.
cards);
128 ((CardLayout) mainPanel.
cards.getLayout()).show(mainPanel.
cards,
129 (String) e.getItem());
132 public static void main(String args[]) {
138 return "An interactive demonstration of some graphics.";
143 @SuppressWarnings(
"serial")
147 setLayout(
new CardLayout());
157 @SuppressWarnings(
"serial")
161 setLayout(
new GridLayout(0, 2));
170 @SuppressWarnings(
"serial")
176 this.filled = filled;
191 for (; (a1 + a2) <= 360; a1 = a1 + a2, a2 += 1) {
192 if (g.getColor() == c1) {
199 g.fillArc(x, y, w, h, a1, a2);
201 g.drawArc(x, y, w, h, a1, a2);
207 if (progress != 360) {
209 g.fillArc(x, y, w, h, a1, 360 - progress);
211 g.drawArc(x, y, w, h, a1, 360 - progress);
218 Rectangle r = getBounds();
220 arcSteps(g, 3, 0, 0, r.width, r.height, Color.orange, Color.blue);
244 @SuppressWarnings(
"serial")
250 this.filled = filled;
255 Rectangle r = getBounds();
257 g.setColor(Color.yellow);
259 g.fillArc(0, 0, r.width, r.height, 0, 45);
261 g.drawArc(0, 0, r.width, r.height, 0, 45);
264 g.setColor(Color.green);
266 g.fillArc(0, 0, r.width, r.height, 90, -45);
268 g.drawArc(0, 0, r.width, r.height, 90, -45);
271 g.setColor(Color.orange);
273 g.fillArc(0, 0, r.width, r.height, 135, -45);
275 g.drawArc(0, 0, r.width, r.height, 135, -45);
278 g.setColor(Color.magenta);
281 g.fillArc(0, 0, r.width, r.height, -225, 45);
283 g.drawArc(0, 0, r.width, r.height, -225, 45);
286 g.setColor(Color.yellow);
288 g.fillArc(0, 0, r.width, r.height, 225, -45);
290 g.drawArc(0, 0, r.width, r.height, 225, -45);
293 g.setColor(Color.green);
295 g.fillArc(0, 0, r.width, r.height, -135, 45);
297 g.drawArc(0, 0, r.width, r.height, -135, 45);
300 g.setColor(Color.orange);
302 g.fillArc(0, 0, r.width, r.height, -45, -45);
304 g.drawArc(0, 0, r.width, r.height, -45, -45);
307 g.setColor(Color.magenta);
309 g.fillArc(0, 0, r.width, r.height, 315, 45);
311 g.drawArc(0, 0, r.width, r.height, 315, 45);
318 abstract class Shape {
320 abstract void draw(Graphics g,
int x,
int y,
int w,
int h);
322 abstract void fill(Graphics g,
int x,
int y,
int w,
int h);
329 void draw(Graphics g,
int x,
int y,
int w,
int h) {
330 g.drawRect(x, y, w, h);
334 void fill(Graphics g,
int x,
int y,
int w,
int h) {
335 g.fillRect(x, y, w, h);
343 void draw(Graphics g,
int x,
int y,
int w,
int h) {
344 g.drawOval(x, y, w, h);
348 void fill(Graphics g,
int x,
int y,
int w,
int h) {
349 g.fillOval(x, y, w, h);
357 void draw(Graphics g,
int x,
int y,
int w,
int h) {
358 g.drawRoundRect(x, y, w, h, 10, 10);
362 void fill(Graphics g,
int x,
int y,
int w,
int h) {
363 g.fillRoundRect(x, y, w, h, 10, 10);
375 pBase =
new Polygon();
376 pBase.addPoint(0, 0);
377 pBase.addPoint(10, 0);
378 pBase.addPoint(5, 15);
379 pBase.addPoint(10, 20);
380 pBase.addPoint(5, 20);
381 pBase.addPoint(0, 10);
382 pBase.addPoint(0, 0);
387 for (
int i = 0; i <
pBase.npoints; ++i) {
388 p.addPoint((
int) (
pBase.xpoints[i] * w),
389 (
int) (
pBase.ypoints[i] * h));
395 void draw(Graphics g,
int x,
int y,
int w,
int h) {
396 Graphics ng = g.create();
407 void fill(Graphics g,
int x,
int y,
int w,
int h) {
408 Graphics ng = g.create();
420 @SuppressWarnings(
"serial")
437 Rectangle bounds = getBounds();
443 for (color = Color.red, cx = bounds.x, cy = bounds.y,
444 cw = bounds.width / 2, ch = bounds.height;
446 cx += step, cy += step, cw -= (step * 2), ch -= (step * 2),
449 shape.draw(g, cx, cy, cw, ch);
452 for (cx = bounds.x + bounds.width / 2, cy = bounds.y,
453 cw = bounds.width / 2, ch = bounds.height;
455 cx += step, cy += step, cw -= (step * 2), ch -= (step * 2)) {
456 if (g.getColor() == Color.red) {
457 g.setColor(Color.blue);
459 g.setColor(Color.red);
462 shape.fill(g, cx, cy, cw, ch);
471 return new Color(Math.min((
int) (c.getRed() * (1 / factor)), 255),
472 Math.min((
int) (c.getGreen() * (1 / factor)), 255),
473 Math.min((
int) (c.getBlue() * (1 / factor)), 255));
476 static Color
darker(Color c,
double factor) {
477 return new Color(Math.max((
int) (c.getRed() * factor), 0),
478 Math.max((
int) (c.getGreen() * factor), 0),
479 Math.max((
int) (c.getBlue() * factor), 0));