Sunday, January 24, 2016
Radio Button - Compute Total
package radiobuttonexample;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
/**
*
* @author zbawk
*/
public class RadioButtonFrame extends javax.swing.JFrame {
/**
* Creates new form RadioButtonFrame
*/
public RadioButtonFrame() {
initComponents();
//Step 1:
jbtnComputeTotal.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
double drinkPrice = 0;
double dessertPrice = 0;
//check the first group
if(jradCoffee.isSelected())
{
drinkPrice = 1.75;
}
else if(jradJuice.isSelected())
{
drinkPrice = 3.75;
}
else if(jradSoda.isSelected()){
drinkPrice = 2.25;
}
int dq = Integer.parseInt(jtxtDrink.getText());
//drink subtotal
double drinkSubTotal = dq * drinkPrice;
//============== Check the dessert selection================
//check the second group
if(jradPecanPie.isSelected())
{
dessertPrice = 5.99;
}
else if(jradIceCream.isSelected())
{
dessertPrice = 4.50;
}
else if(jRadLemonPie.isSelected()){
dessertPrice = 4.99;
}
//get the qty of dessert
int dessertQty = Integer.parseInt(jtxtDessert.getText());
//drink subtotal
double dessertSubTotal = dessertQty * dessertPrice;
//Display subTotal for drinks next to a text "drinks: "
//Display subTotal for desserts next to a text "dessert: "
//Display overall subTotals next to a text "subtotals: "
//Display Tax next to a text "tax: "
//Display total cost next to a text "Total"
//in currency format
//That's your lab assignment
double SubTotal = drinkSubTotal + dessertSubTotal;
double Tax = SubTotal * 0.098;
double Total = SubTotal + Tax;
//jlblFahrenheit.setText (Ferh + "'" + " Fahrenheit");
NumberFormat formatter = NumberFormat.getCurrencyInstance();
// jlblDrink.formatter.format(drinkSubTotal);
// jtxtSalary.setText(formatter.format(salary));
jlblDrink.setText(formatter.format(drinkSubTotal));
jlblDessert.setText(formatter.format(dessertSubTotal));
jlblSubTotal.setText(formatter.format(SubTotal));
jlblTax.setText(formatter.format(Tax));
jlblTotal.setText(formatter.format(Total));
}
});
jbtnClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
// jtxtSalary.setText("");
//radioButton.setSelected(false);
}
});
}
Labels:
Java
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment