'Display arlert dialog of information when button clicked (NetBeans - JavaFX)
I get stuck on display the subtotal, tax and grand total in an Alert dialog of information (displayed when Complete Order is clicked). I don't kknow how to display my calculation in alert dialog. Please advise.
public void handle(ActionEvent evtActionEvent)
{
//get the object that triggered the event
Object sourceObject = evtActionEvent.getSource();
//which object triggered the event
if(sourceObject == quantityTextField || sourceObject == addOrderButton)
{
// call the validation method and if it returns a true then call purchase
if(validation())
purchase();
}
else if(sourceObject == completeOrderButton)
{
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Confirmation");
alert.setHeaderText(null);
alert.setContentText(".");
alert.showAndWait();
}
}
public void displayPurchase(float newSubtotalFloat, float newTaxFloat,
float newTotalFloat)
{
//Format the values to currency format
DecimalFormat valueDecimalFormat = new DecimalFormat("$#0.00");
//display the total for the customer
invoiceTextArea.setText("Invoice for Customer "+'\n' +
"Name " + nameTextField.getText() + '\n' +
"Quantity " + '\t' + quantityTextField.getText() + '\n' +
"Type " + '\t' + typeSelect()+ '\n' +
"Subtotal " + valueDecimalFormat.format(newSubtotalFloat) + '\n' +
"Tax " + valueDecimalFormat.format(newTaxFloat) + '\n' +
"Total " + valueDecimalFormat.format(newTotalFloat) + '\n' );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|