Adding mouse event to Arc : Arc « JavaFX « Java






Adding mouse event to Arc

  

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcBuilder;
import javafx.scene.shape.ArcType;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }
    @Override
    public void start(Stage primaryStage) {
        Group root = new Group();
        Scene scene = new Scene(root, 551, 400, Color.BLACK);
        Group buttonGroup = new Group();
        
        Arc leftButton = ArcBuilder.create()
                .type(ArcType.ROUND)
                .centerX(12)
                .centerY(16)
                .radiusX(15)
                .radiusY(15)
                .startAngle(-30)
                .length(60)
                .fill(new Color(1,1,1, .90))
                .build();
        
        leftButton.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
            public void handle(MouseEvent me) {                
              System.out.println("left");
            }
        });
        buttonGroup.getChildren().add(leftButton);
        root.getChildren().add(buttonGroup);
        
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

   
    
  








Related examples in the same category

1.Arc is centered around 50,50, has a radius of 25 and extends from the angle 45 to the angle 315 (270 degrees long)