List 删除形状后。。我不能再旋转了JavaFX

List 删除形状后。。我不能再旋转了JavaFX,list,javafx,rotation,nodes,shapes,List,Javafx,Rotation,Nodes,Shapes,我目前有一个程序,我可以添加矩形的场景。可以选择、旋转、调整大小和删除这些对象。如果我在一个矩形上选择并单击“旋转”,则它可以工作;如果我添加另一个矩形并单击“旋转”,则它仍然可以工作。但是,如果我“删除”了其中一个矩形,那么我就不能再旋转另一个或任何其他添加的矩形 我有以下字段和两种方法: private List<Node> selectedShapes = new ArrayList<>(); private double angle[] = {0}; @FXML

我目前有一个程序,我可以添加矩形的场景。可以选择、旋转、调整大小和删除这些对象。如果我在一个矩形上选择并单击“旋转”,则它可以工作;如果我添加另一个矩形并单击“旋转”,则它仍然可以工作。但是,如果我“删除”了其中一个矩形,那么我就不能再旋转另一个或任何其他添加的矩形

我有以下字段和两种方法:

private List<Node> selectedShapes = new ArrayList<>();
private double angle[] = {0};

@FXML
private AnchorPane container2;
删除

 public void deleteButton(ActionEvent e) {
    deletebutton.setOnAction(a -> container2.getChildren().removeAll(selectedShapes));
    selectedShapes.remove(0);
}

我觉得我选择或删除所选形状的方式不正确。有人能告诉我选择当前商品的正确方法吗。因此,如果我删除其中一个矩形,另一个应该仍然可以旋转。谢谢

您想要创建一个矩形列表,因此与其遍历基类
节点
为什么不直接使用矩形/形状列表:

List<Shape> selectedShapes = new ArrayList<>();
最后,要在列表中找到自己,请使用递增(添加时)和递减(删除时)的int:

编辑: 以下是组织项目时可以遵循的简单方法:

private List<Rectangle> recs = new ArrayList<>();
private final double width = 50, height = 50;
private final double x = 200, y = 200;


public void add(){

    recs.add(new Rectangle(x, y, width, height));
    /*Properties of your rectangle (fill,shape...)*/

}

public void delete(int deleteIndex){

    /*Here the root is the container of your Rectangles*/
    root.getChildren().remove(recs.get(deleteIndex));
    recs.remove(deleteIndex);

}

public void rotate(int recIndex, double angle){

    recs.get(recIndex).setRotate(recs.get(recIndex).getRotate()+angle);

}
private List recs=new ArrayList();
私人最终双倍宽度=50,高度=50;
私人最终双x=200,y=200;
公共无效添加(){
记录添加(新矩形(x,y,宽度,高度));
/*矩形的属性(填充、形状…)*/
}
公共void delete(int deleteIndex){
/*这里的根是矩形的容器*/
root.getChildren().remove(recs.get(deleteIndex));
记录删除(删除索引);
}
公共空间旋转(内部循环,双角度){
recs.get(recIndex).setRotate(recs.get(recIndex).getRotate()+角度);
}

祝你好运

嘿,谢谢你的回复。那么,我将如何在我的rotate/delete方法中编写这个。谢谢,我只是使用了你的删除方法,这正是我想要的!非常感谢你,波!
List<Double> angle = new ArrayList<>();
int Index = 0;
private List<Rectangle> recs = new ArrayList<>();
private final double width = 50, height = 50;
private final double x = 200, y = 200;


public void add(){

    recs.add(new Rectangle(x, y, width, height));
    /*Properties of your rectangle (fill,shape...)*/

}

public void delete(int deleteIndex){

    /*Here the root is the container of your Rectangles*/
    root.getChildren().remove(recs.get(deleteIndex));
    recs.remove(deleteIndex);

}

public void rotate(int recIndex, double angle){

    recs.get(recIndex).setRotate(recs.get(recIndex).getRotate()+angle);

}