Newbie - problem with getting a file in load of image [message #638957] |
Sat, 13 November 2010 22:11 |
Mark Messages: 4 Registered: December 2009 Location: VT, USA |
Junior Member |
|
|
Hi,
I am just starting to find my way around in the Eclipse Java IDE - very slick stuff.. I found a code sample for the game "calculation", and I will be wanting to make card games. I did a few things with the JUnit project (tutorial), and then I tried to make a project out of calculation. Link: calculation source
The problem I have is when it gets to this in Pile.java...
ImageIcon imageicon = new ImageIcon( s );
Where s = 'deck.png"
Another snippet I downloaded MediaTrackerDemo got an image from a file ok but with Applet's getDocumentBase() to get a URL. The Pile.java file above does not have any references to Applet in it. Here's working code from MediaTrackerDemo:
imgArray[index] = getImage( getDocumentBase(), "deck0.PNG");
In both cases, I got a copy of the image file to the directory where it needs to go, but I don't know how to get it without a URL working, or to get a URL in Pile,java. Can I get the ImageIcon constructor call to work?
Here is the complete Pile constructor that uses ImageIcon to handle its images...
public Pile(String s)
{
// ImageIcon imageicon = new (ImageIcon) getImage( "deck0.PNG" );
ImageIcon imageicon = new ImageIcon( s );
cards = new ArrayList<Card>();
int i = imageicon.getIconWidth() / 13;
int j = imageicon.getIconHeight() / 4;
BufferedImage bufferedimage = new BufferedImage(i, j, 1);
Graphics2D graphics2d = bufferedimage.createGraphics();
for(int k = 0; k < 13; k++)
{
for(int l = 0; l < 4; l++)
{
graphics2d.drawImage(imageicon.getImage(), 0, 0, i, j, k * i, l * j, (k + 1) * i, (l + 1) * j, null);
Card card = new Card(k + 2, l, new ImageIcon(bufferedimage));
cards.add(card);
add(card, new Integer(13 * l + k + 1));
}
}
shuffle();
}
- Mark
[Updated on: Sat, 13 November 2010 22:21] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03274 seconds