ProgressIndicator是JavaFX包的一部分。它是一个循环控件,用于指示进度,可以是无限的,也可以是有限的。通常与任务API一起使用,用于表示后台任务的进度。它通常显示任务的完成量。
null
类的构造函数是
- ProgressIndicator() :创建一个新的中间进度指示器。
- 进度指示器(双p) :创建具有指定进度的进度指示器
常用方法
方法 | 解释 |
---|---|
isIndeterminate() | 获取不确定属性的值。 |
getProgress() | 获取属性progress的值。 |
setProgress(双v) | 设置属性progress的值 |
以下程序说明了进度指标的使用:
创建进度指示器的程序: 该程序创建一个由名称指示的进度指示器 PB 。进度指示器将在场景中创建,而场景又将在舞台中托管。函数setTitle()用于为舞台提供标题。然后创建一个平铺窗格,在该窗格上调用addChildren()方法,将进度指示器和按钮附加到场景中。最后调用show()方法来显示最终结果。
// Java program to illustrate the use of Progress Indicator import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import java.io.*; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.control.Label; import javafx.stage.Stage; import java.net.*; public class progressi extends Application { static double ii = 0 ; // launch the application public void start(Stage s) throws Exception { // set title for the stage s.setTitle( "creating progressIndicator" ); // create a progress indicator ProgressIndicator pb = new ProgressIndicator(); // create a tile pane TilePane r = new TilePane(); // action event EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { // set progress to different level of progressindicator ii += 0.1 ; pb.setProgress(ii); } }; // creating button Button b = new Button( "increase" ); // set on action b.setOnAction(event); // add button r.getChildren().add(pb); r.getChildren().add(b); // create a scene Scene sc = new Scene(r, 200 , 200 ); // set the scene s.setScene(sc); s.show(); } public static void main(String args[]) { // launch the application launch(args); } } |
输出:
笔记 :以下程序可能无法在联机IDE中运行。请使用脱机编译器。 参考: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ProgressIndicator.html
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END