删除绘制的形状对象

时间:2014-11-05 21:52:23

标签: java swing awt shape graphics2d

我正在尝试使用Shape java内置构建一个简单的绘制,如何从JFrame中删除/删除形状(例如圆圈)?

import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.Polygon;
import java.util.List;

public class Delete extends DrawingPanel {
    List<ShapeItem> shape;
    public Delete(List<ShapeItem> shape){
        this.shape = shape;
    }
    public void deleteShape(){
        for(ShapeItem s : shape){
            if(s.getShape() instanceof Line2D){
                s.setColor(getBackground());
            }
            if(s.getShape() instanceof Ellipse2D){
                s.setColor(getBackground());
            }
            if(s.getShape() instanceof Rectangle2D){
                s.setColor(getBackground());
            }
            if(s.getShape() instanceof Polygon ){
                s.setColor(getBackground());
            }
        }
    }


}

这种方式有效吗?

0 个答案:

没有答案