在Java中,有个方法是鼠标的监听事件,MouseEvent,有很多静态的 方法,比如点击,按下,或者释放事件,可以在软件的窗体上加一个鼠标监听,记录下点击数量就可以了,
package test;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class javafxText1 extends Application {
static int num = 0;
@Override
public void start(Stage primaryStage) throws Exception {
AnchorPane anchorPane = new AnchorPane();
Label label = new Label();
label.setPrefSize(300,50);
label.setText("鼠标点击次数:\t"+num);
anchorPane.addEventHandler(MouseEvent.MOUSE_CLICKED,