Radix
Radix

Reputation: 3657

Display Image from Server in Java

I am new in Java programming. My query is that I am having an image which is present on a server and I want to display that image inside the JFrame. I tried using the Image class but that seems to be not working.

Please Note: I don't want to use applets for this, so is there some other method by which this can be done?

Thanks & Regards,

Upvotes: 0

Views: 2357

Answers (1)

BalusC
BalusC

Reputation: 1109132

Assuming that it's a public accessible webserver, you can use URL#openStream() to get an InputStream out of an URL.

InputStream input = new URL("http://example.com/image.png").openStream();

Then you can just create the BufferedImage with help of ImageIO#read() the usual way.

BufferedImage image = ImageIO.read(input);
// ...

Upvotes: 4

Related Questions