title: Change colors using one button javafx
body: <p>How should I use my Buttons(red and blue). </p>
  
  <p>Got four buttons on my pane. Two of them to draw the shapes circle and square on to the pane, and two to color them with either red or blue. </p>
  
  <p>I want the color Buttons to only paint the last shape Button(Circle1 or Square) I clicked on. </p>
  
  <p>Any suggestions?</p>
  
  <pre><code>
      public void start(Stage primaryStage) {
  
  
          HBox hBox = new HBox();
          Button circle = new Button("Circle");
          Button square = new Button("Square");
          Button red = new Button("Red");
          Button blue = new Button("Blue");
          hBox.getChildren().addAll(circle, square, red, blue);
  
          Rectangle Square = new Rectangle();
          square.setOnAction(e -&gt; {
              Square.setX(200);
              Square.setY(200);
              Square.setHeight(75);
              Square.setWidth(75);
          });
  
          Circle Circle1 = new Circle();
          red.setOnAction(e -&gt; {
              Square.setFill(Color.RED);
              Circle1.setFill(Color.RED);
          });
  
          blue.setOnAction(e -&gt; {
              Square.setFill(Color.BLUE);
              Circle1.setFill(Color.BLUE);
          });
  
          circle.setOnAction(e -&gt; {
              Circle1.setCenterX(100);
              Circle1.setCenterY(100);
              Circle1.setRadius(45);
          });
  
          BorderPane borderPane = new BorderPane();
          borderPane.getChildren().addAll(Square, Circle1, hBox);
  
          Scene scene = new Scene(borderPane, 600, 500);
          primaryStage.setTitle("ShowBorderPane");
          primaryStage.setScene(scene);
          primaryStage.show();
  
      }
  
  }
  
  </code></pre>