标签:ext1 throw 是你 制作 over exception ati col group
JavaFX制作鼠标双击或者多击事件需要用到getClickCount()方法,这个方法需要添加addEventHandler()方法,addEventHandler()是事件方法。
1 scene.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
2
3 @Override
4 public void handle(MouseEvent event) {
5 int times=event.getClickCount();
6 if(times==2) {
7 System.out.println("2次");
8 }
9 }
10 });
1 package text1;
2
3 import javafx.application.Application;
4 import javafx.event.EventHandler;
5 import javafx.scene.Group;
6 import javafx.scene.Scene;
7 import javafx.scene.input.MouseEvent;
8 import javafx.stage.Stage;
9
10 public class Main extends Application {
11
12 @Override
13 public void start(Stage stage) throws Exception {
14 Group root=new Group();
15 Scene scene=new Scene(root);
16 stage.setWidth(500);
17 scene.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
18
19 @Override
20 public void handle(MouseEvent event) {
21 int times=event.getClickCount();
22 if(times==2) {
23 System.out.println("2次");
24 }
25 }
26 });
27 stage.setScene(scene);
28 stage.show();
29 }
30
31 public static void main(String[] args) {
32 launch(args);
33 }
34
35 }
标签:ext1 throw 是你 制作 over exception ati col group
原文地址:https://www.cnblogs.com/modulecode/p/12079392.html