/*************************************************************/ /* Program Name: Lab6ExperimentView */ /* */ /*************************************************************/ import java.awt.*; import java.applet.*; import java.awt.event.*; import java.text.DecimalFormat; import javax.swing.*; public class Lab6ExperimentView extends JFrame { // Class declaration protected JTextField dataN = new JTextField(); protected JButton dataB = new JButton("submit"); protected JLabel dataL = new JLabel("data #"); protected JTextField[] disFields; protected JButton avgButton = new JButton("avg"); protected JButton maxButton = new JButton("max"); protected JComboBox cbOptions = new JComboBox(); protected JButton resetButton = new JButton("reset"); protected JTextField resField = new JTextField(15); protected JPanel dataP = new JPanel(); protected JPanel resultP = new JPanel(); protected JPanel numPanel = new JPanel(); protected JPanel resPanel = new JPanel(new GridLayout(1,5)); protected int numData; protected final boolean verbose = true; protected DecimalFormat decimal = new DecimalFormat("###,###.##"); public static void main(String args[]) { // Construct the frame new Lab6ExperimentView(); } public Lab6ExperimentView() // change init method to a constructor { dataN.setText("0"); setFont(new Font("TimesRoman",Font.BOLD,14)); setBounds(200,400,700,200); setVisible(true); setLayout(new FlowLayout()); addOptions(); dataP.add(dataL);dataP.add(dataN);dataP.add(dataB); dataN.requestFocus(); dataP.setBackground(Color.GREEN); setBounds(200,400,700,400); setLayout(new BorderLayout()); add(dataP,BorderLayout.NORTH); setVisible(true);validate(); } private void addOptions() { cbOptions.addItem("Select Operation" ); cbOptions.addItem("std sample") ; cbOptions.addItem("std population") ; cbOptions.addItem("Sort with doubles") ; cbOptions.addItem("Sort with Strings") ; cbOptions.addItem("Search unsorted") ; cbOptions.addItem("Search sorted") ; } protected void addPanel() { if(validateInt(dataN.getText())) { numData = Integer.parseInt(dataN.getText()); int dataR = (int) numData/5+1; disFields = new JTextField[numData]; numPanel.setLayout(new GridLayout(dataR,5,2,2)); numPanel.setBackground(Color.MAGENTA); resPanel.setBackground(Color.BLUE); add(numPanel, BorderLayout.CENTER); add(resPanel, BorderLayout.SOUTH); for( int i = 0; i< numData ; i++ ) { disFields[i] = new JTextField(10); numPanel.add(disFields[i]); } resPanel.add(avgButton); resPanel.add(maxButton); resPanel.add(cbOptions); resPanel.add(resetButton); resPanel.add(resField); validate(); repaint(); } else dataN.setText("submit integer"); } private boolean validateInt(String s) { try{ int v = Integer.parseInt(s); return true; } catch (NumberFormatException e) { System.out.println("please type a number"); return false;} } } // end Class