• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating and manipulating buttons using JButton....  RSS feed

 
Ryon Groff
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, this is for a beginner java class, and I'm struggling. Basically, we have an array full of different albums and information about them, and now I need to create a GUI that allows a user to move next, previous, first, and last. It seems simple enough, but I'm a little bit confused, I can't seem to wrap my head around the code I need. I have a next and previous button already established, but when I run the program (using the next button) and reach the last entry, it will not let me use the previous button to go back. The next and previous buttons also need to scroll through the entire thing, ex. pressing next after the last entry brings you to the first entry, and vice versa. I have several classes but I am only going to post the one I'm working in, but I can post them if they are needed. The code block with the buttons is about halfway down...I added a big space between to make it easier to find.
You guys are really great, and I've actually learned a great deal just reading through these posts, apologies if something like this has been posted recently, I didn't find anything.



 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please UseCodeTags when you post source code. I added them to your post above for you.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you get it to work without a GUI?Give your Inventory class get(int), getNext(), getPrevious() methods. You would have to record the index being accessed inside the Inventory object. Using the % operator, you can use the getNext() method to go from the last to the first, and vice versa for getPrevious().
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!