ArrayList Weirdness

From: Advocated (......_at_......com)
Date: 02/09/04


Date: Mon, 9 Feb 2004 11:23:32 -0000

Hey there, im having real problems with my code.
the idea is, user presses a button, it adds that number to an arraylist,
then prints out the contents of the array list. For example if i press, 3
then 4 then 9 it should show 3, then show 34, then show 349 if that makes
any sense, like adds it to the end.

but its acting weird, for example if i press 9, it prints 99, then if i
press 1 afterwards, it prints 191.

Really confused about this, anyone got any ideas please?

//I initialise like:
    ArrayList alist = new ArrayList();
    int buttonNumber;

//Example Button:

    private void nineActionPerformed(java.awt.event.ActionEvent evt) {
        buttonNumber = 9;
        str = Integer.toString(buttonNumber);
        alist.add(str);
        printCode();
    }

// printCode() function

  private void printCode(){
          // for(i=0;i!= alist.size();i++) {
          for (int i = 0; i < alist.size(); i++) {

                str += alist.get(i);

            }
            screen.setText(str);

    }


Loading