문제

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 the paintComponent() method in the default super class which is Object and there is no paintComponent() method there.

public class myClass extends JPanel {
    ...
}

다른 팁

Your call to super.paintComponent(g) is looking for a paintComponent() method from the super class. It's probably because you're trying to use this method in a class that is not a subclass of JComponent, which is the class with the paintComponent() method. See JComponent.

More than likely, you want to make your class a subclass of JPanel, or any other class that is a subclass of JComponent

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top