import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class PathsFill extends Canvas { public PathsFill() { setBackground(Color.cyan); } public void paint(Graphics g) { int n = 0; Dimension theSize = getSize(); Graphics2D g2; g2 = (Graphics2D) g; /* g2.setRenderingHints(Graphics2D.ANTIALIASING, Graphics2D.ANTIALIAS_ON); */ GeneralPath p = new GeneralPath(1); p.moveTo( theSize.width/6, theSize.height/6); p.lineTo(theSize.width*5/6, theSize.height/6); p.lineTo(theSize.width*5/6, theSize.height*5/6); p.lineTo( theSize.width/6, theSize.height*5/6); p.closePath(); g2.setColor(Color.blue); g2.draw(p); AffineTransform at = new AffineTransform(); at.scale(.5, .5); at.translate(theSize.width/2, theSize.height/2); g2.setTransform(at); g2.setColor(Color.red); g2.fill(p); Color colorArray[] = new Color[10]; colorArray[0] = Color.blue; colorArray[1] = Color.green; colorArray[2] = Color.magenta; colorArray[3] = Color.lightGray; colorArray[4] = Color.pink; colorArray[5] = Color.white; colorArray[6] = Color.yellow; colorArray[7] = Color.black; colorArray[8] = Color.gray; colorArray[9] = Color.orange; for(n = 0; n < 10; n++) { at.scale(.9, .9); at.rotate(15, theSize.width/2, theSize.height/2); g2.setTransform(at); g2.setColor(colorArray[n]); g2.fill(p); } } public static void main(String s[]) { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } public void windowClosed(WindowEvent e) { System.exit(0); } }; Frame f = new Frame("Simple 2D Demo ..."); f.addWindowListener(l); f.add("Center", new PathsFill()); f.pack(); f.setSize(new Dimension(400,400)); f.show(); } }