下载资源后端资源详情
BindingDemon.zip
大小:4.55KB
价格:12积分
下载量:0
评分:
5.0
上传者:weixin_52019286
更新日期:2024-08-09

Java FX 数据绑定demo

资源文件列表(大概)

文件名
大小
BindingDemon/pom.xml
2.82KB
BindingDemon/src/
-
BindingDemon/src/main/
-
BindingDemon/src/main/java/
-
BindingDemon/src/main/java/com/
-
BindingDemon/src/main/java/com/example/
-
BindingDemon/src/main/java/com/example/bindingdemon/
-
BindingDemon/src/main/java/com/example/bindingdemon/HelloApplication.java
630B
BindingDemon/src/main/java/com/example/bindingdemon/HelloController.java
1.57KB
BindingDemon/src/main/java/module-info.java
182B
BindingDemon/src/main/resources/
-
BindingDemon/src/main/resources/com/
-
BindingDemon/src/main/resources/com/example/
-
BindingDemon/src/main/resources/com/example/bindingdemon/
-
BindingDemon/src/main/resources/com/example/bindingdemon/hello-view.fxml
1.23KB

资源内容介绍

将变化的数据统一抽象为IntegerProperty与圆和进度条进行数据绑定,然后add 和sub只管更改IntergerProperty(),最后实现通过addButon和subButton来控制圆和进度条
package com.example.bindingdemon;import javafx.application.Platform;import javafx.beans.property.IntegerProperty;import javafx.beans.property.SimpleIntegerProperty;import javafx.event.ActionEvent;import javafx.fxml.FXML;import javafx.fxml.Initializable;import javafx.scene.control.Button;import javafx.scene.control.Label;import javafx.scene.control.ProgressBar;import javafx.scene.shape.Arc;import java.net.URL;import java.util.ResourceBundle;public class HelloController implements Initializable { @FXML public Arc arc; @FXML public Label numLabel; @FXML public Button addBtn; @FXML public Button subBtn; @FXML public ProgressBar bar; IntegerProperty integerProperty = new SimpleIntegerProperty(0); @Override public void initialize(URL url, ResourceBundle resourceBundle) { arc.setStartAngle(90); arc.setLength(-0); numLabel.textProperty().bind(integerProperty.asString()); addBtn.disableProperty().bind(integerProperty.greaterThanOrEqualTo(100)); subBtn.disableProperty().bind(integerProperty.lessThanOrEqualTo(0)); integerProperty.addListener((observableValue, number, t1) -> { arc.setStartAngle(90); arc.setLength(-t1.intValue() * 3.6); bar.setProgress(t1.intValue() / 100.0); }); } @FXML public void sub(ActionEvent actionEvent) { integerProperty.set(integerProperty.get() - 10); } @FXML public void add(ActionEvent actionEvent) { integerProperty.set(integerProperty.get() + 10); }}

用户评论 (0)

发表评论

captcha