Example usage for java.awt Point Point

List of usage examples for java.awt Point Point

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Document

Constructs and initializes a point at the specified (x,y) location in the coordinate space.

Usage

From source file:Main.java

/**
 * Returns component location relative to another component.
 *
 * @param component  component to process
 * @param relativeTo component relative to which location will be returned
 * @return component location relative to another component
 *///from ww w  .  ja  va 2 s . c o m
public static Point getRelativeLocation(final Component component, final Component relativeTo) {
    final Point los = component.getLocationOnScreen();
    final Point rt = relativeTo.getLocationOnScreen();
    return new Point(los.x - rt.x, los.y - rt.y);
}

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  ww . j ava2s.  c  om*/

}

From source file:Main.java

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

    Rectangle r = new Rectangle();

    r.setLocation(new Point(20, 20));
    r.setSize(new Dimension(10, 10));

    g2.fill(r);//  ww w. j a va  2s . c  o  m
    System.out.println(r.height);

}

From source file:Main.java

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

    Rectangle r = new Rectangle();

    r.setLocation(new Point(20, 20));
    r.setSize(new Dimension(10, 10));

    g2.fill(r);/*from   ww  w . ja  v a 2s  .  c o  m*/
    System.out.println(r.isEmpty());

}

From source file:Main.java

static public void overlapComponents(Component top, Component bottom, int offset,
        boolean preserveZeroLocation) {
    ////from w ww  .ja  v  a2 s  .  c  om
    // If top's location is (0,0), then adjust the location so that
    // the first appearance will be on the top of the parent frame.
    //
    Point location = top.getLocation();

    //
    // if preserveZeroLocation is true, it means that location(0,0) is
    // a valid location. [V1.75]
    //
    if (location.x == 0 && location.y == 0 && !preserveZeroLocation) {
        //
        // With Windows 95, if the main frame is iconified, its location()
        // might be out of screen. Therefore, if the its location is out
        // of screen, then position the top component into the center 
        // of the screen.
        //
        location = bottom.getLocation();

        if ((location.x > SCREEN_SIZE.width) || (location.y > SCREEN_SIZE.height))
            centerComponent(top, new Point(0, 0), SCREEN_SIZE);
        else {
            location.x += offset;
            location.y += offset;
            fitComponentIntoScreen(top, location);
        }
    } else
        fitComponentIntoScreen(top, location);
}

From source file:Main.java

/**
 * Centers a Window on the screen<p>
 * Sets the window on the top left corner if the window's
 * dimensions are bigger than the screen's.
 *
 * @param window a Window object/*w  w w .  j a  v a 2  s.  co  m*/
 */
public static void centerOnScreen(Window window) {
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    double w = Math.min(window.getWidth(), screen.width);
    double h = Math.min(window.getHeight(), screen.height);
    int x = (int) (center.x - (w / 2));
    int y = (int) (center.y - (h / 2));

    Point corner = new Point((x >= 0 ? x : 0), (y >= 0 ? y : 0));

    window.setLocation(corner);
}

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);
    arc.setAngles(new Point(4, 5), new Point(6, 3));
    g2.draw(arc);//from ww w  . j av a2s  . c o  m

    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);
}

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);
    arc.setAngleStart(new Point(3, 4));
    g2.draw(arc);//from  w w w. j  a  v a  2 s.  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);
}

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);
    arc.setAngleStart(new Point(3, 4));
    g2.draw(arc);/*from   w  w  w  . j av  a2 s  . c o m*/

    Arc2D arc1 = new Arc2D.Float(0.0f, 0.0f, w, h, 80.0f, 110.0f, Arc2D.PIE);
    arc.setArc(arc1);
    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 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 ww  . j av  a 2 s  .  co  m*/

    arc.setArcByTangent(new Point(2, 3), new Point(3, 4), new Point(3, 4), Arc2D.PIE);
    g2.fill(arc);

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

    g2.draw(arc);
}