Question
I have been given the following code to create a progress bar and it needs to be adjusted to run on NetBeans import javafx.application.Application; import
I have been given the following code to create a progress bar and it needs to be adjusted to run on NetBeans
import javafx.application.Application; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.Scene;
//Import for the progress bar. import javafx.scene.control.ProgressBar;
//Import for the progress indicator. import javafx.scene.control.ProgressIndicator;
//Labels and buttons. import javafx.scene.control.Label; import javafx.scene.control.Button;
//Imports for layout. import javafx.scene.layout.GridPane;
/** * * @author Anita Murphy */
public class Progress2 extends Application { //Declare a progress bar. ProgressBar progBar;
//Declare a progress indicator. ProgressIndicator progIndicator;
//Labels Label lblProgress;
//Buttons Button btnIncrease, btnDecrease;
public void init(){
//Create a progress bar. 1.0 is full scale. Give it 0. progBar = new ProgressBar(0);
//Construct a progress indicator. progIndicator = new ProgressIndicator(0);
//Construct labels and buttons. lblProgress = new Label("Progress:"); btnIncrease = new Button("Increase"); btnDecrease = new Button("Decrease");
//Set preferred widths for the buttons. btnIncrease.setPrefWidth(70); btnDecrease.setPrefWidth(70);
//Set the preferred width of the progress bar. progBar.setPrefWidth(300);
//Set a style. Show a green progress bar. progBar.setStyle("-fx-accent: green;");
//Handle events on the increase button. btnIncrease.setOnAction(ae -> {
//Get the current progress. double progValue = progBar.progressProperty().get();
//Increase it by 0.05. progValue = progValue + 0.05; if(progValue >= 0.7){
//Set a style. Show a green progress bar. progBar.setStyle("-fx-accent: red;"); progIndicator.setStyle("-fx-accent: red;"); }//if else { //Set a style. Show a green progress bar. progBar.setStyle("-fx-accent: green;"); progIndicator.setStyle("-fx-accent: green;"); }//else
//Don't let the progress bar or indicator go off scale. if(progValue < 0.95){
//Set the new (increased) progress. progBar.setProgress(progValue);
//Set the progress indicator. progIndicator.setProgress(progValue); } else{ progValue = 1; progBar.setProgress(progValue); progIndicator.setProgress(progValue); }//else });
@Override public void start(Stage primaryStage) throws Exception {
//Set the title. primaryStage.setTitle("Progress Bar 2");
//Create a gridpane. GridPane gp = new GridPane();
//Set the hgap, vgap and padding. gp.setHgap(10); gp.setVgap(15); gp.setPadding(new Insets(10));
//Add the controls to the gridpane. gp.add(lblProgress, 0, 0); gp.add(progBar, 1, 0); gp.add(progIndicator, 2, 0); gp.add(btnIncrease, 2, 1); gp.add(btnDecrease, 2, 2);
//Create a scene. Scene scene = new Scene(gp, 470, 150);
//Set the scene. primaryStage.setScene(scene);
//Show the stage. primaryStage.show(); }
//start()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started