솔루션 모양의 각각에
를, 마우스 입력 및 종료 이벤트를 잡을 마우스가 끝난 모양의 인덱스를 기록하는 setOnMouseEntered 및 setOnMouseExited 핸들러를 제공합니다.
가정
난 당신이 커서 핫스팟을 교차 할 필요가 가정 커서 모양 또는 핫스팟의 교차점으로 커서의 직사각형 경계 (표준 방식합니다 (마우스 포인터 화살표의 팁 등)이 아니라을이다 그 커서가 작동합니다).
샘플 응용 프로그램 출력
![mouseover](https://i.stack.imgur.com/zG7x8.png)
- 당신은 원 이상 마우스, 원이 강조되고 원의 인덱스 (1)
- 표시됩니다 때 때 사각형을 통해 당신은 마우스 , 사각형이 강조 표시되고 사각형의 색인 (2)이 표시됩니다.
- 두 모양 중 하나에 마우스를 올려 놓지 않으면 모양이 강조 표시되지 않고 색인이 표시되지 않습니다.
샘플 코드 내가 생각하고 내가 필요 단지 무엇보다
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;
public class ShapeIntersector extends Application {
private static final Shape[] shapes = {
new Circle(50, Color.AQUAMARINE),
new Rectangle(100, 100, Color.PALEGREEN)
};
private static final DropShadow highlight =
new DropShadow(20, Color.GOLDENROD);
@Override
public void start(Stage stage) throws Exception {
HBox layout = new HBox(40);
layout.setPadding(new Insets(30));
layout.setAlignment(Pos.CENTER);
Label highlightedShapeLabel = new Label(" ");
highlightedShapeLabel.setStyle(
"-fx-font-family: monospace; -fx-font-size: 80px; -fx-text-fill: olive"
);
for (Shape shape: shapes) {
layout.getChildren().add(shape);
shape.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
shape.setEffect(highlight);
int idx = layout.getChildren().indexOf(shape) + 1;
highlightedShapeLabel.setText(
"" + idx
);
}
});
shape.setOnMouseExited(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
shape.setEffect(null);
highlightedShapeLabel.setText(" ");
}
});
}
layout.getChildren().add(highlightedShapeLabel);
stage.setScene(new Scene(layout));
stage.show();
}
public static void main(String[] args) { launch(args); }
}
간단한. 감사 ! :디 – Adorjan