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;
    int w = getSize().width;
    int h = getSize().height;

    Arc2D arc = new Arc2D.Double(0.0, 0.5, w, h, 0.0, 60.0, Arc2D.CHORD);

    g2.draw(arc);//from   w w w.  j a  v a2  s.c  o  m

    arc.setArc(new Rectangle(2, 3, 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);
}

From source file:Main.java

public static void centerAndSizeWindow(Window win, int fraction, int base) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = screenSize.width * fraction / base;
    int height = screenSize.height * fraction / base;

    Rectangle rect = new Rectangle((screenSize.width - width) / 2, (screenSize.height - height) / 2, width,
            height);//from   ww  w  . j a v a 2 s. c o m
    win.setBounds(rect);
}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    gp1.createContext(ColorModel.getRGBdefault(), new Rectangle(0, 0, 30, 40), new Rectangle(0, 0, 30, 40),
            new AffineTransform(), null);

    System.out.println(gp1.getTransparency());
    g2d.setPaint(gp1);//from   w  w w .  j a v  a2  s.  co m
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Main.java

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

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area(e1);
    Area a2 = new Area(e2);

    a1.intersects(new Rectangle(20, 20, 300, 300));

    g2.setColor(Color.orange);//  w w  w . jav a 2 s  .co m
    g2.fill(a1);

    g2.setColor(Color.black);
    g2.drawString("intersect", 20, 140);
}

From source file:BasicStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(3.0f));
    g2.setPaint(Color.blue);// w w  w . j av a2  s .c o  m

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

    g2.draw(r);
}

From source file:ThickStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(8.0f));
    g2.setPaint(Color.blue);/* ww w  .java  2s  . co  m*/

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

    g2.draw(r);
}

From source file:TransformDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Rectangle rect = new Rectangle(5, 5, 200, 200);

    int w = getSize().width;
    int h = getSize().height;

    AffineTransform saveXform = g2.getTransform();
    AffineTransform toCenterAt = new AffineTransform();
    toCenterAt.translate(w / 2 - (rect.width / 2), h / 2 - (rect.height / 2));
    g2.transform(toCenterAt);/*from w  ww  .jav a 2  s.c  o m*/

    g2.fill(rect);

    g2.transform(saveXform);
}

From source file:GradientPaintDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(new GradientPaint(0, 0, Color.lightGray, 200, 200, Color.blue, false));

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

    g2.fill(r);//from w  w  w. ja  va  2s.  c om
}

From source file:BasicDraw.java

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

    g2d.setColor(Color.red);/* w  ww  .j a v a2s . co  m*/

    g2d.fill(new Rectangle(20, 20, 200, 200));
    int red = 230;
    int green = 45;
    int blue = 67;
    g2d.setColor(new Color(red, green, blue));
    g2d.fill(new Rectangle(40, 40, 200, 200));
}

From source file:Main.java

/**
 * Retrieves the bounds represents the available space on the Window's display that is not used up by things like
 * the task bar or dock./*from  w w  w.  java2s .com*/
 *
 * @param window
 *         The window to center
 * @return Bounds of the display's available space
 */
public static Rectangle getBoundsOfAvailableDisplaySpace(Window window) {
    GraphicsConfiguration graphicsConfigToUse = window.getGraphicsConfiguration();
    // If the Window does not have a GraphicsConfiguration yet (perhaps when the Window is not set up yet) then use the default screen's GraphicsConfiguration.
    if (graphicsConfigToUse == null) {
        graphicsConfigToUse = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration();
    }
    Rectangle boundsOfEntireScreen = graphicsConfigToUse.getBounds();
    Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfigToUse);

    return new Rectangle(screenInsets.left, screenInsets.top,
            boundsOfEntireScreen.width - screenInsets.left - screenInsets.right,
            boundsOfEntireScreen.height - screenInsets.top - screenInsets.bottom);
}