i am new to Java . i was just trying to load image as background in JFrame
. What i wanted to do is get the image from C Drive(that is not my workspace) so what i did in Board.java
:
ImageIcon i = new ImageIcon("C:/image.png");
img =i.getImage();
and did try to paint it something like this:
public void paint(Graphics g )
{
super.paint(g);
Graphics2D g2d= (Graphics2D) g;
g2d.drawImage(img, 0, 100, null);
}
And then i am calling in my main class like this
public static void main(String[] args)
{
JFrame frame= new JFrame(" Game") ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200, 365);
frame.setVisible(true);
frame.add(new Board());
}
but i am not getting any image displayed , so is it legal way to add Image
?