我正在制作一个游戏,我必须在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不可见。
添加回答
举报
0/150
提交
取消