import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; //class declaration public class foodtest extends JFrame implements ActionListener {     // declare global variables     JCheckBox cbBurger, cbEggs, cbFriedChicken, cbBrownRice, cbIceCream;     JLabel lblTitle, lblBurger, lblEggs, lblFriedChicken, lblBrownRice, lblIceCream;     JButton b1Calculate, b2Check, b3Reset, b4Cancel;     JTextArea t1Output;     int burgerCal = 295, eggsCal = 72, friedchickenCal = 260, brownriceCal = 111, icecreamCal = 300;     int totalCal = 0;     ArrayList foodItems = new ArrayList();     ArrayList foodCalories = new ArrayList();     // constructor     public foodtest() {         // set frame properties         setTitle("IS YOUR FOOD HEALTHY?");         setSize(630, 520);         setLayout(new FlowLayout());         setResizable(false);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         // initialize variables         lblTitle = new JLabel("Whats your order:");         lblBurger = new JLabel("Burger");         lblEggs = new JLabel("Eggs");         lblFriedChicken = new JLabel("Fried Chicken");         lblBrownRice = new JLabel("Brown Rice");         lblIceCream = new JLabel("Ice Cream");         cbBurger = new JCheckBox();         cbEggs = new JCheckBox();         cbFriedChicken = new JCheckBox();         cbBrownRice = new JCheckBox();         cbIceCream = new JCheckBox();         b1Calculate = new JButton("Calculate");         b2Check = new JButton("Check");         b3Reset = new JButton("Reset");         b4Cancel = new JButton("Cancel");         t1Output = new JTextArea(10, 30);         // add action listeners         b1Calculate.addActionListener(this);         b2Check.addActionListener(this);         b3Reset.addActionListener(this);         b4Cancel.addActionListener(this);         // add items to frame         add(lblTitle);         add(lblBurger);         add(cbBurger);         add(lblEggs);         add(cbEggs);         add(lblFriedChicken);         add(cbFriedChicken);         add(lblBrownRice);         add(cbBrownRice);         add(lblIceCream);         add(cbIceCream);         add(b1Calculate);         add(b2Check);         add(b3Reset);         add(b4Cancel);         add(t1Output);         // display frame         setVisible(true);     }     // actionPerformed method     public void actionPerformed(ActionEvent e) {         // declare local variables         Object source = e.getSource();         if (source == b1Calculate) {             // get selected food items and add them to array list             if (cbBurger.isSelected()) {                 foodItems.add("Burger");                 foodCalories.add(burgerCal);             }             if (cbEggs.isSelected()) {                 foodItems.add("Eggs");                 foodCalories.add(eggsCal);             }             if (cbFriedChicken.isSelected()) {                 foodItems.add("Fried Chicken");                 foodCalories.add(friedchickenCal);             }             if (cbBrownRice.isSelected()) {                 foodItems.add("Brown Rice");                 foodCalories.add(brownriceCal);             }             if (cbIceCream.isSelected()) {                 foodItems.add("Ice Cream");                 foodCalories.add(icecreamCal);             }             // calculate total calories             for (                     int i = 0; i < foodCalories.size(); i++) {                 totalCal += foodCalories.get(i);             }             // display selected food items and total calories             t1Output.setText("You have selected:");             for (int i = 0; i < foodItems.size(); i++) {                 t1Output.append(foodItems.get(i) + "\n");             }             t1Output.append("Total Calories: " + totalCal);         } else if (source == b2Check) {             // check if food is healthy or not             if (totalCal <= 200) {                 t1Output.append("\nThis food is healthy!");             } else {                 t1Output.append("\nThis food is unhealthy!");             }         } else if (source == b3Reset) {             // clear all selections             cbBurger.setSelected(false);             cbEggs.setSelected(false);             cbFriedChicken.setSelected(false);             cbBrownRice.setSelected(false);             cbIceCream.setSelected(false);             foodItems.clear();             foodCalories.clear();             totalCal = 0;             t1Output.setText("");         } else if (source == b4Cancel) {             // exit program             System.exit(0);         }     }     // main method     public static void main(String[] args) {         new foodtest();     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
PLEASE ADD SOME DESIGNS ON MY JAVA PROGRAM, LIKE FONTS, BACKGROUND COLOR ETC.
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

//class declaration
public class foodtest extends JFrame implements ActionListener {
    // declare global variables

