Java Reference
In-Depth Information
Program: Grapher
Grapher
is a simple program that reads a table of numbers and graphs them. The input
format is two or more lines that each contain an X and a Y value. The output is an onscreen
display that can also be printed.
Figure 12-7
shows the results of running it with the follow-
ing simple data; the first column is the X coordinate and the second is the Y coordinate of
each point. The program scales the data to fit the window:
1.5 5
1.7 6
1.8 8
2.2 7
Figure 12-7. Grapher in action
Example 12-13
shows the code.
Example 12-13. Grapher.java
public
public class
class
Grapher
Grapher
extends
extends
JPanel
{
private
private static
static final
final
long
long
serialVersionUID
= -
1813143391310613248L
;
/** Multiplier for range to allow room for a border */
public
public final
final static
static
double
double
BORDERFACTOR
=
1.1f
;
/** The list of Point points. */
protected
protected
List
<
Point2D
>
data
;
/** The minimum and maximum X values */
protected
protected
double
double
minx
=
Integer
.
MAX_VALUE
,
maxx
=
Integer
.
MIN_VALUE
;