Results 1 to 2 of 2
Thread: images not displaying?
- 01-29-2013, 07:50 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 1
- Rep Power
- 0
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 ); }; } } }
the cards are 71x96 pixelsLast edited by imawesum; 01-29-2013 at 11:54 PM.
- 01-29-2013, 08:26 PM #2
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 - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
Similar Threads
-
Displaying An Array Of Images
By dofod in forum AWT / SwingReplies: 3Last Post: 04-02-2012, 06:22 PM -
displaying images
By sukanya in forum JavaServer Pages (JSP) and JSTLReplies: 6Last Post: 03-25-2012, 03:46 PM -
Images not displaying in JFrame.
By jlennards in forum AWT / SwingReplies: 3Last Post: 07-12-2011, 04:46 AM -
[SOLVED] Need help in displaying images
By kirly in forum Advanced JavaReplies: 3Last Post: 10-21-2008, 06:36 AM -
Images not displaying in JSP in IE7
By chadscc in forum Advanced JavaReplies: 0Last Post: 11-13-2007, 04:24 PM
Bookmarks