This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have tried the code below, but when run I get zero for total size. package arrayoffset; import java.awt.*; import java.awt.event.*; import javax.swing.*;
/** * * */ public class arrayOffset extends JFrame implements ActionListener{ int dim = 5; private String theOutput = ""; private int [] collectinput1 = new int[dim]; private int [] collectinput2 = new int[dim]; private JLabel [] enter; private JTextField [] input1; private JTextField [] input2; private JTextArea output;
/** Creates a new instance of arrayOffset */ public arrayOffset() { // Collect the number of dimension from user String num = JOptionPane.showInputDialog("Enter the number of dimension"); dim = Integer.parseInt(num); Container con = getContentPane(); con.setLayout(new FlowLayout()); //layout components to collect data enter = new JLabel [dim]; input1 = new JTextField[dim]; input2 = new JTextField[dim]; for(int i = 0; i<dim; i++) { enter [i]= new JLabel("Enter the upper and lower bounds for subscript:" + i); con.add(enter[i]); input1 [i] = new JTextField(2); input1 [i].addActionListener(this); con.add(input1[i]); input2 [i] = new JTextField(2); input2 [i].addActionListener(this); con.add(input2[i]); }
//add component to display data output = new JTextArea(10, 25); output.setEditable(false); con.add(output);
setSize(450, 400); setVisible(true); }
public void actionPerformed(ActionEvent l) { int size [] = new int [dim]; int totalSize = 0; //String [] myoutput = l.getActionCommand();