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

You have been contacted by a client who owns a garden shop. The client would lik

ID: 3571950 • Letter: Y

Question

You have been contacted by a client who owns a garden shop. The client would like an application where the customers can choose from garden supplies (rakes, garden hose, etc.), various plants (flowering as well as non-flowering plants, such as ferns).

Give the code to create N W E W and Center Panel Buttons: North will feature Contact Information when pressed; South will feature Garden Supply Products with three check boxes (one for garden tools, one for fertilizer, and one for pest control) when pressed;

East will feature Gardening tips; West will feature all plants sold at the facility, with three radio buttons (one for flowers, one for grass, one for trees).

Center will contain a combo box which lists the following choices: garden tips, garden supplies, garden plants – flowers, garden plants – fruit trees, garden plants – vegetables

And how about an image or two! Find at least one image per panel that is pertinent to the subject matter of the main NEWSC buttons (that’s five images!).

  

Functionality is NOT required (don’t worry about listeners)! Just design for practice with GUI components!

Provide a snapshot of the output of your GUI and the code! in Java language please.

Explanation / Answer

Please find below the GUI java program with comments :

import javax.swing.*;
import java.io.*; // This is Needed for File object related things.
import java.util.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.Color;
import java.text.SimpleDateFormat;

public class GardenShop extends MouseAdapter implements ActionListener{
Flower inventory; // This is the Inventory of all flowers in the shop.
  
// This is GUI related objects.
  
JButton [] flowerButton; // This will Holds incons of all flowers in the shop
JButton transactionOver; // This will Indcate the end of a transaction
  
JFrame fProduct, fReceipt; // This is the part Where all the panels are placed.
  
JPanel buttonPanel; // This is the part Where all buttons are placed
JPanel textPanel; // This is the part Where all the price information is displayed in textfields
JPanel receiptPanel; //This is the part Where the receipt is displayed
JPanel backgroundPanel; // This is to hold all the other panels
  
JTextField flowerPurchased, unitPrice, quantity;
JTextField purchasePrice, netCostField;
  
JTextArea receipt; // This is to display the receipt
JScrollPane scrollPane; // This is the part to help with scrollable text area
  
  
// Below are the other useful variables
  
int flowerCount=0; // This is Number of flower types in the inventory
int maxFlowers=100; // This is Maximum types of flowers in the inventory
double totalCost=0; // This is to calculate Total cost of all purchased flowers
Flower [] flower=new Flower[maxFlowers]; // Flower data goes in this array
String inventoryLocation="FlowerPictures"; /// Folder where the flower data to be input

public GardenShop(){
  
}// This is the end of constructor
  
// This will Get flower inventory from the specified file
// and will create buttons with flower icons.
  
public void getFlowerdata(String fileName) throws Exception{
File file = new File(fileName); // This will create a virtual file object.
Scanner in = new Scanner(file);
flowerButton=new JButton[maxFlowers] ;
  
// The below will Set up loop to read data from the inventory file.
  
while (in.hasNext()){
String name=in.next();
double unitPrice=in.nextDouble();
String location=inventoryLocation+"/"+name+".jpg";
Flower f=new Flower(name, location, unitPrice);
flower[flowerCount]=f;
flowerCount++;
System.out.println(flowerCount+" "+name +" "+unitPrice);
}
}// This is the End of getFlowerData()
  
public void createButtons(){
for(int i=0; i<flowerCount; i++){
flowerButton[i]=new JButton(flower[i].getIcon());
flowerButton[i].addActionListener(this);
flowerButton[i].addMouseListener(this);
}
  
transactionOver=new JButton("Checkout");
transactionOver.addActionListener(this);
}// This is the End of createButtons()
  
public void createTextBoxes(){
final int TEXTFIELD_WIDTH=10;
flowerPurchased=new JTextField("None", TEXTFIELD_WIDTH);
unitPrice=new JTextField("$0.0", TEXTFIELD_WIDTH);
quantity=new JTextField("0", TEXTFIELD_WIDTH);
quantity.addActionListener(this);
purchasePrice=new JTextField("$0.0", TEXTFIELD_WIDTH);
netCostField=new JTextField("$0.0", TEXTFIELD_WIDTH);
  
// To Create a scrollable text area.
  

receipt=new JTextArea("Your receipt ", 20, 40);
scrollPane = new JScrollPane(receipt);

  
} // This is the End of createTextBoxes()
  
  
public void createPanels(){
  
// To Create panel to hold text boxes
textPanel=new JPanel(new GridLayout(2,5));
textPanel.add(new JLabel("Flower"));
textPanel.add(new JLabel("Quantity"));
textPanel.add(new JLabel("Unit Price"));
textPanel.add(new JLabel("You pay"));
textPanel.add(new JLabel("Total Price"));
  
textPanel.add(flowerPurchased);
textPanel.add(quantity);
textPanel.add(unitPrice);
  
textPanel.add(purchasePrice);
textPanel.add(netCostField);
  
buttonPanel=new JPanel(new GridLayout(5,2));
for(int i=0; i<flowerCount; i++){
buttonPanel.add(flowerButton[i]);
}
buttonPanel.add(transactionOver);
// To Create panel for receipt
  
receiptPanel=new JPanel();
receiptPanel.setBackground(Color.BLUE);
receiptPanel.add(scrollPane);
  
// To Create background panel that holds other panels.
backgroundPanel=new JPanel();
  
backgroundPanel.setBackground(Color.YELLOW);
backgroundPanel.add(textPanel);
backgroundPanel.add(buttonPanel);
backgroundPanel.add(receiptPanel);
  
  
}// This is the End of createPanels()
  
public void createFrame(){
//This will ask for window decorations provided by the look and feel.
JFrame.setDefaultLookAndFeelDecorated(true);
  
fProduct=new JFrame("CS 180 Flower Shop");
fProduct.setSize(700, 500);
fProduct.add(backgroundPanel);
fProduct.setVisible(true);
  
// The below will get position of Product frame and place the receipt frame below it.
Point p=fProduct.getLocationOnScreen();
Dimension d=fProduct.getSize();
  
fReceipt=new JFrame("CS 180 Flower Shop: Receipt");
fReceipt.setSize(600, 400);
fReceipt.add(receiptPanel);
fReceipt.setLocation(p.x, p.y+d.height+5);
  
fReceipt.setVisible(true);
  
}// This is the End createFrame()
  
public void newTransaction(){
  
}// This is the End of new transaction
  
// This method is based on Sun Java
public String getDate(){
Date today;
String output;
SimpleDateFormat formatter;
String pattern="yyyy.MMMMM.dd GGG hh:mm aaa"; //string pattern will be set here
  
formatter = new SimpleDateFormat(pattern); //new format set
today = new Date();
output = formatter.format(today);
return(output);
}// This is the End of getDate()
  
public void actionPerformed(ActionEvent e){
Object ob=e.getSource(); // This will extract the object that led to this event.
  
// This is to first check if this is the end of the purchase
  
if(ob==transactionOver){
if(totalCost>0){
Date d;
receipt.append(" Your Total: "+String.format("$%.2f ", totalCost));
receipt.append(" Thank you. Please come again. ");
receipt.append(getDate());
}

return; // Done with this transaction.
}
// This is to identify which button, if any, was clicked.
  
boolean objectLocated=false; // Which all Object are not yet identified
int nextObject=0; // Iteration count

// The below will Search for object ob in the flowerButtons
while(nextObject<flowerCount &&!objectLocated){
if(ob==flowerButton[nextObject]){
objectLocated=true;
}else{
nextObject++;
}
}// This is the End of while

if(objectLocated){
String fPurchased=flower[nextObject].getKind();
flowerPurchased.setText(fPurchased);
double uPrice=flower[nextObject].getUnitPrice();
String formattedUPrice="$"+Double.toString(uPrice);
unitPrice.setText(formattedUPrice);
String q=quantity.getText();
double quantDouble=Double.parseDouble(q);
if(quantDouble>0){
double price=quantDouble*uPrice;
String formattedPrice="$"+String.format("%.2f",price);
purchasePrice.setText(formattedPrice);
totalCost=totalCost+price;
String fTotalCost=String.format("$%.2f ", totalCost);
netCostField.setText("$"+fTotalCost);

// The below will Display this item on the receipt.
String r=fPurchased+" "+q+" "+formattedUPrice+ //Purchased item receipt
" "+formattedPrice+" "+fTotalCost+" ";
receipt.append(r);
}
}
}// This is the End of action performed method
  
public void mouseEntered(MouseEvent e){
Object ob=e.getSource(); // Extract the object that led to this event.
  
// This is to identify which button, if any, was clicked.
  
boolean buttonLocated=false; // Object not yet iudentified
int nextObject=0; // Iteration count

// The below will Search for object o in the flowerButtons
while(nextObject<flowerCount &&!buttonLocated){
if(ob==flowerButton[nextObject]){
buttonLocated=true;
}else{
nextObject++;
}
}// This is the End of while

if(buttonLocated){
flowerPurchased.setText(flower[nextObject].getKind());
unitPrice.setText("$"+Double.toString(flower[nextObject].getUnitPrice()));
}
}// This is the End of mouseEntered()
  
public static void main(String [] args)throws Exception{
  
// This will Get user supplied file name.
String fileName="flowerInventory.txt";
  
GardenShop GardenShop=new GardenShop();
GardenShop.getFlowerdata(fileName);
GardenShop.createButtons();
GardenShop.createTextBoxes();
  
GardenShop.createPanels();
GardenShop.createFrame();
  
}// This is the End of main()
  
}// This is the End of GardenShop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote