Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Exporting a Final Project  (Read 398 times)
0 Members and 1 Guest are viewing this topic.
Offline bstrauch24

Junior Newbie


Exp: 2 years



« Posted 2014-07-08 22:58:27 »

I just recently finished a game using pure Java (no libraries like libgdx or lwjgl). When I exported it from Eclipse (Right-Click Project > Export... > Java > Runnable JAR File > Extract / Package Required Libraries Into Generated JAR > Finish) when opened, the JAR file showed a blank (grey) JFrame without any graphics drawn onto it. Could this be a problem with my code, (even though it runs fine in Eclipse)? Or possibly the way that I am exporting it? I am also using a sprite sheet for a pixel font in the game, but the background and characters are created in the game, so that most likely isn't the problem.
Offline death_angel
« Reply #1 - Posted 2014-07-08 23:01:20 »

your images folder need to be next to the jar file.

Like a Boss Hacker
Offline bstrauch24

Junior Newbie


Exp: 2 years



« Reply #2 - Posted 2014-07-08 23:04:45 »

Thanks for the help! It worked, but how can I prevent players from modifying the sprite sheets?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline death_angel
« Reply #3 - Posted 2014-07-08 23:06:49 »

Sorry i dont know any method to do that :/

Like a Boss Hacker
Offline danieldean

Senior Member


Medals: 5
Projects: 1



« Reply #4 - Posted 2014-07-08 23:17:02 »

If the images don't need to be edited then you can put them in your JAR instead.

I usually use NetBeans but I have Eclipse as well so I'll try to guide you through doing this. First make a folder in the root of your project where you want to store your images, if you don't already have one, and put the images in it. I'd use 'res' or 'img' as the name to make your intent clear.

Next open Eclipse and right click on the project, go to 'Java Build Path' and click on 'Add Folder', find and select the folder you used in the previous step. You should now see this next to 'src' in Eclipse. Anything in here will now be put in your JAR.

You will probably need to change the code to load these images. Something like:

1  
this.getClass().getResourceAsStream("/<Image_Name>");


Should do this for you, this gets you an InputStream. Note the slash, you will need it. Or maybe:

1  
this.getClass().getResource("/<Image_Name>");


Which gets a URL.

Hope this helps!
Offline bstrauch24

Junior Newbie


Exp: 2 years



« Reply #5 - Posted 2014-07-08 23:32:49 »

Thanks for your help! I have the build path set up, but I still don't understand the way that you suggested loading the images. Currently, I am using Buffered Images and storing the data in an array of pixels:

1  
2  
3  
4  
5  
private BufferedImage image;
image = ImageIO.read(new File("res/spritesheets/font.png"));

private int[] pixels;
pixels = image.getRGB(0, 0, width, height, pixels, 0, width);
Offline danieldean

Senior Member


Medals: 5
Projects: 1



« Reply #6 - Posted 2014-07-08 23:35:50 »

Simple, replace:

1  
ImageIO.read(new File("res/spritesheets/font.png"));


With:

1  
ImageIO.read(this.getClass().getResourceAsStream("/<Image_Name>"));


 Putting "/font.png" in there as the name should work. Wink
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 757
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2014-07-08 23:43:54 »

Please allow my pre-emptive strike Smiley

http://www.java-gaming.org/topics/faq-cannot-find-the-resource-file/33226/view.html

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline danieldean

Senior Member


Medals: 5
Projects: 1



« Reply #8 - Posted 2014-07-09 00:08:35 »


Fair point. Last time I did this I just used the default package. In this case assuming 'res' is the package folder and spritesheets the package "/spritesheets/font.png" would appear to be what is actually needed. Or at least it was in my dummy. Nice utility by the way. I'm sure that'll come in handy...  Cheesy
Offline bstrauch24

Junior Newbie


Exp: 2 years



« Reply #9 - Posted 2014-07-09 00:27:20 »

Thank you everyone for the help. After this addition, there is a slight 2 second lag during startup, but the game seems to be running fine.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!