Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector

 
Maya Naga
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out JList.
 
Pari Nanoti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maya Naga
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks pari..
that worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic