1 36 37 40 41 package java2d.demos.Paths; 42 43 import static java.awt.Color .*; 44 import java.awt.*; 45 import java.awt.font.TextLayout ; 46 import java.awt.geom.GeneralPath ; 47 import java2d.Surface; 48 49 50 53 public class FillStroke extends Surface { 54 55 56 public FillStroke() { 57 setBackground(WHITE); 58 } 59 60 61 public void render(int w, int h, Graphics2D g2) { 62 GeneralPath p = new GeneralPath (GeneralPath.WIND_EVEN_ODD); 63 p.moveTo( w*.5f, h*.15f); 64 p.lineTo( w*.8f, h*.75f); 65 p.lineTo( w*.2f, h*.75f); 66 g2.setColor(LIGHT_GRAY); 67 g2.fill(p); 68 g2.setColor(BLACK); 69 g2.setStroke(new BasicStroke(10)); 70 g2.draw(p); 71 TextLayout tl = new TextLayout ("Fill, Stroke w/o closePath", 72 g2.getFont(), g2.getFontRenderContext()); 73 tl.draw(g2, (float)(w/2-tl.getBounds().getWidth()/2), h*.85f); 74 } 75 76 77 public static void main(String s[]) { 78 createDemoFrame(new FillStroke()); 79 } 80 } 81 | Popular Tags |