package figure;

import java.awt.*;
import javax.swing.*;

public class FunctionFigure implements Function {
    public double valueAt(double x, double[] params) {
	return x*x*x + params[0]*x;
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("FunctionFigure");
	frame.setDefaultOperation(JFrame.DISPOSE_ON_CLOSE);
        FigurePanel panel = new FigurePanel(-2, -3, 2, 3);
        frame.getContentPane().add(panel, BorderLayout.CENTER);
        panel.setPreferredSize(new Dimension(300, 300));

	Color[] colors = { new Color(0.3f, 0.3f, 1f),
			   new Color(1f, 0.3f, 0.3f),
			   new Color(0.3f, 1f, 0.3f) };

        Grid grid = new Grid();
        grid.setColor(Color.lightGray);
        panel.add(grid);
        
        Axes axes = new Axes();
        panel.add(axes);

	FunctionFigure function = new FunctionFigure();
	for (int i = 0;  i < 3; i++) {
	    GraphicalFunction f1 = 
		new GraphicalFunction(function, new double[] {i-1});
	    f1.setColor(colors[i]);
	    panel.add(f1);
	}        
        frame.pack();
        frame.setVisible(true);
    }

}
