public class RelativePoint extends Point
Extension of java.awt.Point class allowing to specify the coordinates as percentages instead of absolute numbers. This supports handling of requests like "click at the point which is at 50% of the screen width and 20% of screen height.
The class can be used as a standard Point instance with absolute coordinates x ,y
passed through the constructor or superclass methods. To create a relative point
set at least one of the percentages to a non-negative value and invoke the
updateCoordinates()
method. It recalculates the real x, y coordinates
with regard to the screen resolution.
A typical usage is:
RelativePoint p = new RelativePoint(0, 300); p.setXPercentage(10f); ... // The following method changes p.x to 64 (10 * 640/100). // The p.y coordinate will remain 300 because it has no percentage defined. p.updateCoordinates(new Dimension(640, 480));
Point2D.Double, Point2D.Float
Constructor and Description |
---|
RelativePoint()
Default constructor.
|
RelativePoint(int x,
int y)
Constructor.It creates a standard Point instance with coordinates
initialized to [x,y].
|
RelativePoint(Point p)
Default constructor.It creates a standard Point instance with coordinates
initialized to those of the argument point.
|
Modifier and Type | Method and Description |
---|---|
float |
getXPercentage()
Get value of the x coordinate percentage.
|
float |
getYPercentage()
Get value of the y coordinate percentage.
|
boolean |
isXRelative() |
boolean |
isYRelative() |
void |
setXPercentage(float xPercentage) |
void |
setYPercentage(float yPercentage) |
void |
updateCoordinates(Dimension resolution)
Update relative coordinates with regard to the screen resolution.
|
equals, getLocation, getX, getY, move, setLocation, setLocation, setLocation, toString, translate
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, hashCode, setLocation
public RelativePoint()
public RelativePoint(Point p)
p
- a point.public RelativePoint(int x, int y)
x
- the X coordinate.y
- the Y coordinate.public void updateCoordinates(Dimension resolution)
resolution
- screen resolution.public float getXPercentage()
public boolean isXRelative()
public void setXPercentage(float xPercentage)
xPercentage
- the xPercentage to setpublic float getYPercentage()
public boolean isYRelative()
public void setYPercentage(float yPercentage)
yPercentage
- the yPercentage to set