Java 我试图在Eclipse环境中的JFrame中将.jpg导入到我的JPanel的后台。谁能告诉我我';我做错了吗?

Java 我试图在Eclipse环境中的JFrame中将.jpg导入到我的JPanel的后台。谁能告诉我我';我做错了吗?,java,jframe,jpanel,jpeg,Java,Jframe,Jpanel,Jpeg,我唯一看到的是它应该是 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.io.*; import java.util.*; import java.lang.String; public class Game extends JFrame { public IntroPanel introduction; p

我唯一看到的是它应该是

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;    
import java.io.*;
import java.util.*;
import java.lang.String;

public class Game extends JFrame
{
    public IntroPanel introduction;
    public InstructPanel instructions;
    public GamePanel gameboard;
    public ScorePanel highscore;
    public QuestionPanel questions;
    public AnswerPanel right;
    public FailPanel wrong;
    public Container c;
    public CardLayout cards;
    private boolean runStandAlone = true;

    public static void main (String [] args)
    {
        Game gem = new Game();
    }

    public Game()
    {
        setVisible(true); // allows JFrame to be seen
        setSize(800, 800); // sets the size
        setTitle("Biopardy"); // sets the title
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); // Closing is taken care of 
        // by the following WindowListener, there's no default close operation.
        addWindowListener(new WindowAdapter() 
        { // lets the program run without having to import all WindowListener methods
            public void windowClosing(WindowEvent evt) 
            { // this gives the user a chance to stop the close operation
                int response = JOptionPane.showConfirmDialog(null, "Do you really want to quit?");
                if(response == JOptionPane.YES_OPTION) 
                {
                    dispose();
                    if(runStandAlone)
                        System.exit(0);
                }
            }
        });

        c = this.getContentPane();
        cards = new CardLayout();
        c.setLayout(cards);

        introduction = new IntroPanel(); // initializes new panel
        add(introduction, BorderLayout.CENTER); // adds the panel to the center

        instructions = new InstructPanel(); // initializes new panel
        c.add(instructions, "Instructions"); // string identifier (call on panel by using this name)

        gameboard = new GamePanel(); // initializes new panel
        c.add(gameboard, "Start"); // string identifier (call on panel by using this name)

        highscore = new ScorePanel(); // initializes new panel
        c.add(highscore, "High Score"); // string identifier (call on panel by using this name)

        questions = new QuestionPanel(); // initializes new panel

        right = new AnswerPanel(); // initializes new panel

        wrong = new FailPanel(); // initializes new panel
    }

class IntroPanel extends JPanel implements ActionListener
{
    private JButton start, record, instruct;
    private JTextField username;
    private Image jeopardy;

    public IntroPanel(Image jeopardy)
    {
        setBackground(Color.white); // sets background color
        this.setLayout(new FlowLayout());

        this.jeopardy = Toolkit.getDefaultToolkit().getImage("jeopardy.jpg");

        start = new JButton("Start");
        start.addActionListener(this);
        this.add(start);

        instruct = new JButton("Instructions");
        instruct.addActionListener(this);
        this.add(instruct);

        record = new JButton("High Score");
        record.addActionListener(this);
        this.add(record);

        username = new JTextField("User Name");
        username.addActionListener(this);
        this.add(username);
    }

    public void actionPerformed(ActionEvent e)
    {
        String command = e.getActionCommand();
        if(command.equals("Start"))
            cards.show(c, "Start");
        else if(command.equals("Instructions"))
            cards.show(c, "Instructions");
        else if(command.equals("High Score"))
            cards.show(c, "High Score");
    }

    public void WaitForImage(JApplet component, Image image)   
    {
        MediaTracker tracker = new MediaTracker(component);
        try 
        {
            tracker.addImage(image, 0);
            tracker.waitForID(0);
        }
        catch(InterruptedException evt)  
        {
            evt.printStackTrace();   
        }
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.drawImage(jeopardy, 0, 0, null);
    }
}
您只需设置方法变量


编辑:您还调用了空构造函数。确保为面板调用正确的构造函数。

thynoob,欢迎使用SO。您已经发布了我们认为是一个很差的问题:一个巨大的代码块,没有对问题的描述,也没有错误消息。请把更多的精力放在你的问题上,考虑到这些要点,并阅读以下内容:哦,对不起,代码块太大了……我将把它删掉可能不是真的。我已经添加了这个。在初始化变量jeopardy之前,我的编译器仍然存在一个问题,即构造函数Game.IntroPanel()未定义。我不太清楚这意味着什么…请仔细查看您的代码,并将其与编译器错误消息进行比较。提示:您的IntroPanel类有多少个构造函数,它们的参数是什么?
this.jeopardy = Toolkit.getDefaultToolkit().getImage("jeopardy.jpg");