質問

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