S O U R C E C O D E
/ 1999 / 10
/ java
/ 2.lst
// The Plotter Applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Plotter extends Applet {
boolean isStandalone = false;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Plotter() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private PlotEngine engine;
private void jbInit() throws Exception {
String engname;
engname=getParameter("engine","PlotEngineImpl");
Class c=Class.forName(engname);
engine=(PlotEngine)c.newInstance();
}
//Get Applet information
public String getAppletInfo() {
return "JPlot demo by Al Williams";
}
public void paint(Graphics g) {
int x,y;
float x0,xscale,yscale;
xscale=Float.valueOf(getParameter("XScale","1.0")).floatValue();
yscale=Float.valueOf(getParameter("YScale","1.0")).floatValue();
x0=Float.valueOf(getParameter("XOff","0.0")).floatValue();
Dimension d;
d=this.getSize();
if (engine==null) return;
for (x=0;x<d.width;x++) {
y=d.height-(int)(yscale*engine.f((x+x0)*xscale));
g.fillRect(x,y,1,1);
}
}
}
|
home
|
current issue
|
archives
|
source code
|
demo express
|
events
|
search
|
editorial calendar
|
advertising
|
customer service
|
author guidelines
|
jobs
|
about
Entire contents copyright 1996-2000 CMP Media Inc.
Read our privacy policy.