Link to home
Start Free TrialLog in
Avatar of bombboyer
bombboyer

asked on

Putting a JPEG in a JFrame form

I've written a basic JFrame form, and I want to put a small JPEG image on/in it to "jazz it up". How?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bombboyer
bombboyer

ASKER

Where do I specify the path to the image in your code "objects"? Also, when I compile it, will the JPEG be incorporated into the .exe, or will I have to distribute the picture with my program?
you can load the image using the Toolkit getImage method.

Image i = Toolkit.getDefaultToolkit().getImage(imageurl);

Java doesn't produce an exe (though there are 3rd party products that provide varying levels of support for generating an exe, but thats a different story), you will need to distrubute the image with you program. You can get the url from your application jar (or classpath) for the image using:

URL imageurl = getClass().getResource(imagename);

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-- Split between objects and CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TimYates
EE Cleanup Volunteer