I'm trying to make a card game and need some help on how to display random images when a button has been pressed. Without using images just text I can diplay random numbers using the random function but have no idea how display a series of images, can anybody help?
Welcome to JavaRanch! Have you figured out how to display a single image? Feel free to post any relevant code. Just be sure to surround it with the [code] and [/code] UBB tags, in order to help preserve any formatting.
This is a pretty big question, and in order to make it manageable I'm going to assume that you know how to draw an image once you have an Image object. Instead, I'm going to focus on managing a group of Images to represent a deck of cards. So, let's say you have a deck of 52 cards. Let's further assume that you have 52 different images, one for each card. Finally, we'll say that the images are in 52 GIF files, one for each image, and that you have those 52 names in an array call imageFileNames. Load the images from the files:
Okay, now you want to display the appropriate image. You would need to generate a random number between 0 and 51 to select one of those cards, right? So let's say your generated value between 0 and 51 is stored in a variable called "card". The image for that card would be in cardImages[card]. Use this in the appropriate paint() method. Hope this helps. Joe