Java Reference
In-Depth Information
I'll present a high-level class that abstracts the key characteristics of a series of such plotters
made by different vendors. It would be used, for example, in an analytical or data-explora-
tion program to draw colorful charts showing the relationships found in data. But I don't
want my main program to worry about the gory details of any particular brand of plotter, so
I'll abstract into a
Plotter
class, whose source is as follows:
plotter/Plotter.java
/**
* Plotter abstract class. Must be subclassed
* for X, DOS, Penman, HP plotter, etc.
*
* Coordinate space: X = 0 at left, increases to right.
* Y = 0 at top, increases downward (same as AWT).
*
* @author Ian F. Darwin
*/
public
public abstract
abstract class
class
Plotter
Plotter
{
public
public final
final
int
int
MAXX
=
800
;
public
public final
int
MAXY
=
600
;
/** Current X co-ordinate (same reference frame as AWT!) */
protected
final
int
protected
int
int
curx
;
/** Current Y co-ordinate (same reference frame as AWT!) */
protected
protected
int
int
cury
;
/** The current state: up or down */
protected
protected
boolean
boolean
penIsUp
;
/** The current color */
protected
protected
int
int
penColor
;
Plotter
() {
penIsUp
=
true
true
;
curx
=
0
;
cury
=
0
;
}
abstract
abstract
void
void
rmoveTo
(
int
int
incrx
,
int
int
incry
);
abstract
abstract
void
void
moveTo
(
int
int
absx
,
int
int
absy
);
abstract
abstract
void
void
penUp
();
abstract
abstract
void
void
penDown
();
abstract
abstract
void
void
penColor
(
int
int
c
);
abstract
abstract
void
void
setFont
(
String fName
,
int
int
fSize
);
abstract
abstract
void
void
drawString
(
String s
);
/* Concrete methods */