Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

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

Prototype

public Rectangle(int x, int y, int width, int height) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(10, 10, 50, 40);

    r.intersects(new Rectangle(40, 40, 20, 20));

    g2.fill(r);/* w  ww .j a  v  a  2 s.c  o m*/

}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(10, 10, 50, 40);

    System.out.println(r.contains(new Rectangle(40, 40, 20, 20)));

    g2.fill(r);/*from   w w w. j  av  a2 s.c  om*/

}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(10, 10, 50, 40);

    r.add(new Rectangle(40, 40, 100, 100));

    g2.fill(r);/*from   w w w .  j a  v a 2  s .  c o  m*/

}

From source file:Main.java

/** Centers the given window on the screen. */
public static void centerWindow(final Window window) {
    final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
    centerWindow(new Rectangle(0, 0, s.width, s.height), window);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(10, 10, 50, 40);

    r.add(new Point(40, 40));

    g2.fill(r);/*from   w ww  . j av a 2 s . c  o m*/

}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(10, 10, 50, 40);

    System.out.println(r.contains(new Point(40, 40)));

    g2.fill(r);/*from  w w  w  .  java 2  s  .c om*/

}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(20, 20, 200, 200);

    g2.fill(r);/*w w w .ja v  a 2 s.  c o  m*/
    System.out.println(r.contains(40, 40));

}

From source file:GraphicsUtil.java

static public Rectangle getTextBounds(Graphics g, Font font, String text, int x, int y, int halign,
        int valign) {
    if (g == null)
        return new Rectangle(x, y, 0, 0);
    Font oldfont = g.getFont();/*from   w  w  w . j a v  a2  s  . co m*/
    if (font != null)
        g.setFont(font);
    Rectangle ret = getTextBounds(g, text, x, y, halign, valign);
    if (font != null)
        g.setFont(oldfont);
    return ret;
}

From source file:Main.java

/**
 * Returns component content size limited by component border.
 *
 * @param component/*from ww w .  j ava 2s  .c o  m*/
 *            component to process
 * @return component content size rectangle
 */
public static Rectangle contentSize(final Component component) {
    if (component instanceof JComponent) {
        final Insets i = ((JComponent) component).getInsets();
        return new Rectangle(i.left, i.top, component.getWidth() - i.left - i.right,
                component.getHeight() - i.top - i.bottom);
    } else {
        return size(component);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    Arc2D arc = new Arc2D.Double(0.0, 0.0, w, h, 0.0, 60.0, Arc2D.CHORD);
    System.out.println(arc.contains(new Rectangle(5, 6, 20, 20)));
    g2.draw(arc);/*www. jav a  2s.c om*/

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 80.0f, 110.0f, Arc2D.PIE);

    g2.fill(arc);

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 210.0f, 130.0f, Arc2D.OPEN);

    g2.draw(arc);
}