Jump to content

  • Log In with Google      Sign In   
  • Create Account


Pack images into .jar file?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 miicchhii   Members   -  Reputation: 212

Like
0Likes
Like

Posted 17 December 2012 - 01:22 PM

Hello everyone!

I just started learning Java and i use eclipse.
At the moment i work on a Pong game and i want to include some pictures
i.e. a ball instead of a circle, to make it look better.

This is the Code i use to load the image:

try {
	  img_ball = ImageIO.read(new File("/home/michael/Desktop/workspace-java/JPong/src/ball2.png"));
  } catch (IOException e) {
   System.out.println("ball2.png not found!");
  }

As you can see i use absolute paths, because relative would not work at all.
But using absolute paths is not what i want since i'm not the only to playing it.

Where do i have to place those files to be accessible relatively?
I would also like to put it INTO the jar file, so the release is just one file to run without the folders with files

Thanks in advance!

Sponsor:

#2 minibutmany   Members   -  Reputation: 1590

Like
0Likes
Like

Posted 18 December 2012 - 04:07 PM

I encountered a similar issue recently, so I feel your pain and frustration!
Here's the code I use to load images, storing each image in a folder called "Image" inside of src:
	 	   BufferedImage img_ball;		  
	 	   String Pathl1 = "Images/ball2.png";
			InputStream streaml1 =  MyClass.class.getResourceAsStream(Pathl1);
			img_ball = ImageIO.read(streaml1);

When you export as compile you .jar all the images in your Image folder will be packaged inside.
Your going to make the following imports:

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;

Oh yeah, change "MyClass" to whatever the name of your class is
Stay gold, Pony Boy.

#3 miicchhii   Members   -  Reputation: 212

Like
0Likes
Like

Posted 19 December 2012 - 12:19 AM

Thanks for the answer!
I hope this will solve my problem! :)

#4 miicchhii   Members   -  Reputation: 212

Like
0Likes
Like

Posted 19 December 2012 - 05:13 AM

Thank you so much!
It works, but i had to make a folder inside the Class, not inside src

:)

Here is a dl, i would appreciate some feedback!
http://www.langeder.org/wordpress/jpong-version-1-1-released-multiplayer-launcher/

#5 minibutmany   Members   -  Reputation: 1590

Like
1Likes
Like

Posted 20 December 2012 - 03:39 PM

Looks good! Maybe you could make an AI single player version, because it doesn't look like you have a very large server community! Very cool!
Stay gold, Pony Boy.

#6 miicchhii   Members   -  Reputation: 212

Like
0Likes
Like

Posted 23 December 2012 - 06:19 AM

Looks good! Maybe you could make an AI single player version, because it doesn't look like you have a very large server community! Very cool!

Thanks!
I guess i will do that, since jPong isn't a game one would play on a LAN-Party.

I thought about creating a game-lobby,
where one can download the games and directly connect to other players,
but that will take a while.

#7 3Ddreamer   Crossbones+   -  Reputation: 3134

Like
0Likes
Like

Posted 23 December 2012 - 01:33 PM

Hi,

 

It is not always possible or practical to load all the images into a .jar file.  When a file is part of a model or the file is to be changed dynamically, then your solution could be least useful.   Class and subclass structure should take into consideration such things, just so you know in future game structure. 


Personal life and your private thoughts always effect your career. Research is the intellectual backbone of game development and the first order. Version Control is crucial for full management of applications and software.  The better the workflow pipeline, then the greater the potential output for a quality game.  Completing projects is the last but finest order.

 

by Clinton, 3Ddreamer





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS