Basically i have this code
ImageIcon image = new ImageIcon(this.getClass().getResource("http://i.imgur.com/UKmK7j0.jpg")); //Image is just an example
public void paintComponent(Graphics g) {
super.paintComponent(g);
image.paintIcon(null, g, x, y);
}
but it tells me
"The method paintComponent(Graphics) is undefined for the type Object"
What am i doing wrong?? Please help me
This is most likely because you are not extending the correct class. You need to extend
JPanel
or any other class that contains it in order to call this super class. Right now it is looking for thepaintComponent()
method in the default super class which isObject
and there is nopaintComponent()
method there.