import java.awt.*; import java.awt.event.*; import java.lang.*; import javax.swing.*; import GrapherGUI.*; public class Standalone { static public void main(String[] args) { SliderMatrix sm = new SliderMatrix(3); sm.add(-10.0, 10.0, 0.0, 4, "param_h.jpg", "h"); sm.add(5.0, 15.0, 5.0, 4, "param_g.jpg", "g"); GUI gui = new GUI(sm, -2.0, 2.0, -3.0, 10.0); MyFunction nf = new MyFunction(); MyOtherFunction of = new MyOtherFunction(); gui.addFunction(nf); gui.addFunction(of); gui.setAxesIcons("axis_x.jpg", "axis_y.jpg"); JPanel p = new JPanel(); p.add(gui); JFrame f = new JFrame("Grapher"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); f.setSize(510, 760); f.setLocation(300, 200); f.getContentPane().add(p); f.setVisible(true); f.show(); } } class MyFunction extends Function { public short type() { return Function.FCNTYPE_SINGLEVAL; } public String name() { return "Test"; } public double f(double x, SliderMatrix p) { double g, h; try { g = p.val("g"); h = p.val("h"); } catch (Error e) { return 0.0; } return x * x * x * h / g; } public void farray( double minx, double maxx, int density, double[] a, double[] b, SliderMatrix p) {} } class MyOtherFunction extends Function { public short type() { return Function.FCNTYPE_ARRAY; } public String name() { return "Using a whole array"; } public double f(double x, SliderMatrix p) { return 4.0; } public void farray( double minx, double maxx, int density, double[] X, double[] Y, SliderMatrix p) { double dx = Math.abs(maxx - minx) / (double) density; double x, y, g, h; int i; try { g = p.val("g"); h = p.val("h"); } catch (Error e) { g = 0.0; h = 0.0; } x = minx; i = 0; while (x < maxx && i < density) { y = x * g; X[i] = x; Y[i] = y; x += dx; i++; } } }