我试图通过按SHIFT键选择多个对象,然后右键单击并选择删除选项,它应该能够删除所有选定的对象。
然而,它没有用。
我的代码如下。
鼠标点击
clickShape = null;
int x = clickEvent.getX(); // x-coordinate of point where mouse was
// clicked
int y = clickEvent.getY(); // y-coordinate of point
// when press down shift key
if (clickEvent.isShiftDown()) {
for (int i = 0; i < shapes.size(); i++) {
Shape s = (Shape) shapes.get(i);
if (s.containsPoint(x, y)) {
s.setColor(Color.RED);
multiShape.add(s);
}
}
DeleteSelection
else if (command.equals("Delete Selection")) {
for (Shape s : multiShape)// look for multishape size
shapes.remove(multiShape);
}// remove selectedmultiple object.
答案 0 :(得分:0)
应该是
shapes.remove(s);
不是
shapes.remove(multiShape);
您应该通过shape s
移除方法以从形状shape s
移除ArrayList
java.util.ArrayList.remove(Object) // this is the method you are using .