Java examples for 2D Graphics:Text
draw Boundary
//package com.java2s; import java.awt.*; import java.awt.geom.*; public class Main { public static void drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts) { Color smokey = new Color(128, 128, 128, 128); drawBoundary(g2d, bounds, pts, smokey, true); }// w ww . j a v a 2 s. co m public static void drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts, Color color, boolean drawSqPt) { g2d.setPaint(Color.BLACK); BasicStroke basicStroke = new BasicStroke(0.25f); Stroke origStroke = g2d.getStroke(); g2d.setStroke(basicStroke); g2d.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON); g2d.draw(bounds); basicStroke = new BasicStroke(1.0f); g2d.setStroke(basicStroke); for (int i = 0; i < pts.length; i++) { if (drawSqPt) drawSquarePoint(g2d, pts[i], 1, color); else drawPoint(g2d, pts[i], 1, color); } g2d.setStroke(origStroke); } public static void drawSquarePoint(Graphics2D g2, Point2D.Double pt, int ptSize, Color color) { Color origColor = g2.getColor(); g2.setColor(color); Rectangle2D.Double ptRect = new Rectangle2D.Double(pt.x - 4 * ptSize, pt.y - 4 * ptSize, 8 * ptSize, 8 * ptSize); g2.fill(ptRect); g2.draw(ptRect); g2.setColor(origColor); } public static void drawPoint(Graphics2D g2, Point2D.Double pt, int ptSize, Color color) { AffineTransform affine = new AffineTransform(); affine.setToIdentity(); drawPoint(affine, g2, pt, ptSize, color); } public static void drawPoint(AffineTransform affine, Graphics2D g2, Point2D.Double point, int ptSize, Color color) { Point2D.Double pt = (Point2D.Double) affine.transform(point, null); Color origColor = g2.getColor(); g2.setColor(color); g2.fill(new Ellipse2D.Double(pt.x - 4 * ptSize, pt.y - 4 * ptSize, 8 * ptSize, 8 * ptSize)); g2.setColor(origColor); } }