Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Newbie - problem with getting a file in load of image
Newbie - problem with getting a file in load of image [message #638957] Sat, 13 November 2010 22:11 Go to next message
Mark is currently offline MarkFriend
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

Re: Newbie - problem with getting a file in load of image [message #638963 is a reply to message #638957] Sun, 14 November 2010 01:07 Go to previous message
Mark is currently offline MarkFriend
Messages: 4
Registered: December 2009
Location: VT, USA
Junior Member
Hi,
I found working directory under the settings for the project, and got refs working to image files putting them there (which was neither src nor bin, was their common project root dir). Well, that fixes that. Thx!

- Mark

[Updated on: Sun, 14 November 2010 01:08]

Report message to a moderator

Previous Topic:Statement-level IJavaElementDelta
Next Topic:Problem connecting to MySql
Goto Forum:
  


Current Time: Fri Apr 26 17:07:04 GMT 2024

Powered by FUDForum. Page generated in 0.03159 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top