Results 1 to 2 of 2
  1. #1
    imawesum is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Default images not displaying?

    I'm trying to create a program (applet) to "shuffle" a deck of cards and display the first ten cards of the deck. My solution so far is this:
    (the filenames for the cards are c1.gif (ace of clubs) c2.gif (two of clubs), etc.)

    java code:

    Java Code:
    import java.applet.*;
    import java.awt.*;
    
    public class DeckOfCards extends Applet
    {
    
    public Image clubs[] = new Image[13];
    public Image hearts[] = new Image[13];
    public Image spades[] = new Image[13];
    public Image diamonds[] = new Image[13];
    
    	public void init()
    	{
    		for( int i = 0; i < 13; i++ )
    		{
    			clubs[i] = getImage( getDocumentBase(),"http://www.java-forums.org/images/c" + i + ".gif" );
    			hearts[i] = getImage( getDocumentBase(),"http://www.java-forums.org/images/h" + i + ".gif" );
    			spades[i] = getImage( getDocumentBase(),"http://www.java-forums.org/images/s" + i + ".gif" );
    			diamonds[i] = getImage( getDocumentBase(),"http://www.java-forums.org/images/d" + i + ".gif" );
    		}
    	}
    	
    	public void paint( Graphics screen )
    	{
    		int x[] = new int[10];
    		int y = 0;
    			
    		for( int i = 0; i < 10; i++ )
    		{
    			x[i] = (int)( Math.random() * 52 ); 
    			y = x[i];
    			
    			System.out.println( x[i] );
    			
    			if( 1 <= y && y <= 13 )
    			{
    				screen.drawImage( clubs[y], 10, 10, this );
    			}
    			else if( 14 <= y && y <= 26 )
    			{
    				screen.drawImage( hearts[ y - 13 ], 10, 10, this );
    			} 
    			else if ( 27 <= y && y <= 39 )
    			{
    				screen.drawImage( spades[ y - 26 ], 10, 10, this );
    			}
    			else if ( 40 <= y && y <= 52 )
    			{
    				screen.drawImage( diamonds[ y - 39 ], 10, 10, this );
    			};
    			
    		}
    	}
    }
    But I can't figure out how to display the cards in a format of five cards per row, two rows. any ideas?
    the cards are 71x96 pixels
    Last edited by imawesum; 01-29-2013 at 10:54 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: images not displaying?

    If I were you, I would get out a piece of graph paper and a pencil and start drawing out example until you see a pattern in the coordinates.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Displaying An Array Of Images
    By dofod in forum AWT / Swing
    Replies: 3
    Last Post: 04-02-2012, 05:22 PM
  2. displaying images
    By sukanya in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 03-25-2012, 02:46 PM
  3. Images not displaying in JFrame.
    By jlennards in forum AWT / Swing
    Replies: 3
    Last Post: 07-12-2011, 03:46 AM
  4. [SOLVED] Need help in displaying images
    By kirly in forum Advanced Java
    Replies: 3
    Last Post: 10-21-2008, 05:36 AM
  5. Images not displaying in JSP in IE7
    By chadscc in forum Advanced Java
    Replies: 0
    Last Post: 11-13-2007, 03:24 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •