modify my code so that whenever the button Modifier la commande is clicked on in…
- User
modify my code so that whenever the button Modifier la commande is clicked on in Receipt, it will bring me back to the PizzaOrder window and when the button Ajouter is clicked on again, the Receipt window will show again and whatever was on the list before is still shown and whatever was added to the list shows too and whatever the total was before was added to the total that was just added: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.border.TitledBorder; import javax.swing.border.EtchedBorder; import java.awt.Color; import java.awt.EventQueue;
import javax.swing.border.BevelBorder; import javax.swing.border.LineBorder; import javax.swing.border.SoftBevelBorder; import java.awt.GridLayout; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.DefaultComboBoxModel; import javax.swing.JTextField; import javax.swing.JButton; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; import java.awt.event.ActionEvent; import java.util.ArrayList;
public class PizzaOrder extends JFrame {
private JPanel contentPane; private JTextField NumPizza; private JTextField NumTopping; private JTextField NumBreuvage; private JButton Ajouter; private double totales; private String History; private static String previousHistory; private List<String> historyList; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { PizzaOrder frame = new PizzaOrder(previousHistory); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public PizzaOrder(String previousHistory) { History = previousHistory; historyList = new ArrayList<>(); setTitle("Order"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 630, 689); contentPane = new JPanel(); contentPane.setBackground(new Color(255, 147, 0)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JPanel Menu = new JPanel(); Menu.setBackground(new Color(255, 147, 0)); Menu.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0)), "Menu", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); Menu.setBounds(6, 6, 618, 158); contentPane.add(Menu); Menu.setLayout(new GridLayout(0, 3, 0, 0)); JPanel PizzaPrice = new JPanel(); PizzaPrice.setBackground(new Color(255, 147, 0)); PizzaPrice.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Pizza", TitledBorder.LEADING, TitledBorder.TOP, null, null)); Menu.add(PizzaPrice); PizzaPrice.setLayout(null); JLabel PetitPizza = new JLabel("Petit: 6.79$"); PetitPizza.setBounds(17, 21, 72, 16); PizzaPrice.add(PetitPizza); JLabel MoyenPizza = new JLabel("Moyen: 8.29$"); MoyenPizza.setBounds(17, 40, 85, 16); PizzaPrice.add(MoyenPizza); JLabel LargePizza = new JLabel("Large: 9.49$"); LargePizza.setBounds(17, 59, 85, 16); PizzaPrice.add(LargePizza); JLabel ExtraLargePizza = new JLabel("Extra Large: 10.29$"); ExtraLargePizza.setBounds(17, 78, 127, 16); PizzaPrice.add(ExtraLargePizza); JLabel FetePizza = new JLabel("Fete: 15.99$"); FetePizza.setBounds(17, 97, 93, 16); PizzaPrice.add(FetePizza); JPanel ToppingPrice = new JPanel(); ToppingPrice.setBackground(new Color(255, 147, 0)); ToppingPrice.setLayout(null); ToppingPrice.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Toppings", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); Menu.add(ToppingPrice); JLabel Petittopping = new JLabel("Petit: 1.20$"); Petittopping.setBounds(17, 21, 72, 16); ToppingPrice.add(Petittopping); JLabel Moyentopping = new JLabel("Moyen: 1.40$"); Moyentopping.setBounds(17, 40, 85, 16); ToppingPrice.add(Moyentopping); JLabel Largetopping = new JLabel("Large: 1.60$"); Largetopping.setBounds(17, 59, 85, 16); ToppingPrice.add(Largetopping); JLabel ExtraLargetopping = new JLabel("Extra Large: 1.80$"); ExtraLargetopping.setBounds(17, 78, 127, 16); ToppingPrice.add(ExtraLargetopping); JLabel Fetetopping = new JLabel("Fete: 2.30$"); Fetetopping.setBounds(17, 97, 93, 16); ToppingPrice.add(Fetetopping); JPanel BreuvagePrice = new JPanel(); BreuvagePrice.setBackground(new Color(255, 147, 0)); BreuvagePrice.setLayout(null); BreuvagePrice.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Breuvages", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); Menu.add(BreuvagePrice); JLabel Pop = new JLabel("Pop: 1.10$"); Pop.setBounds(17, 21, 72, 16); BreuvagePrice.add(Pop); JLabel Jus = new JLabel("Jus: 1.35$"); Jus.setBounds(17, 40, 85, 16); BreuvagePrice.add(Jus); JLabel Eau = new JLabel("Eau: 1.00$"); Eau.setBounds(17, 59, 85, 16); BreuvagePrice.add(Eau); JPanel PizzaSelect = new JPanel(); PizzaSelect.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null)); PizzaSelect.setBackground(new Color(255, 147, 0)); PizzaSelect.setBounds(16, 187, 350, 300); contentPane.add(PizzaSelect); PizzaSelect.setLayout(null); JComboBox<PizzaSize> ChoixPizza = new JComboBox<>(PizzaSize.values()); ChoixPizza.setModel(new DefaultComboBoxModel(PizzaSize.values())); ChoixPizza.setBounds(44, 8, 126, 27); ChoixPizza.setMaximumRowCount(5); PizzaSelect.add(ChoixPizza); NumPizza = new JTextField(); NumPizza.setText("0"); NumPizza.setBounds(175, 8, 130, 26); PizzaSelect.add(NumPizza); NumPizza.setColumns(10); JLabel PizzaIcon = new JLabel(""); PizzaIcon.setBounds(6, 6, 350, 279); PizzaSelect.add(PizzaIcon); PizzaIcon.setIcon(new ImageIcon(PizzaOrder.class.getResource("/Image/PizzaImage.png"))); JPanel ToppingSelect; ToppingSelect = new JPanel(); ToppingSelect.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null)); ToppingSelect.setBackground(new Color(255, 147, 0)); ToppingSelect.setBounds(400, 187, 208, 129); contentPane.add(ToppingSelect); ToppingSelect.setLayout(null); JComboBox<ToppingSize> ChoixTopping = new JComboBox<>(ToppingSize.values()); ChoixTopping.setModel(new DefaultComboBoxModel(ToppingSize.values())); ChoixTopping.setBounds(41, 8, 126, 27); ChoixTopping.setMaximumRowCount(5); ToppingSelect.add(ChoixTopping); NumTopping = new JTextField(); NumTopping.setText("0"); NumTopping.setBounds(39, 40, 130, 26); NumTopping.setColumns(10); ToppingSelect.add(NumTopping); JLabel ToppingIcon = new JLabel(""); ToppingIcon.setIcon(new ImageIcon(PizzaOrder.class.getResource("/Image/ToppingImage.png"))); ToppingIcon.setBounds(6, 8, 208, 109); ToppingSelect.add(ToppingIcon); JPanel BreuvageSelect = new JPanel(); BreuvageSelect.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null)); BreuvageSelect.setBackground(new Color(255, 147, 0)); BreuvageSelect.setBounds(400, 358, 208, 129); contentPane.add(BreuvageSelect); BreuvageSelect.setLayout(null); JComboBox<Breuvages> ChoixBreuvage = new JComboBox<>(Breuvages.values()); ChoixBreuvage.setModel(new DefaultComboBoxModel(Breuvages.values())); ChoixBreuvage.setBounds(64, 8, 79, 27); ChoixBreuvage.setMaximumRowCount(3); BreuvageSelect.add(ChoixBreuvage); NumBreuvage = new JTextField(); NumBreuvage.setText("0"); NumBreuvage.setBounds(39, 40, 130, 26); NumBreuvage.setColumns(10); BreuvageSelect.add(NumBreuvage); JLabel BreuvageIcon = new JLabel(""); BreuvageIcon.setIcon(new ImageIcon(PizzaOrder.class.getResource("/Image/BreuvageImage.png"))); BreuvageIcon.setBounds(0, 0, 209, 129); BreuvageSelect.add(BreuvageIcon); Ajouter = new JButton("Ajouter"); Ajouter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // retrieve selected values from combo boxes PizzaSize selectedPizzaSize = (PizzaSize) ChoixPizza.getSelectedItem(); ToppingSize selectedToppingSize = (ToppingSize) ChoixTopping.getSelectedItem(); Breuvages selectedBreuvage = (Breuvages) ChoixBreuvage.getSelectedItem(); int numPizza = Integer.parseInt(NumPizza.getText()); int numTopping = Integer.parseInt(NumTopping.getText()); int numBreuvage = Integer.parseInt(NumBreuvage.getText()); // calculate total amount totales += selectedPizzaSize.getPrice() * numPizza; totales += selectedToppingSize.getPrice() * numTopping; totales += selectedBreuvage.getPrice() * numBreuvage; double historytotal = (numPizza * selectedPizzaSize.getPrice()) + (numTopping * selectedToppingSize.getPrice() + (numBreuvage * selectedBreuvage.getPrice())); String historyEntry = numPizza + " Pizza de taille " + selectedPizzaSize + " avec " + numTopping + " " + selectedToppingSize + " garniture - Cout: " + historytotal; historyList.add(historyEntry); // clear text fields NumPizza.setText("0"); NumTopping.setText("0"); NumBreuvage.setText("0"); } }); Ajouter.setBounds(234, 552, 160, 50); contentPane.add(Ajouter); JButton Quitter = new JButton("Quitter"); Quitter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); Quitter.setBounds(33, 552, 160, 50); contentPane.add(Quitter); JButton Payer = new JButton("Payer"); Payer.setBounds(431, 552, 160, 50); contentPane.add(Payer); Payer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Receipt receiptWindow = new Receipt(totales, historyList); receiptWindow.setVisible(true); setVisible(false); } }); } - Assistant