3

I've library of JRE System Library JRE 1.8.x Here an error goes with my lines.

Error: The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files

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

enter image description here

Kindly tell me 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);
    }
}

Class Snake

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();
    }
}
12

1 Answer 1

1

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

You have imported JPanel but not JComponent.

Under your import JPanel line add another one that looks the same but has JComponent at the end instead of JPanel.

3
  • how to import classes in each file Sir? Apr 27, 2015 at 16:58
  • @DavidStevenson you go to each class and do the import as TimB said.
    – Frakcool
    Apr 27, 2015 at 17:01
  • I edited question. Please review, i mentioned classes. thanks Apr 27, 2015 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.