Answered step by step
Verified Expert Solution
Question
1 Approved Answer
help me fix this javafx program: main class: import javafx.application.Application; import javafx.fxml . FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; import java.io . IOException; public
help me fix this javafx program:
main class:
import javafx.application.Application;
import javafx.fxmlFXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.ioIOException;
public class CloudCostMonitor extends Application
@Override
public void startStage stage throws Exception
Parent root
FXMLLoader.loadgetClassgetResourceCloudCostMonitorfxml;
Scene scene new Sceneroot; attach scene graph to scene
stage.setTitleCloud Cost Monitor"; displayed in window's title bar
stage.setScenescene; attach scene to stage
stage.show; display the stage
public static void mainString args
create a TipCalculator object and call its start method
launchargs;
controller class
import javafx.event.ActionEvent;
import javafx.fxmlFXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import java.time.Duration;
import java.time.LocalDate;
public class CloudCostController
@FXML
private TextField costTextField;
@FXML
private TextField monthlyCostTextField;
@FXML
private TextField usageTextField;
@FXML
private TextField alertTextField;
@FXML
private RadioButton dropboxRadioButton;
@FXML
private DatePicker durationDatePicker;
@FXML
private Button enterButton;
@FXML
private RadioButton googleRadioButton;
@FXML
private RadioButton onedriveRadioButton;
@FXML
private ToggleGroup providerGroup;
@FXML
private TextField storageTextField;
private final double DROPBOXRATEPERGB ;
private final double GOOGLERATEPERGB ;
private final double ONEDRIVERATEPERGB ;
private final double STORAGELIMITGB ; Example limit you can change it
@FXML
void initialize
Set today's date as the default for the durationDatePicker
durationDatePicker.setValueLocalDatenow;
Set a default cloud provider as selected. For instance, select Google Drive by default.
googleRadioButton.setSelectedtrue;
Clear all text fields to be cleared or set to a default value at startup:
costTextFieldclear;
monthlyCostTextField.clear;
usageTextField.clear;
alertTextField.clear;
storageTextField.clear;
@FXML
void calculateButtonPressedActionEvent event
LocalDate startDate durationDatePicker.getValue;
LocalDate endDate LocalDate.now; Assume end date is today
long days Duration.betweenstartDateatStartOfDay endDate.atStartOfDaytoDays;
double storageUsed Double.parseDoublestorageTextFieldgetText;
double costPerDay ;
Determine the selected provider and calculate the cost
if dropboxRadioButtonisSelected
costPerDay DROPBOXRATEPERGB storageUsed;
else if googleRadioButtonisSelected
costPerDay GOOGLERATEPERGB storageUsed;
else if onedriveRadioButtonisSelected
costPerDay ONEDRIVERATEPERGB storageUsed;
double totalCost costPerDay days;
double monthlyCost totalCost ; Assuming days in a month
costTextFieldsetTextStringformat$f costPerDay;
monthlyCostTextField.setTextStringformat$f monthlyCost;
if storageUsed STORAGELIMITGB
alertTextField.setTextWarning: Approaching storage limit;
You can also display an alert dialog
Alert alert new AlertAlertAlertType.WARNING;
alert.setTitleStorage Limit Warning";
alert.setHeaderTextWarning: Approaching storage limit;
alert.setContentTextYou have exceeded your storage limit of STORAGELIMITGB GB;
alert.showAndWait;
else
alertTextField.clear;
here's the FXML file just incase:
xml version encoding"UTF
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