我尝试通过按 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);
}
}
删除选择
else if (command.equals("Delete Selection")) {
for (Shape s : multiShape)// look for multishape size
shapes.remove(multiShape);
}// remove selectedmultiple object.
最佳答案
应该是
shapes.remove(s);
不是
shapes.remove(multiShape);
您应该传递 shape s
来删除方法,以从形状 ArrayList
中删除 shape s
java.util.ArrayList.remove(Object) // this is the method you are using .
关于java - 无法删除多个选定的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32118131/