Re: Vector Help
From: SPG (steve.nospoo.goodsell_at_nopoo.blueyonder.co.uk)
Date: 04/22/04
- Next message: Evan Dekker: "applet paint? not sure why this doesn't work..."
- Previous message: Jeff Schwab: "[OT] Re: with X Y separate dual-bus"
- In reply to: Row: "Re: Vector Help"
- Next in thread: Row: "Re: Vector Help!!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 22 Apr 2004 11:11:55 GMT
Rowan,
This is a simple example of how you should implement it..
public class MyClass{
private int vectPointer = 0;
private Vector myVect;
public MyClass(){
myVect = new Vector();
//Now do your population of the Vector...
//Set pointer to 0;
vectPointer = 0;
}
public String GetNext(){
String val = (String)myVect.elementAt(vectPointer);
vectPointer++;
if( vectPointer >= myVect.Size()){
val = null
}
return val;
}
public String GetPrevious(){
if( vectPointer == 0) return null;
vectPointer--;
return (String)myVect.elementAt(vectPointer);
}
}
Steve
"Row" <soul_fly@punkass.com> wrote in message
news:4d68ed39.0404211943.162e907d@posting.google.com...
> Thanks for the reply steve,
>
> Unfortunatly i really have no idea about linked lists.
> I would like the keep the Iterator, but again i have no idea how to
> implement an iterator as a class level variable?
> I have tried putint the new Iterator at the top of my main class.
>
> but when i run the program it throws an exception relating to the
> Iterator :(
>
> Could you please describe how you would put the list Iterator in a
> class method
> So a new Iterator isn't created every time i press next / or previous.
> like i said im new to this, so I would be so greatfull if you could
> show me.!!!!!
>
>
> thanks once again Steve and everyone else!
>
> Rowan
>
>
>
> "SPG" <steve.nospoo.goodsell@nopoo.blueyonder.co.uk> wrote in message
news:<LFvhc.27$T87.493699@news-text.cableinet.net>...
> > You could use a LinkedList, that makes traversing back and forth simple.
> > Your code always gets a new iterator on each click, so you will always
show
> > the first element in the list.
> >
> > If you want to keep your code using the listIterator, then I suggest you
use
> > a class level variable to store an instance of the iterator in.
> >
> > Good luck,
> >
> > Steve
> >
- Next message: Evan Dekker: "applet paint? not sure why this doesn't work..."
- Previous message: Jeff Schwab: "[OT] Re: with X Y separate dual-bus"
- In reply to: Row: "Re: Vector Help"
- Next in thread: Row: "Re: Vector Help!!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|