首页下载资源后端Java FX 数据绑定demo

ZIPJava FX 数据绑定demo

weixin_520192864.55KB需要积分:1

资源文件列表:

BindingDemon.zip 大约有15个文件
  1. BindingDemon/pom.xml 2.82KB
  2. BindingDemon/src/
  3. BindingDemon/src/main/
  4. BindingDemon/src/main/java/
  5. BindingDemon/src/main/java/com/
  6. BindingDemon/src/main/java/com/example/
  7. BindingDemon/src/main/java/com/example/bindingdemon/
  8. BindingDemon/src/main/java/com/example/bindingdemon/HelloApplication.java 630B
  9. BindingDemon/src/main/java/com/example/bindingdemon/HelloController.java 1.57KB
  10. BindingDemon/src/main/java/module-info.java 182B
  11. BindingDemon/src/main/resources/
  12. BindingDemon/src/main/resources/com/
  13. BindingDemon/src/main/resources/com/example/
  14. BindingDemon/src/main/resources/com/example/bindingdemon/
  15. 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); } }
100+评论
captcha