Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Image Filename - Relative Location

807603Nov 13 2007 — edited Nov 13 2007
Hi, I am a pretty new programmer, and ran into a situation where I feel pretty stuck. I have a program that involves putting an image on the screen. Currently, I have a static filename: "C:/Program Files..." I want to be able to move a folder with my program and the image around onto multiple computers, but I don't want to have to change the filename every time I do so. Imagine that my the java file is in the same folder as the picture. Is there a method I can call to retrieve the location of file I am running? (If it matters, it is an application)

Please let me know if there is any more information i need to provide.

Thanks in advance for any help you can give.

private class MainPanel extends JPanel {
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2D = (Graphics2D)g;
		Image i = Toolkit.getDefaultToolkit().getImage("C:/Program Files/Folder/Picture.jpg");
		g2D.drawImage(i, 100, 210, this);}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2007
Added on Nov 13 2007
1 comment
111 views