001: /*
002: * @(#)DrawDemo.java 1.5 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026: package basis.demos;
027:
028: import java.awt.*;
029: import basis.Builder;
030:
031: public class DrawDemo extends Demo {
032: private int x;
033: private int y;
034: private int w;
035: private int h;
036: private int i;
037:
038: public void paint(Graphics g) {
039: Dimension d = getSize();
040: i = (d.width + d.height) / 100;
041: // lines
042: x = 0;
043: y = 0;
044: w = d.width / 4 - i;
045: h = d.height - 1;
046: g.setColor(Builder.SUN_BLUE);
047: g.drawLine(x, y, x + w, y + h);
048: g.drawLine(x + w / 2, y, x + w / 2, y + h);
049: g.drawLine(x + w, y, x, y + h);
050: g.drawLine(x, y + h / 2, x + w, y + h / 2);
051: // rects
052: x = 0;
053: x = d.width / 4;
054: y = 0;
055: w = d.width / 4 - i;
056: h = d.height - 1;
057: g.setColor(Builder.SUN_BLUE);
058: g.drawRect(x, y, w, h);
059: adjust();
060: g.fillRect(x, y, w, h);
061: g.setColor(Builder.SUN_YELLOW);
062: adjust();
063: g.draw3DRect(x, y, w, h, true);
064: adjust();
065: g.fill3DRect(x, y, w, h, true);
066: g.setColor(Builder.SUN_BLUE);
067: adjust();
068: g.drawRoundRect(x, y, w, h, 10, 10);
069: adjust();
070: g.fillRoundRect(x, y, w, h, 10, 10);
071: adjust();
072: g.clearRect(x, y, w, h);
073: // circles
074: x = 2 * d.width / 4;
075: y = 0;
076: w = d.width / 4 - i;
077: h = d.height - 1;
078: g.setColor(Builder.SUN_BLUE);
079: g.drawOval(x, y, w, h);
080: adjust();
081: g.fillOval(x, y, w, h);
082: g.setColor(Builder.SUN_YELLOW);
083: adjust();
084: g.drawArc(x, y, w, h, 135, 270);
085: adjust();
086: g.fillArc(x, y, w, h, 135, 270);
087: // polys
088: x = 3 * d.width / 4;
089: y = 0;
090: w = d.width / 12 - i;
091: h = d.height - 1;
092: g.setColor(Builder.SUN_BLUE);
093: g.drawPolygon(array(x, x + w, x, x + w), array(y, y + h / 4, y
094: + 3 * h / 4, y + h), 4);
095: x = 10 * d.width / 12;
096: g.fillPolygon(array(x, x + w, x, x + w), array(y, y + h / 4, y
097: + 3 * h / 4, y + h), 4);
098: x = 11 * d.width / 12;
099: g.drawPolyline(array(x, x + w, x, x + w), array(y, y + h / 4, y
100: + 3 * h / 4, y + h), 4);
101: }
102:
103: private void adjust() {
104: x += i;
105: y += i;
106: w -= 2 * i;
107: h -= 2 * i;
108: }
109:
110: private int[] array(int i1, int i2, int i3, int i4) {
111: int[] array = { i1, i2, i3, i4 };
112: return array;
113: }
114: }
|