O'Reilly logo

Java 2D Graphics by Jonathan Knudsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.4. Rectangles

3.4.1. RectangularShape

As Figure 3.3 shows, java.awt.geom.RectangularShape is an important class. It's the abstract parent class of the rectangle, rounded rectangle, arc, and ellipse classes in java.awt.geom. It implements the methods of Shape and adds a few of its own.

First, a RectangularShape returns information about its location and size:

public abstract double getX()

This method returns the horizontal location of the left side of the rectangle.

public abstract double getY()

This method returns the vertical location of the top side of the rectangle.

public abstract double getWidth()

This method returns the width of the rectangle.

public abstract double getHeight()

This method returns the height of the rectangle.

public double getMinX()

This method returns the smallest x coordinate of the rectangle.

public double getMaxX()

This method returns the largest x coordinate of the rectangle.

public double getMinY()

This method returns the smallest y coordinate of the rectangle.

public double getMaxY()

This method returns the largest y coordinate of the rectangle.

Two methods are provided to examine the center point of the rectangle:

public double getCenterX()

public double getCenterY()

A rectangular shape is empty if its width and height are 0. The isEmpty() method returns true in this case:

public abstract boolean isEmpty()

Finally, RectangularShape includes three methods for setting the bounds of the shape:

public abstract void setFrame(double x, double ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required