What's Wrong WIth My Code involving JFrames

一笑奈何 提交于 2019-12-02 19:44:08

问题


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

Here is my Code:

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.


回答1:


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

i.e.,

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.

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



来源:https://stackoverflow.com/questions/21355547/whats-wrong-with-my-code-involving-jframes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!