我有两个按钮: buttonPoint1 以及 buttonPoint2 .当我单击其中一个按钮时,它将调用此按钮的操作方法。在这个函数中,我希望程序等待我点击屏幕上的任何地方。那我就给你打电话 MouseInfo.getPointerInfo().getLocation() .当我在应用程序窗口外(例如在其他窗口)单击时,我会失去对应用程序的关注。如何使程序等待点击,不隐藏,失去焦点,给我的回应,我点击?
buttonPoint1
buttonPoint2
MouseInfo.getPointerInfo().getLocation()
hgtggwj01#
一个想法是使用这样一个透明的窗口
public class Main extends Application { @Override public void start(Stage primaryStage) { VBox vBox = new VBox(new Label("IMAGINE A BEAUTIFUL APPLICATION HERE")); vBox.setAlignment(Pos.CENTER); Button button = new Button("Im gonna steal your next click"); button.setOnAction(event -> { System.out.println("Firing Button Action"); openTransparentWindow(); System.out.println("Button Action Finished Firing"); }); vBox.getChildren().add(button); Scene scene = new Scene(vBox, 300, 150); primaryStage.setScene(scene); primaryStage.show(); } private void openTransparentWindow(){ VBox vBox = new VBox(); Stage stage = new Stage(); stage.setScene(new Scene(vBox)); //stage.setOpacity(0.5f); //Uncomment if you want to test and see the stage stage.setOpacity(0f); stage.setMaximized(true); vBox.setOnMouseClicked(event ->{ System.out.println("event.getX() = " + event.getX()); System.out.println("event.getY() = " + event.getY()); System.out.println("event.getScreenX() = " + event.getScreenX()); System.out.println("event.getScreenY() = " + event.getScreenY()); stage.close(); }); stage.showAndWait(); } }
1条答案
按热度按时间hgtggwj01#
一个想法是使用这样一个透明的窗口