• 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

random images

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1376
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic