publicvoid drawDemo(int w, int h, Graphics2D g2) {
GeneralPath p1 = new GeneralPath();
// draws the polygon on the left side
p1.moveTo( w * .25f, 0.0f);
p1.lineTo( w * .75f, h * .5f);
p1.lineTo( w * .25f, (float) h);
p1.lineTo( 0.0f, h * .5f);
p1.closePath();
GeneralPath p2 = new GeneralPath();
// draws the polygon on the right side
p2.moveTo( w * .75f, 0.0f);
p2.lineTo( (float) w, h * .5f);
p2.lineTo( w * .75f, (float) h);
p2.lineTo( w * .25f, h * .5f);
p2.closePath();
// creates an area object with the first path
Area area = new Area(p1);
g2.setColor(Color.yellow);
double sx = w/100; double sy = h/140;
g2.scale(sx, sy); double x = w/sx/2; double y = h/sy/2;
/* *createsthefirstleafbyfillingtheintersectionof *twoAreaobjectscreatedfromanellipse.
*/
Ellipse2D leaf = new Ellipse2D.Double(x-16, y-29, 15.0, 15.0);
Area leaf1 = new Area(leaf);
leaf.setFrame(x-14, y-47, 30.0, 30.0);
Area leaf2 = new Area(leaf);
leaf1.intersect(leaf2);
g2.setColor(Color.green);
g2.fill(leaf1);
// creates the second leaf.
leaf.setFrame(x+1, y-29, 15.0, 15.0);
leaf1 = new Area(leaf);
leaf2.intersect(leaf1);
g2.fill(leaf2);
/* *createsthestembyfillingtheArearesultingfromthe *subtractionoftwoAreaobjectscreatedfroman *ellipse.
*/
Ellipse2D stem = new Ellipse2D.Double(x, y-42, 40.0, 40.0);
Area st1 = new Area(stem);
stem.setFrame(x+3, y-47, 50.0, 50.0);
st1.subtract(new Area(stem));
g2.setColor(Color.black);
g2.fill(st1);
/* *createsthepearitselfbyfillingtheArearesulting *fromtheunionoftwoAreaobjectscreatedbytwo *differentellipses.
*/
Ellipse2D circle = new Ellipse2D.Double(x-25, y, 50.0, 50.0);
Ellipse2D oval = new Ellipse2D.Double(x-19, y-20, 40.0, 70.0);
Area circ = new Area(circle);
circ.add(new Area(oval));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.