我如何让这个JPanel坐在我的背景图像上?

时间:2014-04-16 22:29:54

标签: java jpanel jbutton

我正在尝试在我设置的背景图像上绘制mainPanel,这样即使面板启动,您仍然可以看到图像。 setOpaque似乎不起作用。此外,我将在Galaga超级班级中切换所有面板,所以我希望所有面板都采用相同的方式。

public class Galaga extends JFrame {
    private static final long serialVersionUID = 1L;

    private JPanel mainPanel;//main menu with top-level button
    private JPanel optionsPanel; //has option buttons and detail
    private JPanel highScorePanel; //shows high scores
    public BufferedImage image;

    public Galaga(String t) {
        super(t);

        JLayeredPane pane = this.getLayeredPane();
        File img = new File("images/Spacebackground.png");
        try {
            image = ImageIO.read(img);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }

        mainPanel = new MainPanel(this);
        mainPanel.setOpaque(false);
        mainPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        add(mainPanel, BorderLayout.CENTER);//adds main panel
        }//ends Galaga function

0 个答案:

没有答案