I recently started learning java and am trying to make a simple GUI program that takes in a location of an image and then displays the it.

What would be the best way to do this??

haha i saw that tuturial using google earlier today. However i didnt really understand how the code it gives you works (yes i read the descriptions)

To load an image (which is the part i dont quite get) it gives you the following code:

try {
URL url = new URL(getCodeBase(), "strawberry.jpg");
img = ImageIO.read(url);
} catch (IOException e) {
}

if the folder the image is in is (C:\Users\General Use\Pictures) and the name of the file is "0118080951" where do these things go in the above code? i thought the C:\Users\General Use\Pictures would go in the URL place but i tried that and it didnt work

URLs, unless what I've grown up knowing and loving is no longer sacred, point to resources on the interwebzzzz

img = ImageIO.read(new File("C:\\Users\\General Use\\Pictures\\0118080951"));

should work fine.

never mind i figured out my problem... forgot the .jpg at the end of the file name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.