With a little help I've finally managed to add an arrayList to my swing program. The problem is now with iteration through this list. When I try to go through the list, it simply jumps straight to the beginning or end of the list, depending on whether I click the backwards or forwards button.
The arrayList is printing out correctly, so I'm guessing the problem must be with the code for the iteration methods.
My code so far is as follows,
I can't seem to see the problem. Any advice or help appreciated.
I've tried that solution. The problem is that by setting currentPosition to 0, for some reason it is ignoring the arrayList, and starting at 0. It then increments the value from 1 upwards and does not go through the arrayList.
Maybe there's a way to link this to the arrayList, but I'm getting really confused at the moment.
Thanks for the reply. I have tried implementing the actionPerformed methods as suggested above, and I get a really weird result. It outputs an error saying 'ArrayIndexOutofBoundsException: -1'. Any ideas why this is happening?
My current is as follows,
I really can't see where the problem is with these methods. It's all very strange.
Any help or advice really appreciated at this stage.
[ January 29, 2006: Message edited by: celine scarlett ] [ January 29, 2006: Message edited by: celine scarlett ]
I dont see the error myself. One thought would be to make sure that when the current index is 0, the back button is always disabled. And anytime you add a new value to the ArrayList, the current index should be set to (theList.size - 1).
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
With alot of help, I've managed to get the actionPerformed methods of the backward and forward buttons going through the arrayList correctly, with the exception of one small problem.
When a user enters a sequence of numbers eg: 22,32,42,52 and then presses the back button, they are taken back to 22, instead of 52. Then the user has to press the forward button. From this point on, the buttons work perfectly, and go backwards and forwards through the list.
Does anybody know why this error might be occurring?
My current code for the actionPerformed methods is as follows,