JPanel错误-无法解析J组件 [英] JPanel error - J Component cannot be resolved

查看:403
本文介绍了JPanel错误-无法解析J组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有JRE系统库JRE 1.8.x库 我的台词出现了错误.

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

错误:无法解析类型javax.swing.JComponent.从所需的.class文件间接引用

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

如何清除此错误?这是屏幕截图: http://i60.tinypic.com/15z1n2h.png

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

请告诉我步骤.我是Java新手.预先感谢.

Kindly tell me steps. I am new to Java. Thanks in advance.

. . 包装蛇 ** Class RenderPanel

. . 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);
    }
}

蛇类

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

推荐答案

您需要在每个文件中导入"类才能使用它们.

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

您已导入JPanel,但未导入JComponent.

在您的导入JPanel行下,添加另一行看起来相同但末尾带有JComponent的行,而不是JPanel.

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

这篇关于JPanel错误-无法解析J组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