关于JAVAFX鼠标单击案例
在javafx中 鼠标单击事件属于ActionEvent,而不属于mouseAction所以说 如果用的ActionEvent则单击没有效果哟
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Action1 extends Application {
int count=0;
Button bt=new Button();
@Override
public void start(Stage primaryStage)
{
HBox hBox=new HBox();
hBox.setAlignment(Pos.TOP_CENTER);
hBox.getChildren().add(bt);
BorderPane pane =new BorderPane();
pane.setBottom(hBox);
bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// TODO Auto-generated method stub
count+=1;
bt.setText("被点击了"+count+"次");
}
});
Scene scene=new Scene(pane);
primaryStage.setTitle("Jframe");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这个案例显示的是会在鼠标单击后显示单击了几次.

博客介绍了JavaFX鼠标单击案例,指出在JavaFX中鼠标单击事件属ActionEvent,用其实现单击无效果,该案例可显示鼠标单击次数。还提及实现双击也需用ActionEvent,要设定延迟时间,双击则运行双击程序,不再运行单击程序。
43

被折叠的 条评论
为什么被折叠?



