CircleListener 是我面板类中的一个内部类,它现在涉及 MouseListener 接口。MouseRelased 方法检查单击的区域是否被圆圈包围,如果是,则将该形状设置为选中并删除选中的形状。
现在我需要一个 ActionListener 使用“计时器”对象向这个面板添加随机大小的圆圈。问题:是否可以为 CircleListener 实现“ActionListener”或者为“ActionListener”创建另一个内部类更好?
提前致谢
private class CircleListener implements MouseListener
{
ShapesCanvas canvas;
ShapeContainer container;
Shape possibleShape;
private CircleListener(ShapesCanvas canv, ShapeContainer cont)
{
this.canvas = canv;
this.container = cont;
}
public void MouseRelased (MouseEvent e)
{
possibleShape = container.contains( e.getX(), e.getY());
if( possibleShape != null)
{
( (Selectable)possibleShape).setSelected(true);
container.removeSelected();
}
canvas.repaint(); //repaints the last situation
}