import javax.swing.*; import javax.swing.event.*; //import com.sun.java.swing.*; //import com.sun.java.swing.event.*; import java.awt.*; import java.awt.event.*; import java.util.Vector; import java.text.*; public class GraphPanel extends JPanel implements ChangeListener { Vector v[] = new Vector[2]; AspireGraph aspiregraph; PlotSource plotSource; String names[] = new String[2]; double data[][] = new double[2][]; int count[] = new int[1]; JButton regress; JLabel equationLabel = new JLabel("y = mx + b"); JLabel mValueLabel = new JLabel("m ="); JLabel bValueLabel = new JLabel("b ="); DecimalFormat format; GraphPanel(PlotSource plotSource) { super(false); this.plotSource = plotSource; setLayout(new BorderLayout(15,0)); aspiregraph = new AspireGraph(names, data, count); add(aspiregraph,BorderLayout.CENTER); JPanel infoPanel = new JPanel(new GridLayout(4,1)); add(infoPanel,BorderLayout.WEST); ImageIcon icon1 = new ImageIcon(getClass().getResource("images/mreg.gif")); JPanel buttonHolder = new JPanel(); regress = new JButton("Linear Regession", icon1); buttonHolder.add(regress); infoPanel.add(buttonHolder); regress.addActionListener(new FindLineButtonListener()); JPanel MandBPanel = new JPanel(new GridLayout(3,1,10,10)); MandBPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(5,5,5,5))); Font f = bValueLabel.getFont(); Font f2 = new Font(f.getName(),f.getStyle(),3*f.getSize()/2); equationLabel.setFont(f2); bValueLabel.setFont(f2); mValueLabel.setFont(f2); MandBPanel.add(equationLabel); MandBPanel.add(bValueLabel); MandBPanel.add(mValueLabel); infoPanel.add(MandBPanel); setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); // set number formatting format = new DecimalFormat(); format.setMaximumFractionDigits(3); } public void stateChanged(ChangeEvent e) { if(((JTabbedPane)e.getSource()).getSelectedIndex() == 1){ count[0] = plotSource.getData(names,data); aspiregraph.initializeLabels(); bValueLabel.setText("b = "); mValueLabel.setText("m = "); aspiregraph.drawLine = false; if (count[0] < 2) { regress.setEnabled(false); return; } else regress.setEnabled(true); } } class FindLineButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { double b,m; double xsum = 0.0f; double ysum = 0.0f; double xxsum = 0.0f; double xysum = 0.0f; for(int i=0;i