JPanel error - J Component cannot be resolved

I have JRE System Library JRE 1.8.x An error occurs here with my lines.

Error: The type javax.swing.JComponent could not be resolved. This indirectly refers to the required .class files

How do I remove this error? Here is a screenshot: http://i60.tinypic.com/15z1n2h.png

enter image description here

Tell me the steps. I am new to Java. Thanks in advance.

... , Package Snake ** Class RenderPanel

package snake;
import javax.swing.JPanel;
import java.awt.Graphics;
import javax.swing.JComponent;

@SuppressWarnings("serial")
public class RenderPanel extends JPanel{
    protected void paintComponent(Graphics g){
        super.paintComponent(g);
    }
}

      

Snake class

package snake;
import javax.swing.JFrame;
import java.awt.Toolkit;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JComponent;

public class Snake {

    public JFrame jframe; 

    public Toolkit toolkit;

    public static Snake snake;

    public Snake() {
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        toolkit = Toolkit.getDefaultToolkit();
        jframe = new JFrame("Snake");
        jframe.setVisible(true);
        jframe.setSize(800,700);
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jframe.setLocation(dim.width / 2 - jframe.getWidth() / 2, dim.height / 2 - jframe.getHeight() / 2);
    }

    public static void main(String[] args)
    {
        snake = new Snake();
    }
}

      

+3


source to share


1 answer


You need to "import" the classes in each file in order to use them.

You imported JPanel

, but not JComponent

.



Below your import line, JPanel

add another that looks the same but has JComponent

a instead of JPanel

.

+1


source







All Articles