Questo esercizio disegna il grafico di funzioni reali a variabile reale. Viene utilizzato il package van.math.functionPlotter che mette a disposizione un'estensione della Canvas che permette di plottare funzioni matematiche definite da una oggetto che definisce una funzione, come ad esempio il seno.
package corsoDrZito.lez2.es4;
import van.math.functionPlotter.*;
import van.math.function.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.Enumeration;
public class esercizio4 extends java.applet.Applet
{
public esercizio4(Container c)
{
Sine sin = new Sine();
Step step = new Step();
Unity unity = new Unity();
Ramp ramp = new Ramp();
Floor floor = new Floor();
Ceil ceil = new Ceil();
Color[] colors = { new Color(230,180,160), new Color(180,220,120), new Color(240,190,140), new Color(180,220,240), new Color(240,220,210), new Color(210, 230, 250) };
Vector canvases = new Vector();
canvases.addElement( new FunctionReal2RealPlotter(unity) );
canvases.addElement( new FunctionReal2RealPlotter(ramp) );
canvases.addElement( new FunctionReal2RealPlotter(step) );
canvases.addElement( new FunctionReal2RealPlotter(sin) );
canvases.addElement( new FunctionReal2RealPlotter(floor) );
canvases.addElement( new FunctionReal2RealPlotter(ceil) );
for (int i=0; i<canvases.size(); i++)
((FunctionReal2RealPlotter)canvases.elementAt(i)).setBackground(colors[i]);
c.setLayout(new GridLayout(3,2,6,6));
Enumeration e = canvases.elements();
while( e.hasMoreElements() )
c.add( (FunctionReal2RealPlotter) e.nextElement() );
}
public void init()
{
new esercizio4(this);
setBackground( new Color(128,148,192) );
}
public static void main(String[] args)
{
Frame f = new Frame("Function Plotter");
new FunctionPlotterTest1(f);
f.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e){
e.getWindow().dispose();
System.exit(0);
}
});
f.setBackground(new Color(128,148,192));
f.pack();
f.setSize(400, 300);
f.show();
}
}