Java Reference
In-Depth Information
remembered. If it is clicked a second time, a line between the mouse positions
of the two clicks is added to the drawing. The functions of the adapter can be
changed or extended by the programmer.
21.3
■
Helper classes
The helper classes provide data types that support the operations of our project.
At first we define two classes for points in the two-dimensional plane. One defines
points in coordinates that are real numbers. The other class defines points in pixel
coordinates. There are methods to convert real coordinates into pixel coordinates
based on the size of the drawing and the panel to display it.
21.3.1
Constants
We define a class
Constants
which contains the definition of some fixed values
that are used by one or more classes of the package. These include the width of
the margins around the drawing. The class also defines some boolean variables
which determine the appearance of the drawing, e.g. whether the anchor points
are drawn or whether the drawing is displayed in proportional model.
21.3.2
Real and pixel points
The classes
RealPoint
and
PixelPoint
each store fields
x
and
y
. These are the
x
- and
y
-coordinates of the point. The first class uses
double
and second one
int
.
The constructor of the pixel points checks that the coordinates are non-negative.
Both classes provide
get
-methods to access the fields.
File:
its/GenericDraw/PixelPoint.java
1.
package
its.GenericDraw;
2.
3.
public class
PixelPoint{
4.
private int
x, y;
5.
6.
public
PixelPoint(
int
xx,
int
yy){
7.
if
((xx >= 0) && (yy >= 0)){
8.
x=xx;
9.
y=yy;
}
10.
else
11.
{
12.
System.out.println("ERROR: Illegal pixel coordinates.");
13.
}
14.
}
15.
16.
Search WWH ::
Custom Search