Introduction to the Figure Package - Sample using the Template class.
Sample Code using the Template class
Here is some sample code, using the Template class that produces a PostScript file named
templateRose.ps when run as an application and that yields a screen image when run as an applet.
/* File: templateRose.java */
import figPac.* ;
import java.applet.* ;
import java.awt.* ;
public class templateRose extends Template {
static {templateClass = new templateRose() ; }
public void setup() {
filePrefix = "templateRose" ;
outputLblFile = false ;
xsize = 4 ; // in inches
ysize = 4 ; // in inches
xmin = -300 ;
xmax = 300 ;
ymin = -300 ;
ymax = 300 ;
showCanvasBoundary = false ;
}
public void prepareFigure(Figure canvas) {
fAxes("x axis","y axis") ;
fSubFigure subfig= new fSubFigure() ;
subfig.append(new fCurve(new rose(200,3),
0,Math.PI,
CLOSED+FILLED)) ;
fEnv("fillColor", Color.yellow) ;
canvas.append(subfig) ;
fLabel(100,50,"cc","Petal") ;
}
}
To compile this program you would
save it to a file named templateRose.java and then use
javac templateRose.java
To create and then print a PostScript file you would execute
java templateRose
lpr templateRose.ps
To get a screen image you would instead create a file called templateRose.html
containing
<HEAD><TITLE>Figure Test Program</TITLE></HEAD>
<BODY>
<H1>Figure Test Program </H1>
<P>
<APPLET code="templateRose.class" width=600 height=500></APPLET>
</BODY>
and then execute
appletviewer templateRose.html &