I'm trying to create an applet that loads 52 cards, shuffles them(using random number generator), then displays the top 10 cards of the deck in two rows of five. I have the HTML file with the 52 images of the cards, but is there a way to load the images without having to load each individual image. And how do you load images from the web?
2 Answers
..is there a way to load the images without having to load each individual image
Put them in one huge image and slice it up at run-time. There is an example in this answer.

Search Google images for 'playing+card' and it is likely there will be 2 or more tile sets in the first page of hits.
But then, even faster is to load:
- Card backdrop
 ImageorShapeof each suit symbolImageof orFontfor the letters and numbers.
Then combine them at start-up to form each of the 52 cards.
It will apparently also require a common 'reverse side' for the cards.
how do you load images from the web?
By URL.
Some alternatives:
Applet.getImage(URL)Toolkit.getImage(URL)- Or for a synchronously loaded 
BufferedImageuseImageIO.read(URL) 
The first two methods are asynchronous & require an ImageObserver.
Consider doing this as an application launched using Java Web Start. If you proceed with using an applet, go through the links in the applet info. page.
- 1
 - 1
 
- 168,117
 - 40
 - 217
 - 433
 
Try this.
Image[] cards = new Image[52]
private void loadImages(){
    for (int i=0; i<cards.length; i++){
        URL imgUrl = getClass().getResource("image"+(i+1));
        cards[i] = getImage(imgUrl);
    }
}
Hope this helps
- 11,744
 - 6
 - 50
 - 91
 
- 
                    if I make all the methods in the program private, will the applet still run? – CuriousTim Oct 02 '12 at 04:56
 - 
                    You simply call the `loadImages()` method from the `init()` method of the applet – Sri Harsha Chilakapati Oct 02 '12 at 08:35