Java examples for 2D Graphics:Shape
Drawing Simple Shapes
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g; g2d.drawLine(x1, y1, x2, y2); g2d.drawOval(x, y, w, h); g2d.drawRect(x, y, w, h); // A start angle of 0 represents a 3 o'clock position, // 90 represents a 12 o'clock position, // and -90 (or 270) represents a 6 o'clock position int startAngle = 45; int arcAngle = -60; g2d.drawArc(x, y, w, h, startAngle, arcAngle); g2d.drawRoundRect(x, y, w, h, arcWidth, arcHeight); Polygon polygon = new Polygon(); polygon.addPoint(x, y); // Add more points... g2d.drawPolygon(polygon); }