import java.text.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class QuadrilateralApplet extends JApplet implements ActionListener { JLabel aLabel, bLabel, cLabel, dLabel, hLabel; JTextField aField, bField, cField, dField, hField; JButton zoomInButton, zoomOutButton; //JRadioButton hypoRadioButton, epiRadioButton, traceRadioButton; //ButtonGroup graphButtonGroup; // JButton aUpButton, aDownButton, bUpButton, bDownButton, zoomInButton, zoomOutButton; //JSlider rSlider, dSlider; final static int westpanelwidth=150; final static int northpanelheight=50; double xLo=0, xHi=1, yLo=0, yHi=1; double a, b, c, d, h; //int graphChoice; //hypo or epi //boolean trace=false; //double [] X, Y; public void init() { Container container = getContentPane(); container.setLayout(null); //** no Layout Manager JPanel westPanel = new JPanel(); westPanel.setLayout( new GridLayout(5,2) ); westPanel.setBackground(Color.LIGHT_GRAY); westPanel.setBounds(0,0, westpanelwidth,100); //westPanel.setLayout(null); container.add(westPanel); /* JPanel coeffsPanel = new JPanel(); coeffsPanel.setLayout(new FlowLayout()); westPanel.add(coeffsPanel); */ /* JPanel plotXPanel = new JPanel(); plotXPanel.setLayout(new FlowLayout()); westPanel.add(plotXPanel); JPanel plotYPanel = new JPanel(); plotYPanel.setLayout(new FlowLayout()); westPanel.add(plotYPanel); JPanel plotTickPanel = new JPanel(); plotTickPanel.setLayout(new FlowLayout()); westPanel.add(plotTickPanel); */ JPanel zoomPanel = new JPanel(); zoomPanel.setBackground(Color.BLACK); //zoomPanel.setBounds(0,getHeight()-200, westpanelwidth,40); zoomPanel.setBounds(getWidth()-200,0, 200,40); container.add(zoomPanel); /* JPanel radioPanel = new JPanel(); //radioPanel.setBackground(Color.BLACK); radioPanel.setBounds(200,0, 200,40); container.add(radioPanel); */ aLabel = new JLabel( "a" ); westPanel.add( aLabel ); aField = new JTextField("1",3 ); aField.setHorizontalAlignment(JTextField.RIGHT); aField.addActionListener( this ); westPanel.add( aField ); bLabel = new JLabel( "b" ); westPanel.add( bLabel ); bField = new JTextField("1",3 ); bField.setHorizontalAlignment(JTextField.RIGHT); bField.addActionListener( this ); westPanel.add( bField ); cLabel = new JLabel( "c" ); westPanel.add( cLabel ); cField = new JTextField("1",3 ); cField.setHorizontalAlignment(JTextField.RIGHT); cField.addActionListener( this ); westPanel.add( cField ); dLabel = new JLabel( "d" ); westPanel.add( dLabel ); dField = new JTextField("1",3 ); dField.setHorizontalAlignment(JTextField.RIGHT); dField.addActionListener( this ); westPanel.add( dField ); hLabel = new JLabel( "h" ); westPanel.add( hLabel ); hField = new JTextField("1",3 ); hField.setHorizontalAlignment(JTextField.RIGHT); hField.addActionListener( this ); westPanel.add( hField ); /* rSlider = new JSlider( SwingConstants.VERTICAL, 0, 100, 20 ); rSlider.setMajorTickSpacing( 10 ); //horizSlider.setMinorTickSpacing( 1 ); rSlider.setPaintTicks( true ); //horizSlider.setPaintLabels( true ); rSlider.setBounds(0,100, 40,210); container.add(rSlider); rSlider.addChangeListener( new ChangeListener() { public void stateChanged( ChangeEvent e ) { rField.setText(""+(rSlider.getValue()/100.0)); rField.postActionEvent(); } } ); */ //coeffsPanel.add( aField ); /* aUpButton = new JButton( "\u2191" ); aUpButton.setBounds(0,180,50,20); container.add( aUpButton ); aUpButton.addActionListener( this ); aDownButton = new JButton( "\u2193" ); aDownButton.setBounds(0,200,50,20); container.add( aDownButton ); aDownButton.addActionListener( this ); */ /* hypoRadioButton = new JRadioButton( "Hypotrochoid" ); hypoRadioButton.setSelected(true); radioPanel.add( hypoRadioButton ); hypoRadioButton.addItemListener( this ); graphChoice = 1; epiRadioButton = new JRadioButton( "Epitrochoid" ); radioPanel.add( epiRadioButton ); epiRadioButton.addItemListener( this ); graphButtonGroup = new ButtonGroup(); graphButtonGroup.add(hypoRadioButton); graphButtonGroup.add(epiRadioButton); traceRadioButton = new JRadioButton( "Trace" ); traceRadioButton.setBounds(500,10,60,20); container.add( traceRadioButton ); traceRadioButton.addItemListener( this ); */ //coeffsPanel.add( bField ); /* bUpButton = new JButton( "\u2191" ); bUpButton.setBounds(260,5,50,20); container.add( bUpButton ); bUpButton.addActionListener( this ); bDownButton = new JButton( "\u2193" ); bDownButton.setBounds(260,25,50,20); container.add( bDownButton ); bDownButton.addActionListener( this ); */ /* xLowLabel = new JLabel( "X low" ); plotXPanel.add( xLowLabel ); xLowField = new JTextField( "-1",3 ); xLowField.setHorizontalAlignment(JTextField.RIGHT); xLowField.addActionListener( this ); plotXPanel.add( xLowField ); xHighLabel = new JLabel( "X high" ); plotXPanel.add( xHighLabel ); xHighField = new JTextField( "1",3 ); xHighField.setHorizontalAlignment(JTextField.RIGHT); xHighField.addActionListener( this ); plotXPanel.add( xHighField ); yLowLabel = new JLabel( "Y low" ); plotYPanel.add( yLowLabel ); yLowField = new JTextField( "-1",3 ); yLowField.setHorizontalAlignment(JTextField.RIGHT); yLowField.addActionListener( this ); plotYPanel.add( yLowField ); yHighLabel = new JLabel( "Y high" ); plotYPanel.add( yHighLabel ); yHighField = new JTextField( "1",3 ); yHighField.setHorizontalAlignment(JTextField.RIGHT); yHighField.addActionListener( this ); plotYPanel.add( yHighField ); tickIntervalLabel = new JLabel( "Tick interval" ); plotTickPanel.add( tickIntervalLabel ); tickIntervalField = new JTextField( "1",2 ); tickIntervalField.setHorizontalAlignment(JTextField.RIGHT); tickIntervalField.addActionListener( this ); plotTickPanel.add( tickIntervalField ); */ zoomInButton = new JButton( "Zoom IN" ); zoomPanel.add( zoomInButton ); zoomInButton.addActionListener( this ); zoomOutButton = new JButton( "Zoom OUT" ); zoomPanel.add( zoomOutButton ); zoomOutButton.addActionListener( this ); aField.postActionEvent(); } public void actionPerformed( ActionEvent event ) { double aTry, bTry, cTry, dTry, hTry; DecimalFormat d2, d1; d2 = new DecimalFormat ("0.00"); d1 = new DecimalFormat ("0.0"); if ( event.getSource() == aField || event.getSource() == bField ) { try { aTry = Double.parseDouble(aField.getText()); bTry = Double.parseDouble(bField.getText()); cTry = Double.parseDouble(cField.getText()); dTry = Double.parseDouble(dField.getText()); hTry = Double.parseDouble(hField.getText()); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "a, b, c, d and h must be numbers", "Quadratic: Invalid input", JOptionPane.ERROR_MESSAGE); return; } a = aTry; b = bTry; c = cTry; d = dTry; h = hTry; //rSlider.setValue((int)(r*100)); //doesn't invoke handler? } // double xLo, xHi, yLo, yHi, tickInt; /* try { xLo = Double.parseDouble(xLowField.getText()); xHi = Double.parseDouble(xHighField.getText()); yLo = Double.parseDouble(yLowField.getText()); yHi = Double.parseDouble(yHighField.getText()); tickInt = Double.parseDouble(tickIntervalField.getText()); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "Plotting coordinates must be numbers", "Quadratic plotting: Invalid input", JOptionPane.ERROR_MESSAGE); return; } if (xLo>xHi || yLo>yHi || tickInt<=0) { JOptionPane.showMessageDialog(null, "Bad plotting coordinates", "Quadratic plotting: Invalid input", JOptionPane.ERROR_MESSAGE); return; } */ /* else if ( event.getSource() == aUpButton ) { a += .1; aField.setText(""+d1.format(a)); vertSlider.setValue ((int)(a*10)); } else if ( event.getSource() == aDownButton ) { if (a >= .1) a -= .1; else a = 0; aField.setText(""+d1.format(a)); vertSlider.setValue ((int)(a*10)); } else if ( event.getSource() == bUpButton ) { b += .1; bField.setText(""+d1.format(b)); horizSlider.setValue ((int)(b*10)); } else if ( event.getSource() == bDownButton ) { if (b >= .1) b -= .1; else b = 0; bField.setText(""+d1.format(b)); horizSlider.setValue ((int)(b*10)); } */ else if ( event.getSource() == zoomInButton ) { double scale = .9; //shrink the grid by 10% xLo *= scale; xHi *= scale; yLo *= scale; yHi *= scale; } else if ( event.getSource() == zoomOutButton ) { double scale = 1.1; //grow the grid by 10% xLo *= scale; xHi *= scale; yLo *= scale; yHi *= scale; } /* int numPoints=5000; X = new double[numPoints]; Y = new double[numPoints]; double dt = 2*Math.PI/numPoints; double t=0; for (int i=0; i