想编个五子棋的游戏。
为清晰起见,我把“开始游戏”“重新开始”等按钮放在面板“Control”里了,棋盘和棋子则在面板“Board”里绘制。
现在想按下Control面板中的“重新开始”,对Board面板里绘制的棋子清空(repaint(),只绘棋盘)。但repaint()不是静态方法,不能在静态方法里调用。不知怎样可以让按钮(actionPerformed方法)对另一个面板起作用,让它重绘?
如果对另一个面板的其他字段或方法起作用,比较容易实现,通过参数的改变再用repaint重绘。但要控制repaint这个方法怎么办?public class Control extends JPanel implements ActionListener{……public void actionPerformed(ActionEvent e) {if(e.getActionCommand() == "restart")
{
……
}
}=================public class Cover extends JPanel implements MouseListener{public void paintComponent(Graphics g){}}