package corejava; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; public class Java2DImage extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; Image image = new ImageIcon( "E:/ankit_tutorial/java/beautiful-nature-photographs.jpeg") .getImage(); g2d.drawImage(image, 0, 0, null); } public static void main(String[] args) { Java2DImage image = new Java2DImage(); JFrame frame = new JFrame("Java2D Image"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(image); frame.setSize(380, 320); frame.setLocationRelativeTo(null); frame.setVisible(true); } }