猿问

在DrawingComponent上显示JButton

我正在制作一个游戏,我必须在DrawingComponent上绘制与游戏有关的所有内容。现在,我想在DrawingComponent上添加一个“关闭”按钮。


public class SimulationWindow extends JFrame 

{

private static final long serialVersionUID = 1L;


public SimulationWindow()

{

    super("Game");

    setUndecorated(true);

    setExtendedState(JFrame.MAXIMIZED_BOTH); 



    getContentPane().setBackground(Color.BLACK);

    setLocationRelativeTo(null);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    JButton closeButton = new JButton();

    closeButton.addActionListener(new ActionListener()

    {

        @Override

        public void actionPerformed(ActionEvent arg0) {

            Game.close = true;

        }

    });


    add(new DrawingComponent());

    add(closeButton);


    setVisible(true);

}

}


但这只是一个弹出的灰色区域。实质上是游戏的DrawingComponent不可见。


Smart猫小萌
浏览 124回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答