Java Utililty Methods Graphics Draw

List of utility methods to do Graphics Draw

Description

The list of methods to do Graphics Draw are organized into topic(s).

Method

voiddrawSpline(Graphics graphics, int x1, int y1, int x2, int y2, int x3, int y3)
draw Spline
int xa, ya, xb, yb, xc, yc, xp, yp;
xa = (x1 + x2) / 2;
ya = (y1 + y2) / 2;
xc = (x2 + x3) / 2;
yc = (y2 + y3) / 2;
xb = (xa + xc) / 2;
yb = (ya + yc) / 2;
xp = (x1 + xb) / 2;
...
voiddrawSquarePoint(Graphics2D g2, Point2D.Double pt, int ptSize, Color color)
draw Square Point
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);
voiddrawStackTrace(Graphics gr, int x, int y, Throwable ex)
draw Stack Trace
final int linePadding = 4;
int lineHeight = gr.getFont().getSize() + linePadding;
int currY = y;
Enumeration lines = new StringTokenizer(getStackTrace(ex), "\n", false);
while (lines.hasMoreElements()) {
    gr.drawString(((String) lines.nextElement()).trim(), x, currY);
    currY += lineHeight;
voiddrawStage(Graphics g, int x, int y)
Draw stage with sample
int dy = 6;
int[] xPoints = new int[] { x - 20, x + 20, x + 25, x - 25 };
int[] yPoints = new int[] { y - dy, y - dy, y + dy, y + dy };
g.setColor(Color.GRAY);
g.fillPolygon(xPoints, yPoints, 4);
g.setColor(Color.BLACK);
g.drawPolygon(xPoints, yPoints, 4);
voiddrawStar(Graphics g, int x, int y)
draw Star
g.drawLine(x, y - 3, x, y - 2);
g.drawLine(x - 1, y - 1, x + 1, y - 1);
g.drawLine(x - 3, y, x + 3, y);
g.drawLine(x - 2, y + 1, x + 2, y + 1);
g.drawLine(x - 1, y + 2, x + 1, y + 2);
g.drawLine(x - 2, y + 3, x - 2, y + 3);
g.drawLine(x + 2, y + 3, x + 2, y + 3);
voiddrawTankISPip(Graphics2D g2d, int width, int height)
draw Tank IS Pip
Dimension circle = new Dimension(7, 7);
Dimension fillCircle = new Dimension(5, 5);
g2d.setColor(Color.black);
g2d.fillOval(width, height, circle.width, circle.height);
g2d.setColor(Color.white);
g2d.fillOval(width + 1, height + 1, fillCircle.width, fillCircle.height);
voiddrawTransparent(Graphics g, int x, int y, int width, int height)
draw Transparent
Shape clip = g.getClip();
g.clipRect(x, y, width, height);
int size = 8;
for (int xx = 0; xx <= width / size; xx++)
    for (int yy = 0; yy <= height / size; yy++) {
        if ((xx + yy) % 2 == 0)
            g.setColor(Color.LIGHT_GRAY);
        else
...
voiddrawUp(Graphics g, int x, int y, int w, int h)
draw Up
g.setColor(SHADOW_UP);
g.drawLine(x, y, x + w - 1, y);
g.drawLine(x, y, x, y + h - 2);
g.setColor(SHADOW_DOWN);
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
voiddrawWeightBox(Graphics2D g2d, int ycentre, int xcentre, int width)
draw Weight Box
assert (width % 2 == 1);
g2d.fillRect(xcentre - width / 2, ycentre - width / 2, width, width);
voiddrawWinUpperLeft(Graphics g, int which, Color fill, int x, int y, int fmWidth, int fmHeight)
draw Win Upper Left
Color oldColor = g.getColor(); 
g.setColor(fill);
if (which == WINDOW_GRAPHIC) {
    g.fillRect(x, y, fmWidth, fmHeight);
    g.setColor(Color.white);
    g.drawLine(x, y, x + fmWidth, y);
    g.drawLine(x, y, x, y + fmHeight);
if (which == WINDOW_NORMAL) {
    g.drawLine(x + fmWidth / 2, y + fmHeight / 2, x + fmWidth, y + fmHeight / 2);
    g.drawLine(x + fmWidth / 2, y + fmHeight / 2, x + fmWidth / 2, y + fmHeight);
g.setColor(oldColor);