I'm working on a digital Pokemon card-like game. When I try to paint any of my images, the JFrame remains empty. It may be a simple error, but I have not been able to find a solution. On Stack Overflow, I have seen many issues like mine though their solutions don't work on my code. Here's the code: The class for the JFrame:
import javax.swing.JFrame;
public class Rocks extends JFrame{
public Rocks(){
setVisible(true);
setTitle("Rocks Card Game");
setSize(1200,297);
add(new Display());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Rocks();
}
}
The JPanel Class:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class Display extends JPanel{
Image granite;
public Display(){
granite = new ImageIcon("C:\\Users\\Raj\\Pictures\\Granite.png").getImage();
setBackground(Color.black);
}
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(granite,0,0,null);
}
}