• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating and manipulating buttons using JButton....

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please UseCodeTags when you post source code. I added them to your post above for you.
 
Marshal
Posts: 79265
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
reply
    Bookmark Topic Watch Topic
  • New Topic