tags:

views:

30

answers:

1

I have a class that reads the state of what string is in a JTextFeild (displayBox is the class in this case). The method sould read the state put it into an ArrayList (lastState in this case) and the be able to put it back into the JText feild when a method is called (returnState in this case) displayBox is a object of class Jtextfeild declared and used in another class (Calculator class) I am trying to write an undo feature for a home work assignment. My question is this the correct way to go about the getting and setting of the array date, thanks. Code is below:

import java.util.*;
import java.awt.event.*;
import java.awt.*;
/**
 * Write a description of class Status here.
 * 
 * @author (Jason Sizemore ) 
 * @version (HW09 11-21-09)
 *  This is a class to get the status for the undo feature
 */
public class Status extends Calculator
{   
    //attributes
    private ArrayList<String> lastState;
    public String ls;

    public String rls;  
    //constructors

    public Status()
    {
        super();
        lastState = new ArrayList<String>(10);
    }

    //Methods
    public void copyState()
    {
        ls = displayBox.getText();
        lastState.add(ls);
        System.out.println(ls);
    }

    public String returnState()
    {
        //problem is here 
        int sizeOfArrayList; 
        sizeOfArrayList = lastState.size();
        rls = lastState.get(sizeOfArrayList);
        return rls;
    }
}
+1  A: 

To restate what Luno said, List.getSize() returns the count of elements in the List. The indexes start at 0, so the highest index you can ever get from a List is one less than the total number of elements.

spork
Thank you for the information
Size_J