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??
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??
With Google.
April Fools!
Read this tutorial, I think it is what you are looking for. And I also think I linked someone to it maybe a day ago. http://java.sun.com/docs/books/tutorial/2d/images/index.html
Here's another option as well, using ImageIcon and JLabel:
http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html
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.
ok thank you
never mind i figured out my problem... forgot the .jpg at the end of the file name.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.