    JCheckBox cbBurger, cbEggs, cbFriedChicken, cbBrownRice, cbIceCream;
    JLabel lblTitle, lblBurger, lblEggs, lblFriedChicken, lblBrownRice, lblIceCream;
    JButton b1Calculate, b2Check, b3Reset, b4Cancel;
    JTextArea t1Output;
    int burgerCal = 295, eggsCal = 72, friedchickenCal = 260, brownriceCal = 111, icecreamCal = 300;
    int totalCal = 0;
    ArrayList<String> foodItems = new ArrayList<String>();
    ArrayList<Integer> foodCalories = new ArrayList<Integer>();

    // constructor
    public foodtest() {
        // set frame properties
        setTitle("IS YOUR FOOD HEALTHY?");
        setSize(630, 520);
        setLayout(new FlowLayout());
        setResizable(false);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // initialize variables
        lblTitle = new JLabel("Whats your order:");
        lblBurger = new JLabel("Burger");
        lblEggs = new JLabel("Eggs");
        lblFriedChicken = new JLabel("Fried Chicken");
        lblBrownRice = new JLabel("Brown Rice");
        lblIceCream = new JLabel("Ice Cream");
        cbBurger = new JCheckBox();
        cbEggs = new JCheckBox();
        cbFriedChicken = new JCheckBox();
        cbBrownRice = new JCheckBox();
        cbIceCream = new JCheckBox();
        b1Calculate = new JButton("Calculate");
        b2Check = new JButton("Check");
        b3Reset = new JButton("Reset");
        b4Cancel = new JButton("Cancel");
        t1Output = new JTextArea(10, 30);

        // add action listeners
        b1Calculate.addActionListener(this);
        b2Check.addActionListener(this);
        b3Reset.addActionListener(this);
        b4Cancel.addActionListener(this);

        // add items to frame
        add(lblTitle);
        add(lblBurger);
        add(cbBurger);
        add(lblEggs);
        add(cbEggs);
        add(lblFriedChicken);
        add(cbFriedChicken);
        add(lblBrownRice);
        add(cbBrownRice);
        add(lblIceCream);
        add(cbIceCream);
        add(b1Calculate);
        add(b2Check);
        add(b3Reset);
        add(b4Cancel);
        add(t1Output);

        // display frame
        setVisible(true);
    }

    // actionPerformed method
    public void actionPerformed(ActionEvent e) {
        // declare local variables
        Object source = e.getSource();

        if (source == b1Calculate) {

            // get selected food items and add them to array list
            if (cbBurger.isSelected()) {
                foodItems.add("Burger");
                foodCalories.add(burgerCal);
            }
            if (cbEggs.isSelected()) {
                foodItems.add("Eggs");
                foodCalories.add(eggsCal);
            }
            if (cbFriedChicken.isSelected()) {
                foodItems.add("Fried Chicken");
                foodCalories.add(friedchickenCal);
            }
            if (cbBrownRice.isSelected()) {
                foodItems.add("Brown Rice");
                foodCalories.add(brownriceCal);
            }
            if (cbIceCream.isSelected()) {
                foodItems.add("Ice Cream");
                foodCalories.add(icecreamCal);
            }

            // calculate total calories
            for (

                    int i = 0; i < foodCalories.size(); i++) {
                totalCal += foodCalories.get(i);
            }

            // display selected food items and total calories
            t1Output.setText("You have selected:");
            for (int i = 0; i < foodItems.size(); i++) {
                t1Output.append(foodItems.get(i) + "\n");
            }
            t1Output.append("Total Calories: " + totalCal);

        } else if (source == b2Check) {
            // check if food is healthy or not
            if (totalCal <= 200) {
                t1Output.append("\nThis food is healthy!");
            } else {
                t1Output.append("\nThis food is unhealthy!");
            }
        } else if (source == b3Reset) {
            // clear all selections
            cbBurger.setSelected(false);
            cbEggs.setSelected(false);
            cbFriedChicken.setSelected(false);
            cbBrownRice.setSelected(false);
            cbIceCream.setSelected(false);
            foodItems.clear();
            foodCalories.clear();
            totalCal = 0;
            t1Output.setText("");
        } else if (source == b4Cancel) {
            // exit program
            System.exit(0);
        }
    }

    // main method
    public static void main(String[] args) {
        new foodtest();
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education