Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How do I export an JLabel image with my game?

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How do I export an JLabel image with my game?

    I made a game where basically, a ball (A JLabel with the icon set to a ball image from my computer) bounces across the screen, and when you click it, the speed increases. When I exported the game, it worked fine on my computer and everything, however I sent it to my friend and because his computer didn't have the path of the ball, the ball didn't show up. So basically what im asking is, how can I get an image to export along with the game?

    Heres the code that set the balls icon image



    ball.setFilePath("C:\\Users\\Nathan\\Documents\\Red Ball.png");
    ball.setIcon(new ImageIcon(ball.getFilePath()));


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,354
    Thanks
    182
    Thanked 832 Times in 775 Posts
    Blog Entries
    5

    Default Re: How do I export an JLabel image with my game?

    Package the image, along with all class files, within a jar file. Then access the image by calling getClass().getResource (take a look at the ImageIcon tutorial at Oracle for details: How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) )

  3. The Following User Says Thank You to copeg For This Useful Post:

    NathanWick (November 20th, 2013)

  4. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How do I export an JLabel image with my game?

    Thank you so much !

Similar Threads

  1. Using a JSlider to change the red contrast of an image on a jLabel
    By Bruz69er in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 22nd, 2012, 01:40 AM
  2. Loop through JLabel and change JLabel
    By JoeBrown in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2012, 01:52 PM
  3. Game Image Layering Help
    By SkyAphid in forum Java Theory & Questions
    Replies: 3
    Last Post: December 31st, 2011, 11:01 PM
  4. Problem changing the image in a JLabel
    By kc120us in forum AWT / Java Swing
    Replies: 1
    Last Post: October 16th, 2011, 11:16 PM
  5. JLabel image?
    By frozen java in forum AWT / Java Swing
    Replies: 2
    Last Post: September 28th, 2011, 08:44 AM

Tags for this Thread