I have not completed this application and do not intend to - here is the code.
Will calculate various things for parabolic curves - i was going to implement a graphical interface to show visually the important data associated with parabolic curves, however i am short on time at the moment.
Media
Source Code is below
package Grapher; /** * * @author bbq */ public class MathFunctions { private double sample_rate, min, max; private double a, b, c; private boolean min_tp = true; public MathFunctions(double a, double b, double c, double sample_rate, double min, double max ) { this.a = a; this.b = b; this.c = c; this.sample_rate = sample_rate; this.min = min; this.max = max; } public double get_y_value( double x_val) { return ( (this.a * x_val *x_val) + (this.b * x_val) + this.c ); } public String getDiffEquation() { if (this.b > 0) return ( (2 * this.a)+"x + " + this.b ); else if (this.b == 0) return ( (2 * this.a)+"x" ); else return ( (2 * this.a)+"x - " + (this.b * -1) ); } public double getTurningPt() { double zero; zero = ( 0 - this.b ) / ( this.a * 2); return zero; } public String min_or_max() { if ( this.a > 0) return "Minimum"; else if ( this.a < 0) return "Maximum"; else return "Inflection"; } }
package Grapher; /** * * @author bbq */ import javax.swing.*; import java.awt.*; public class GraphPane extends Frame { // yet to be implemented }
package Grapher; /** * * @author bbq */ public class GraphPoint { private double x, y; public GraphPoint( double x, double y) { this.x = x; this.y = y; } public double getX() { return this.x; } public double getY() { return this.y; } @Override public String toString() { return ( "( " + String.format("%.3f", this.x) +", " + String.format("%.3f", this.y) + " )" ); } }
package Grapher; /** * * @author bbq */ import java.awt.*; import javax.swing.*; public class AccuracySelector extends JFrame { private boolean bFinished = false; public AccuracySelector(int x, int y) { this.setTitle("Define Accuracy"); this.setSize(160,120); this.setLayout(new GridLayout(2,1)); this.setLocation(x,y); this.top = new JPanel(); this.top.setSize(160, 100); this.top.setLayout(new GridLayout( 3, 2)); this.bottom = new JPanel(); this.bottom.setLayout(new FlowLayout() ); this.bottom.setSize( 160, 20 ); this.sample_rate_label = new JLabel("Sample Rate"); this.sample_rate_label.setSize(20, 15); this.min_range_label = new JLabel("Min Range"); this.min_range_label.setSize(20,15); this.max_range_label = new JLabel("Max Range"); this.max_range_label.setSize(20,15); this.sample_rate_field = new JTextField(); this.sample_rate_field.setSize(20, 15); this.min_range_field = new JTextField(); this.min_range_field.setSize(20,15); this.max_range_field = new JTextField(); this.max_range_field.setSize(20,15); this.top.add(sample_rate_label); this.top.add(sample_rate_field); this.top.add(min_range_label); this.top.add(min_range_field); this.top.add(max_range_label); this.top.add(max_range_field); this.finished = new Button("Finished"); this.finished.setSize(30,15); this.bottom.add(this.finished); this.add(top); this.add(bottom); this.pack(); } public Button getButton() { return this.finished; } public JTextField getTextFieldSampleRate() { return this.sample_rate_field; } public JTextField getTextFieldMinRange() { return this.min_range_field; } public JTextField getTextFieldMaxRange() { return this.max_range_field; } public boolean getInputState() { return this.bFinished; } private Button finished; private JTextField sample_rate_field, min_range_field, max_range_field; private JPanel top, bottom; private JLabel sample_rate_label, min_range_label, max_range_label; }
package Grapher; /** * * @author bbq */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class G_Face extends JFrame implements ActionListener { // private vars private double sample_rate = 0; private double range_min = 0, range_max = 0; private double aVal = 0, bVal = 0, cVal = 0; private MathFunctions mathFunc; private ArrayList<GraphPoint> points; // package classes private AccuracySelector accurSel; private void initComponents() { // initialise input components this.mainInputs = new JPanel(); this.mainInputs.setLayout(new GridLayout(1,6,1,1)); this.A = new JLabel("A="); this.A.setSize(4,15); this.B = new JLabel("x"+ (char)(178) +" B="); this.B.setSize(8,15); this.C = new JLabel("x C="); this.C.setSize(8,15); this.aInput = new JTextField(); this.aInput.setSize(30, 15); this.bInput = new JTextField(); this.bInput.setSize(30,15); this.cInput = new JTextField(); this.cInput.setSize(30,15); this.mainInputs.add(this.A); this.mainInputs.add(this.aInput); this.mainInputs.add(this.B); this.mainInputs.add(this.bInput); this.mainInputs.add(this.C); this.mainInputs.add(this.cInput); // Move into the draw area panel this.drawParms = new JPanel(); this.drawParms.setSize(160, 550); this.drawParms.setBackground(Color.DARK_GRAY); this.drawParms.setLayout(new BorderLayout()); this.drawInfoPanel = new JPanel(); this.drawInfoPanel.setSize(160, 20); this.drawInfoPanel.setLayout(new GridLayout(1,2,5,2)); this.turningPoint = new JLabel("Turning Point (x, y)"); this.differentialFunction = new JLabel( "Diff"); this.drawInfoPanel.add(this.turningPoint); this.drawInfoPanel.add(this.differentialFunction); this.p = new TextArea(); this.p.setSize(160, 524); this.drawParms.add(this.drawInfoPanel, BorderLayout.NORTH); this.drawParms.add(this.p, BorderLayout.SOUTH); // controls // this.controls = new JPanel(); this.controls.setSize(160, 35); this.controls.setBackground(Color.lightGray); this.controls.setLayout(new GridLayout(1,3,2,2)); // intialise and add actionListeners this.getParms = new Button("Calculate"); this.getParms.setSize(30,20); this.getParms.addActionListener(this); this.showGraph = new Button("Show Graph"); this.showGraph.setSize(30,20); this.showGraph.addActionListener(this); this.infoButton = new Button("Info"); this.infoButton.setSize(30,20); this.infoButton.addActionListener(this); // add buttons to control this.controls.add(this.getParms); this.controls.add(this.showGraph); this.controls.add(this.infoButton); // add to JFrame and pack it all in this.add(this.mainInputs, BorderLayout.NORTH); this.add(this.drawParms, BorderLayout.CENTER); this.add(this.controls, BorderLayout.SOUTH); this.pack(); } public G_Face(String sup) { super(sup); this.setSize(160,700); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLayout(new BorderLayout()); initComponents(); } private void completeMaths() { this.points = new ArrayList<GraphPoint>(); this.mathFunc = new MathFunctions(this.aVal, this.bVal, this.cVal, this.sample_rate, this.range_min, this.range_max); double counter = this.range_min; do { this.points.add( new GraphPoint( counter, this.mathFunc.get_y_value( counter ))); counter += this.sample_rate; } while ( counter < this.range_max ); int i = 0; while( i < (this.points.size() ) ) { this.p.append(this.points.get(i).toString() + "\n"); i++; } this.differentialFunction.setText( "Differential : " + this.mathFunc.getDiffEquation() ); double p_x = this.mathFunc.getTurningPt(); this.turningPoint.setText( this.mathFunc.min_or_max() + " Point : " + (new GraphPoint( p_x, this.mathFunc.get_y_value(p_x) ).toString() ) ); } public void actionPerformed(ActionEvent e) { // if get we want to see info if (e.getSource() == this.getParms) { try { aVal = Double.parseDouble(this.aInput.getText() ); bVal = Double.parseDouble(this.bInput.getText() ); cVal = Double.parseDouble(this.cInput.getText() ); } catch(Exception q) { JOptionPane.showMessageDialog(this.accurSel, q, "ERROR", JOptionPane.ERROR_MESSAGE); return; } this.accurSel = new AccuracySelector(this.getLocation().x, this.getLocation().y); this.accurSel.getButton().addActionListener(this); this.accurSel.setVisible(true); } if ( e.getSource() == this.accurSel.getButton() ) { try { this.range_max = Double.parseDouble( this.accurSel.getTextFieldMaxRange().getText() ); this.range_min = Double.parseDouble( this.accurSel.getTextFieldMinRange().getText() ); this.sample_rate = Double.parseDouble( this.accurSel.getTextFieldSampleRate().getText() ); } catch(Exception q) { JOptionPane.showMessageDialog(this.accurSel, q, "ERROR", JOptionPane.ERROR_MESSAGE); return; } this.accurSel.dispose(); completeMaths(); } } public static void main(String[] args) { G_Face p = new G_Face("Parabolic Grapher Alpha"); p.setVisible(true); } // components relating to inputs private JPanel mainInputs; private JLabel A, B, C; // lables for consts private JTextField aInput, bInput, cInput; // get our consts // draw related private JPanel drawParms; private JPanel drawInfoPanel; private JLabel turningPoint, differentialFunction; private java.awt.List pointsList; private TextArea p; // functional buttons private JPanel controls; private Button getParms, showGraph, infoButton; }
