我的代码涉及JFrames的错误是什么 [英] What's Wrong WIth My Code involving JFrames

查看:158
本文介绍了我的代码涉及JFrames的错误是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给我一​​个错误,说JFrame类型中的方法setContentPane(Container)不适用于参数(GamePanel)

It's Giving me an error saying that "The method setContentPane(Container) in the type JFrame is not applicable for the arguments (GamePanel)"

这是我的代码:

package main;

import javax.swing.JFrame;

public class Game {

public static void main(String[] args){

    JFrame window = new JFrame("Dragon Tales");
    window.setContentPane(new GamePanel());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setResizable(false);
}

}

我正在完全按照教程进行操作他的屏幕显示没有任何错误。

I am following a tutorial exactly and his screen shows no errors at all.

推荐答案

您的GamePanel类不会扩展任何Swing GUI组件,如Container或其中一个儿童。可能它应该扩展JPanel。

Your GamePanel class does not extend any Swing GUI component such as Container or one of its children. Probably it should extend JPanel.

import javax.swing.JPanel;

public class GamePanel extends JPanel {
   // .... etc
}

请不要添加紧急或尽快帮助位。是的,你的问题非常重要,但它并不比其他人重要。

Please don't add the urgent or "help as soon as possible" bit. Yes your question is very important, but it is no more important than anyone else's.

编辑:Mad的链接值得回答: Oracle Swing教程

Mad's link is worth putting in the answer: The Oracle Swing Tutorial.

这篇关于我的代码涉及JFrames的错误是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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