This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Vector " Watch "Vector " New topic


Maya Naga
Ranch Hand

Joined: Nov 09, 2009
Posts: 79
hi am new to java collections...

in my program am doing calculations and adding those string result values to a vector...
i want to display those values one by one when i click the next and previous button..

when i code as follows only the last value is displayed in text field...

by i want to display all values ..
what i want to do..
please help....
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Check out JList.

How To Ask Questions How To Answer Questions
Pari Nanoti

Joined: Nov 09, 2009
Posts: 9
This is where i think the problem is

A) Logic:
1) You don't need MouseListener, you need ActionListener: one for each button (Next and Previous)

2) Don't loop through the collection, get the next or previous result strnig, based on what button was clicked, and set it in the txtresult

B) Optimization
1) No need of s,s1,s2,s3,s4, string and str variables, you can concatenate the result in the argument to v.addElement() itself.
2) There in no need to convert Vector into array, you can use the vector itself.
3) If you are using 1.5 or higher, go for generics, you can avoid the toString() call.

Thanks & Regards, Happy to help
Parimal Nanoti (SCJP 6)
Maya Naga
Ranch Hand

Joined: Nov 09, 2009
Posts: 79
thanks pari..
that worked
I agree. Here's the link:
subject: Vector
It's not a secret anymore!