Example usage for java.awt Graphics drawRect

List of usage examples for java.awt Graphics drawRect

Introduction

In this page you can find the example usage for java.awt Graphics drawRect.

Prototype

public void drawRect(int x, int y, int width, int height) 

Source Link

Document

Draws the outline of the specified rectangle.

Usage

From source file:SplashScreenDemo.java

public static void main(String[] args) {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();
    Dimension size = splashScreen.getSize();
    int borderDim = (int) (size.height * 0.05);
    Graphics g = splashScreen.createGraphics();
    g.setColor(Color.blue);//from   w w w .java  2  s. c o m
    for (int i = 0; i < borderDim; i++)
        g.drawRect(i, i, size.width - 1 - i * 2, size.height - 1 - i * 2);

    FontMetrics fm = g.getFontMetrics();
    int sWidth = fm.stringWidth("Initializing...");
    int sHeight = fm.getHeight();
    if (sWidth < size.width && 2 * sHeight < size.height) {
        g.setColor(Color.blue);
        g.drawString("Initializing...", (size.width - sWidth) / 2, size.height - 2 * sHeight);
    }

    splashScreen.update();

    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
}

From source file:Main.java

public static void drawBorder(Graphics g, Color c, int x, int y, int w, int h) {
    g.setColor(c);//from  www .  jav  a 2 s  . c o  m
    g.drawRect(x, y, w - 1, h - 1);
}

From source file:MainClass.java

static void printDimensions(Graphics g, Dimension size) {
    int width = size.width;
    int height = size.height;
    int x1 = (int) (width * 0.1);
    int x2 = (int) (width * 0.9);
    int y1 = (int) (height * 0.1);
    int y2 = (int) (height * 0.9);
    g.drawRect(x1, y1, x2 - x1, y2 - y1);
    g.dispose();/*  w w  w  .  j a  va2 s.c o  m*/
}

From source file:Main.java

public static void drawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight) {
    Color oldColor = g.getColor(); // Make no net change to g
    g.translate(x, y);//from  w  ww.  j a  v a 2  s . c om

    g.setColor(shadow);
    g.drawRect(0, 0, w - 2, h - 2);

    g.setColor(highlight);
    g.drawLine(1, h - 3, 1, 1);
    g.drawLine(1, 1, w - 3, 1);

    g.drawLine(0, h - 1, w - 1, h - 1);
    g.drawLine(w - 1, h - 1, w - 1, 0);

    g.translate(-x, -y);
    g.setColor(oldColor);
}

From source file:org.kalypso.ogc.gml.map.widgets.builders.PolygonGeometryBuilder.java

public static void drawHandle(final Graphics g, final int x, final int y) {
    final int sizeOuter = 6;
    g.drawRect(x - sizeOuter / 2, y - sizeOuter / 2, sizeOuter, sizeOuter);
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.util.UtilMap.java

public static void drawHandles(final Graphics g, final int[] x, final int[] y) {
    final int sizeOuter = 6;
    for (int i = 0; i < y.length; i++)
        g.drawRect(x[i] - sizeOuter / 2, y[i] - sizeOuter / 2, sizeOuter, sizeOuter);
}

From source file:PaintUtils.java

/** Uses translucent shades of white and black to draw highlights
 * and shadows around a rectangle, and then frames the rectangle
 * with a shade of gray (120)./*w ww  .  j  ava2 s  .co  m*/
 * <P>This should be called to add a finishing touch on top of
 * existing graphics.
 * @param g the graphics to paint to.
 * @param r the rectangle to paint.
 */
public static void drawBevel(Graphics g, Rectangle r) {
    drawColors(blacks, g, r.x, r.y + r.height, r.x + r.width, r.y + r.height, SwingConstants.SOUTH);
    drawColors(blacks, g, r.x + r.width, r.y, r.x + r.width, r.y + r.height, SwingConstants.EAST);

    drawColors(whites, g, r.x, r.y, r.x + r.width, r.y, SwingConstants.NORTH);
    drawColors(whites, g, r.x, r.y, r.x, r.y + r.height, SwingConstants.WEST);

    g.setColor(new Color(120, 120, 120));
    g.drawRect(r.x, r.y, r.width, r.height);
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.grid.LinePointCollector.java

private static final void drawHandles(final Graphics g, final int[] x, final int[] y, final int pointRectWidth,
        final int selection) {
    final Color oldColor = g.getColor();
    g.setColor(oldColor.darker());//ww  w  .  jav a2  s .  c om
    // int sizeOuter = 4;
    final int halfRectWidth = pointRectWidth / 2;

    if (selection < 0) {
        for (int i = 0; i < y.length; i++) {
            g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth);
        }
    } else {
        int i;
        for (i = 0; i < selection; i++) {
            g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth);
        }
        // is is now selection
        g.drawOval(x[i] - pointRectWidth, y[i] - pointRectWidth, pointRectWidth + pointRectWidth,
                pointRectWidth + pointRectWidth);
        i++;
        for (; i < y.length; i++) {
            g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth);
        }
    }
    g.setColor(oldColor);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.drawRect(5, 15, 50, 75);
}

From source file:MyCanvas.java

public void paint(Graphics g) {
    g.drawRect(10, 10, 200, 200);
}