This is my current code and the showButton is now working, thanks to you, but unfortunately the totalButton is still not. Could you me help figure this out?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import java.util.EventObject;
public class GUISS extends JFrame implements ActionListener
{
public static void main(String[] args)
{
new GUISS();
}
private JButton totalButton, showButton;
private JTextField productField, productField2, productField3, productField4, productField5;
private JTextField priceField, priceField2, priceField3, priceField4, priceField5;
private JTextField quantityField, quantityField2, quantityField3, quantityField4, quantityField5;
private JTextField totalField, totalField2, totalField3, totalField4, totalField5, emptyField, totalAmountField;
static double num1 , num2, num3, num4, num5, ans, ans2;
static double CBOX1 = 25.00, CBOX2 = 25.00, CBOX3 = 39.00, CBOX4 = 25.00;
public GUISS()
{
setLayout(new FlowLayout());
setTitle("Mcdonalds");
setSize(520,200);
productField = new JTextField("Best Sellers", 10);
productField. setEditable(false);
productField2 = new JTextField("Burger Mcdo", 10);
productField2.setEditable(false);
productField3 = new JTextField("Hot Fudge Sundae", 10);
productField3.setEditable(false);
productField4 = new JTextField("CheeseBurger", 10);
productField4.setEditable(false);
productField5 = new JTextField("Regular McFries", 10);
productField5.setEditable(false);
priceField = new JTextField("Alacarte Price", 10);
priceField.setEditable(false);
priceField2 = new JTextField("P25.00", 10);
priceField2.setEditable(false);
priceField3 = new JTextField("P25.00", 10);
priceField3.setEditable(false);
priceField4 = new JTextField("P39.00", 10);
priceField4.setEditable(false);
priceField5 = new JTextField("P25.00", 10);
priceField5.setEditable(false);
quantityField = new JTextField("Quantity", 10);
quantityField.setEditable(false);
quantityField2 = new JTextField(10);
quantityField3 = new JTextField(10);
quantityField4 = new JTextField(10);
quantityField5 = new JTextField(10);
totalField = new JTextField("Total Price", 10);
totalField.setEditable(false);
totalField2 = new JTextField("P0.0", 10);
totalField2.setEditable(false);
totalField3 = new JTextField("P0.0", 10);
totalField3.setEditable(false);
totalField4 = new JTextField("P0.0", 10);
totalField4.setEditable(false);
totalField5 = new JTextField("P0.0", 10);
totalField5.setEditable(false);
emptyField = new JTextField(10);
// JButton showButton = new JButton("Show price");
//JTextFieldtotalButton = new JButton("Total Amount");
totalAmountField = new JTextField("P0.0", 10);
totalAmountField.setEditable(false);
JTextField CashField = new JTextField(10);
totalButton = new JButton("Total Amount");
showButton = new JButton("Show price");
add(productField);
add(priceField);
add(quantityField);
add(totalField);
add(productField2);
add(priceField2);
add(quantityField2);
add(totalField2);
add(productField3);
add(priceField3);
add(quantityField3);
add(totalField3);
add(productField4);
add(priceField4);
add(quantityField4);
add(totalField4);
add(productField5);
add(priceField5);
add(quantityField5);
add(totalField5);
add(showButton);
showButton.addActionListener(this);
add(totalButton);
totalButton.addActionListener(this);
add(totalAmountField);
setVisible(true);
}
public void actionPerformed ( ActionEvent e )
{
System.out.println("Entered action performed");
if(e.getSource() == showButton ){
if(!quantityField2.getText().equals(emptyField.getText())){
num1 = Double.parseDouble(String.valueOf(quantityField2.getText()));
ans = num1 * CBOX1 ;
totalField2.setText(String.valueOf("P" + ans));
}
if(!quantityField3.getText().equals(emptyField.getText())){
num1 = Double.parseDouble(String.valueOf(quantityField3.getText()));
ans = num1 * CBOX2 ;
totalField3.setText(String.valueOf("P" + ans));
}
if(!quantityField4.getText().equals(emptyField.getText())){
num1 = Double.parseDouble(String.valueOf(quantityField4.getText()));
ans = num1 * CBOX3 ;
totalField4.setText(String.valueOf("P" + ans));
}
if(!quantityField5.getText().equals(emptyField.getText())){
num1 = Double.parseDouble(String.valueOf(quantityField5.getText()));
ans = num1 * CBOX4 ;
totalField5.setText(String.valueOf("P" + ans));
}
else if(e.getSource() == totalButton){
if(!totalField2.getText().equals(0)){
num2 = Double.parseDouble(String.valueOf(totalField2.getText()));
}
if(!totalField3.getText().equals(0)){
num3 = Double.parseDouble(String.valueOf(totalField3.getText()));
}
if(!totalField4.getText().equals(0)){
num4 = Double.parseDouble(String.valueOf(totalField4.getText()));
}
if(!totalField5.getText().equals(0)){
num5 = Double.parseDouble(String.valueOf(totalField5.getText()));
}
else {
ans2 = num2 + num3 + num4 + num5 ;
totalAmountField.setText(String.valueOf("P" + ans2));
}
}
}
}
}
thanks for helping, this code is very important for me