Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a JPanel/image viewer and I want to insert images into it. The thing is I

ID: 3621936 • Letter: I

Question

I have a JPanel/image viewer and I want to insert images into it. The thing is I want to be able to insert more than one image. There should be no limit to how many pictures I can insert, which I would use a for loop for that perhaps. I want to be able to have buttons to view a picture forward and backwords.

I just read up on how to add image with File->Open and image and display it on a image panel. I'm just puzzled with adding multiple images and still remembering the images are still there and I want to toggle between them.

Explanation / Answer

It sounds like you need an ArrayList to hold pictures, not a Stack. A Stack is good for accessing the most recently placed element; an ArrayList will allow you to change indices more freely. A linked list would be more efficient in space, but you must have access to the list nodes to have O(1) time lookup.

This site may help you with reading images from files.