Garmaine Staff asked 1 year ago

My task is to write a program that makes a circle ball that gradually fades away as the ball moves to the right. But it's not working, I can make the ball move when the mouse is dragged but the opacity is the same. Can you guys help me? I don't know how to convert the opacity value into double

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.scene.paint.Color;

public class Project3 extends Application
{
   public static void main(String[] args) {
      launch(args);
   }
   public void start(Stage primaryStage) {
      Pane root = createRootPane();
      Scene scene1 = new Scene(root);
      primaryStage.setScene(scene1);
      primaryStage.setTitle(" Hai Vo ");
      primaryStage.show();
   }
   public Pane createRootPane()
   {
      Circle ball = new Circle (100,50,25);
      Pane root = new Pane(ball);
      root.setMinSize(300,300); 
      root.setOnMouseDragged (
       event ->
       {
         double x = event.getX();
         ball.setCenterX(event.getX());
         ball.setCenterY(event.getY());
         ball.opacityProperty().bind(ball.centerXProperty());
         double opacity = ball.opacityProperty();
         ball.setOpacity(opacity);
       } );
       return root;   
   }
}