Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes random images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "random images" Watch "random images" New topic
Author

random images

s corrigan
Greenhorn

Joined: Aug 07, 2003
Posts: 1
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?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: random images