• Post Reply Bookmark Topic Watch Topic
  • New Topic

Iterating Through Array List with Button  RSS feed

 
john gere
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, how do you iterate an arraylist say of 12 items, but only 4 at a time using a jbutton. In other words, when the gui launches, the first 4 items show, then every time the button is clicked, the next four items show and so on until the end of the Array List? How is this done? All I know is that, it has something to do with the actionperformed method or action listener.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might want to break the loop after 4 iterations and an action listener associated with the button.
 
john gere
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand the 4 iterations and breaking the loop. But what would the action listener store? Use it to keep the track of the 'condition' of the loop?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a crude code..

 
john gere
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!