Create ProgressBar in JavaFX
________________________________________________
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.util.Duration;
public class JavaFXProgressBar extends Application{
Double a = 0.0;
@Override
public void start(Stage stage) {
GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
ProgressBar pBar = new ProgressBar();
EventHandler<ActionEvent> eventHandler = e ->{
a+=0.1;
pBar.setProgress(a);
};
Timeline animation = new Timeline(new KeyFrame(Duration.seconds(0.1), eventHandler));
animation.setCycleCount(Timeline.INDEFINITE);
Button btn = new Button("Start");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
animation.play();
}
});
pane.add(pBar, 0, 0);
pane.add(btn, 0, 1);
Scene scene = new Scene(pane, 250, 250);
stage.setTitle("JavaFX ProgressBar");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
_____________________________________________
Dark Hers
YouTube
https://instagram.com/darkhers
https://www.facebook.com/darkhers
TikTok
https://www.tiktok.com/@darkhers
https://www.pinterest.co.uk/darkhers
Comments
Post a Comment