I am trying to find a way to write information gathered via scenebuilder into a .txt file. I managed to use if else statements to produce the desired results within the output window. Sadly, I am unable to find a way to save the file. I need a way to save and restore the information. Please help.
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxapplication1;
import java.awt.Checkbox;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
/**
*
* @author cwcis
*/
public class FXMLDocumentController implements Initializable {
private Label label;
@FXML
private Button save;
@FXML
private Button restore;
@FXML
private Button calculate;
@FXML
private TextField textcalccost;
@FXML
private RadioButton vanilla;
@FXML
private RadioButton chocolate;
@FXML
private RadioButton strawberry;
@FXML
private CheckBox nuts;
@FXML
private CheckBox cherries;
@FXML
private ToggleGroup IceCream;
@FXML
private void handleButtonSaving(ActionEvent event) {
if(vanilla.isSelected()) {
System.out.println("Vanilla");
}
if(chocolate.isSelected()) {
System.out.println("Chocolate");
}
if(strawberry.isSelected()) {
System.out.println("Strawberry");
}
if(nuts.isSelected()) {
System.out.println("With_Nuts");
}
else {
System.out.println("Without_Nuts");
}
if(cherries.isSelected()) {
System.out.println("With_Cherries");
}
else {
System.out.println("Without_Cherries");
}
}
@FXML
private void handleButtonRestore(ActionEvent event) {
}
@FXML
private void handleButtonCalculateCost(ActionEvent event) {
double myTotal = 0.0;
myTotal += retrieveIceCreamCost();
myTotal += retrieveToppingsCost();
myTotal += retrieveTaxCost();
showAlert(myTotal);
}
private void showAlert(double theTotal) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Ice Cream Shop");
alert.setHeaderText("Order Confirmation");
alert.setContentText("Order: " + (retrieveIceCreamCost() +
retrieveToppingsCost())
+ "\nTax: " + retrieveTaxCost() + "\nTotal: " + theTotal);
alert.showAndWait();
}
private double retrieveIceCreamCost() {
double iceCreamCost = 0.0;
if(vanilla.isSelected()) {
iceCreamCost = 2.25;
}
if(chocolate.isSelected()) {
iceCreamCost = 2.25;
}
if(strawberry.isSelected()) {
iceCreamCost = 2.25;
}
return iceCreamCost;
}
private double retrieveToppingsCost() {
double toppingsCost = 0.0;
if(cherries.isSelected()) {
toppingsCost += 0.50;
}
if(nuts.isSelected()) {
toppingsCost += 0.50;
}
return toppingsCost;
}
private double retrieveTaxCost() {
double taxCost = 0.0;
if(cherries.isSelected()) {
taxCost += .03;
}
if(nuts.isSelected()) {
taxCost += .03;
}
if(vanilla.isSelected()) {
taxCost += .14;
}
if(chocolate.isSelected()) {
taxCost += .14;
}
if(strawberry.isSelected()) {
taxCost += .14;
}
return taxCost;
}
public FXMLDocumentController() {
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Aucun commentaire:
Enregistrer un commentaire