Example usage for java.awt Rectangle contains

List of usage examples for java.awt Rectangle contains

Introduction

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

Prototype

public boolean contains(int X, int Y, int W, int H) 

Source Link

Document

Checks whether this Rectangle entirely contains the Rectangle at the specified location (X,Y) with the specified dimensions (W,H) .

Usage

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(40, 40, 10, 10));

    g2.fill(r);/*from  w w w .j  av a2s.c  o m*/

}

From source file:net.java.sip.communicator.gui.AuthenticationSplash.java

/**
 * Centers the window on the screen./*w  ww  .  j  a  v  a 2 s .co m*/
 */
private void centerWindow() {
    Rectangle screen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    Point center = new Point((int) screen.getCenterX(), (int) screen.getCenterY());
    Point newLocation = new Point(center.x - this.getWidth() / 2, center.y - this.getHeight() / 2);
    if (screen.contains(newLocation.x, newLocation.y, this.getWidth(), this.getHeight())) {
        this.setLocation(newLocation);
    }
}