Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to use GUI programming in Java, including components, layouts, listeners,

ID: 3555303 • Letter: I

Question

I need to use GUI programming in Java, including components, layouts, listeners, handlers. And practice how the GUI interacts with the back-end data processing in a program.

I have to modify the given GUI demo (FastFood) by adding a few buttons to allow the user more options for ordering foods and drinks such as more ingredients or less for hamburgers and/or various sizes for drinks.

*****PLEASE HELP!******

Fast Food Class:

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class FastFood extends JFrame implements ActionListener
{
private JTextField display;
private JPanel buttonPanel;
private JTextArea receipt;
private JButton hb; //hamburger
private JButton fr; //fries
private JButton dk; //drink
private JButton ck;
private JButton cancel;
private JButton newC;
private Container contentPane;
private JScrollPane scrollPane;
private String receiptMsg;
private Item lastItemOrdered;
private final double HB_PRICE = 2.99;
private final double FR_PRICE = 1.99;
private final double DK_PRICE = 0.99;
private double total;
private String WELCOME = "welcome to jack's junk food! start ordering........";
private String displayMsg;
public static void main (String [ ] args)
{
FastFood jack = new FastFood ( );
jack.setVisible(true);
}
public FastFood ( )
{
setSize (600,400);
contentPane = getContentPane ( );
setDefaultCloseOperation (EXIT_ON_CLOSE);
contentPane.setLayout (new BorderLayout ( ));

display = new JTextField (50);
contentPane.add (display, BorderLayout.NORTH);
  
receipt = new JTextArea (10,50);
scrollPane = new JScrollPane (receipt);
contentPane.add (scrollPane, BorderLayout.SOUTH);
  
buttonPanel = new JPanel ( );
buttonPanel.setLayout (new FlowLayout ( ));
  
hb = new JButton ("HB");
hb.addActionListener (this);
buttonPanel.add (hb);
  
fr = new JButton ("FR");
fr.addActionListener (this);
buttonPanel.add (fr);
  
dk = new JButton ("DK");
dk.addActionListener (this);
buttonPanel.add (dk);
  
cancel = new JButton ("Cancel");
cancel.addActionListener (this);
buttonPanel.add (cancel);
  
newC = new JButton ("New");
newC.addActionListener (this);
buttonPanel.add (newC);
  
ck = new JButton ("Check");
ck.addActionListener (this);
buttonPanel.add (ck);
  
contentPane.add (buttonPanel, BorderLayout.CENTER);
  
hb.setEnabled (false);
fr.setEnabled (false);
dk.setEnabled (false);
cancel.setEnabled (false);
ck.setEnabled (false);
newC.setEnabled (true);
receiptMsg = "";
displayMsg = "";
total = 0;
}
  
public void actionPerformed (ActionEvent ex)
{
String whichOne = ex.getActionCommand ( );
  
if (whichOne.equals ("New"))
{
display.setText ("");
receiptMsg = WELCOME;
receipt.setText (receiptMsg);
displayMsg = "";
display.setText (displayMsg);
total = 0;
hb.setEnabled (true);
fr.setEnabled (true);
dk.setEnabled (true);
cancel.setEnabled (true);
ck.setEnabled (true);
newC.setEnabled (true);
}
else if (whichOne.equals ("Cancel"))
{
total -= lastItemOrdered.getPrice ( ) ;
receiptMsg += (" CANCEL " + lastItemOrdered + ".....subtracted" );
receipt.setText (receiptMsg);
displayMsg += ("-" + lastItemOrdered.getPrice ( ));
display.setText (displayMsg);
}
else if (whichOne.equals ("Check"))
{
receiptMsg += (" ***total = " + total + " thank you");
receipt.setText (receiptMsg);
displayMsg += ("=" + total);
display.setText (displayMsg);
}
else
{
if (whichOne.equals ("HB"))
lastItemOrdered = new Item ("hamburger",HB_PRICE);
else if (whichOne.equals ("FR"))
lastItemOrdered = new Item ("fries",FR_PRICE);
else if (whichOne.equals ("DK"))
lastItemOrdered = new Item ("drink",DK_PRICE);
total += lastItemOrdered.getPrice ( );
  
receiptMsg += lastItemOrdered;
receipt.setText (receiptMsg);
displayMsg += ("+" + lastItemOrdered.getPrice ( ));
display.setText (displayMsg);
}
  
  
}
  
}

Item Class:

public class Item

{
private String name;
private double price;
  
public Item (String nName, double nPrice)
{
price = nPrice;
name = nName;
}
  
public double getPrice ( )
{
return price;
}
  
public String toString ( )
{
return " 1 " + name + "...price: " + price;
}
}

Explanation / Answer

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.lang.*; public class FastFood extends JFrame{ int i, order; String ch; int quantityLost[] = new int[Main.itemsNo]; double cost[] = new double[Main.itemsNo]; double totalCost=0.0; boolean inputEnabled=false; boolean start=true; boolean firstInput=true; int productID; int cashierNumber=Main.cashierNo+1; Container paneMain = getContentPane(); Date date = new Date(); JPanel paneCENTER = new JPanel(); JPanel paneSOUTH = new JPanel(); JPanel pane1 = new JPanel(); JPanel pane2 = new JPanel(); JPanel pane3 = new JPanel(); JTextField quantityTF = new JTextField(9); JTextArea cashierScreen = new JTextArea(14,31); CheckboxGroup productsCBG = new CheckboxGroup(); Checkbox upsizeFD = new Checkbox("UpSize Fries/Drinks"); JButton addItem = new JButton ("Add Selected Item"); JButton cancel = new JButton ("Cancel Current Transaction"); JButton clear = new JButton ("Reset Fields - [VOID]"); JButton closeCashier = new JButton ("Close Cashier Lane "); JButton startend = new JButton("..Start Transaction.."); JButton about = new JButton("About"); JButton inventory = new JButton("Check Business Status"); Checkbox CBG1 = new Checkbox("Burger",productsCBG, false); Checkbox CBG2 = new Checkbox("Cheese Burger",productsCBG, false); Checkbox CBG3 = new Checkbox("Sandae",productsCBG, false); Checkbox CBG4 = new Checkbox("Fries",productsCBG, false); Checkbox CBG5 = new Checkbox("Drinks",productsCBG, false); JButton[] num = new JButton[10]; JFrame printedReceipt = new JFrame(); JButton rB = new JButton("Exit Printed Receipt Window"); TextArea rTF=new TextArea(); public static String[] products = new String[100]; public static int[] quantity = new int[100]; public static double[] price = new double[100]; public static int itemsNo=7; public static void inventoryLoad() throws IOException{ System.out.println("Loading inventory.txt.."); BufferedReader in = null; in = new BufferedReader(new FileReader("inventory.txt")); String temp; for (int ctr = 0; ctr