Introduction to the Figure Package - Sample Code Yielding a PostScript File and a Screen Image.

Sample Code Yielding a PostScript File and a Screen Image

Here is some sample code that produces a PostScript file named curveTest.ps when run as an application and that yields a screen image when run as an applet.
                  /*  File:  curveTest.java    */

import java.applet.* ;
import java.awt.* ;
import figPac.* ;

 

public class  curveTest extends Applet {

   static void prepareFigure(Figure canvas) {
      canvas.limits(-4,-5,4,5) ;
      canvas.append(new fAxes("x axis","y axis", true) ) ;   
      canvas.append(new fCurve(new step(.5,1,3)) ) ;
   }

   public void init() {          
      Figure canvas = new Figure(this,6,6) ;
      this.add(canvas) ;
      prepareFigure(canvas) ;
      canvas.toScreen() ;
   }

   public static void main(String argv[]) {
      Figure canvas = new Figure(6,6) ;
      prepareFigure(canvas) ;
      canvas.toPsFile("curveTest.ps") ;
      System.exit(0) ;
      }    
}


class step implements S2S {

   double location = 0 ;
   double left_height = 0 ;
   double right_height = 1 ;

   public step() {
   }

   public step(double location, double left_height, double right_height) {
      this.location = location;
      this.left_height = left_height ;
      this.right_height = right_height ;
   }

     public double map(double t) {
      if ( t>location) return right_height ;
      else return left_height ;
   }
}

To compile this program you would save it to a file named curveTest.java and then use
     javac curveTest.java
To create and then print a PostScript file you would execute
     java curveTest
     lpr curveTest.ps
To get a screen image you would instead create a file called curveTest.html containing
<HEAD><TITLE>Figure Test Program</TITLE></HEAD>
<BODY>
<H1>Figure Test Program </H1>

<P>
<APPLET code="curveTest.class" width=600 height=600></APPLET>

</BODY>
and then execute
     appletviewer curveTest.html &