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:test.mandelbrot.SequentialMandelbrotApp.java

@Override
public synchronized void paint(Graphics g) {
    if (done) {/*  w  ww  .  ja va  2  s  .  com*/
        g.drawImage(offscreen, 0, 0, this);
        this.setTitle("Done");
    } else {
        g.drawImage(offscreen, 0, 0, this);
        g.setColor(Color.white);
        g.drawRect(WIDTH / 4, 10, WIDTH / 2, 5);
        g.fillRect(WIDTH / 4, 11, (progress * (WIDTH / 2)) / HEIGHT, 4);
    }
}

From source file:FlexBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    g.setColor(color);/*w  w w .j av a  2 s .c  om*/

    switch (type) {
    case TOP_LINE:
        g.drawLine(x, y, x + width - 1, y);
        break;

    case BOTTOM_LINE:
        g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
        break;

    case RECT:
        g.drawRect(x, y, width - 1, height - 1);
        break;
    }
}

From source file:WebCrawler.java

public void paint(Graphics g) {
    //Draw a Rectangle around the applet's display area.
    g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);

    panelMain.paint(g);//from   ww w. j av  a 2  s  . c om
    panelMain.paintComponents(g);
    // update(g);
    // panelMain.update(g);
}

From source file:AlphaTest.java

/**
 * Draws a rectangle into the display area for the plot.
 *//*from   w w w  .  j  a  v  a2 s . c  o m*/
protected void drawAreaRect(Graphics g, int x, int y, int width, int height) {
    g.drawRect(m_nInsetX + x, m_nInsetY + y, width, height);
}

From source file:contactangle.ImageControl.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (img != null)
        g.drawImage(img, 0, 0, this);
    else//  w w w  .j a va 2  s . c  o m
        g.drawString("NO IMAGE", 0, 15);

    g.setColor(Color.RED);

    if (x1 < x2 && y1 < y2)
        g.drawRect(x1, y1, x2 - x1, y2 - y1);
    else if (x1 >= x2 && y1 < y2)
        g.drawRect(x2, y1, x1 - x2, y2 - y1);
    else if (x1 < x2 && y1 >= y2)
        g.drawRect(x1, y2, x2 - x1, y1 - y2);
    else
        g.drawRect(x2, y2, x1 - x2, y1 - y2);

    if (valid && img != null) {

        if (x1 >= x2) {
            int temp = x1;
            x1 = x2;
            x2 = temp;
        }
        if (y1 >= y2) {
            int temp = y1;
            y1 = y2;
            y2 = temp;
        }

        choosenPoints = new ArrayList<Point>();
        for (int y = y1; y < y2; y++) {
            for (int x = x1; x < x2; x++) {
                int pixelData = img.getRGB(x, y);
                if (pixelData == -1)
                    choosenPoints.add(new Point(x, y));
            }
        }

        SimpleRegression reg = new SimpleRegression();
        for (Point p : choosenPoints) {
            reg.addData(p.x, p.y);
        }

        int firstX = choosenPoints.get(0).x;
        int firstY = choosenPoints.get(0).y;
        double slope = reg.getSlope();
        g.setColor(Color.GREEN);
        g.drawLine(firstX, firstY, firstX + (70), firstY + (int) (slope * (70)));
        g.drawLine(firstX, firstY, firstX - (70), firstY - (int) (slope * (70)));

        double contactDegrees = (Math.atan(reg.getSlope()) / (2 * Math.PI)) * 360.0;

        DecimalFormat d = new DecimalFormat("##.###");

        g.drawString("Contact Angle = ", 25, 25);
        g.drawString(d.format(contactDegrees) + " degrees", 25, 38);
    }

}

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

private 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:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFBoolColumnCellRenderer.java

public void paint(Graphics g) {
    if (g == null) {
        return;/*from   ww  w .j a v  a  2  s.  c om*/
    }
    Rectangle bounds = getBounds();
    g.setColor(getBackground());
    g.fill3DRect(0, 0, bounds.width, bounds.height, true);
    g.setColor(getForeground());
    int xoffbox = (bounds.width - 16) / 2;
    int yoffbox = (bounds.height - 16) / 2;
    g.drawRect(xoffbox, yoffbox, 16, 16);
    Boolean useval;
    if (value instanceof Boolean) {
        useval = (Boolean) value;
    } else if (value instanceof String) {
        String s = (String) value;
        if (s.equals("true")) {
            useval = new Boolean(true);
        } else if (s.equals("false")) {
            useval = new Boolean(false);
        } else {
            useval = null;
        }
    } else {
        useval = null;
    }
    String str;
    if (useval == null) {
        str = "?";
    } else if (useval.booleanValue()) {
        str = "X";
    } else {
        str = null;
    }
    if (str != null) {
        FontMetrics fm = g.getFontMetrics();
        Rectangle sb = fm.getStringBounds(str, g).getBounds();
        int ascent = fm.getAscent();
        int leading = fm.getLeading();
        int sxoff = xoffbox + ((16 - sb.width) / 2);
        int syoff = yoffbox + ((16 - (leading + ascent)) / 2) + leading + ascent;
        g.drawString(str, sxoff, syoff);
    }
}

From source file:MainClass.java

public void print(Graphics g) {
    Font oldFont = g.getFont();/*from  www .  j ava  2s .  co m*/
    if (type == TEXT) {
        g.setFont(font);
        g.drawString(text, x, y);
    } else if (type == GRAPHICS) {
        if (shape.equals("LINE")) {
            g.drawLine(x, y, width, height);
        } else if (shape.equals("OVAL")) {
            g.drawOval(x, y, width, height);
        } else if (shape.equals("RECTANGLE")) {
            g.drawRect(x, y, width, height);
        }
    }
    g.setFont(oldFont);
}

From source file:SaveYourDrawingToFile.java

public void paint(Graphics g) {
    g.setColor(Color.white);//  www . j av a2  s. co  m
    g.fillRect(0, 0, getSize().width, getSize().height);

    g.setColor(Color.black);
    int i = 0;
    while (i < displayList.size()) {
        Point p0 = (Point) (displayList.get(i++));
        Point p1 = (Point) (displayList.get(i++));
        int x = Math.min(p0.x, p1.x);
        int y = Math.min(p0.y, p1.y);
        int w = Math.abs(p0.x - p1.x);
        int h = Math.abs(p0.y - p1.y);
        g.drawRect(x, y, w, h);
    }
}

From source file:edu.ku.brc.af.ui.db.TextFieldWithInfo.java

@Override
public void paint(Graphics g) {
    super.paint(g);

    if (this.isInError && textField.isEnabled()) {
        Dimension dim = getSize();
        g.setColor(valtextcolor.getColor());
        g.drawRect(0, 0, dim.width - 1, dim.height - 1);
    }/*from www  .j av a2  s  .c o m*/
}