How to Display Image in Java


Here you may see how to display an image with drawImage method of an Graphics class in Java.

Source Code

package com.beginner.examples;

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;

public class ImageExample extends Applet
{
	Image img;
	public void init(){		
		img = getImage(null, "file:/D:/Workspaces/img.jpg");
	}
	
	public void paint(Graphics g){
		
		//display image
		g.drawImage(img , 100 , 100 , this);
		System.out.println("ok");
	}
	
}

Output:

ok

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments