Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class BBH_GreetingPanel extends JPanel {
- private JLabel greeting;
- public BBH_GreetingPanel() {
- greeting = new JLabel("Welcome to Brandi's Bagel House!");
- add(greeting);
- }
- }
- import javax.swing.*;
- import java.awt.*;
- public class BBH_ToppingPanel extends JPanel {
- public final double CREAM_CHEESE = 0.50;
- public final double BUTTER = 0.25;
- public final double PEACH_JELLY = 0.75;
- public final double BLUEBERRY_JAM = 0.75;
- private JCheckBox creamCheese;
- private JCheckBox butter;
- private JCheckBox peachJelly;
- private JCheckBox blueberryJam;
- public BBH_ToppingPanel() {
- setLayout(new GridLayout(4, 1));
- creamCheese = new JCheckBox("Cream Cheese");
- butter = new JCheckBox("Butter");
- peachJelly = new JCheckBox("Peach Jelly");
- blueberryJam = new JCheckBox("Blueberry Jam");
- setBorder(BorderFactory.createTitledBorder("Toppings"));
- add(creamCheese);
- add(butter);
- add(peachJelly);
- add(blueberryJam);
- }
- public double getToppingCost() {
- double toppingCost = 0.0;
- if(creamCheese.isSelected())
- toppingCost += CREAM_CHEESE;
- if(butter.isSelected());
- toppingCost += BUTTER;
- if(peachJelly.isSelected());
- toppingCost += PEACH_JELLY;
- if(blueberryJam.isSelected());
- toppingCost += BLUEBERRY_JAM;
- return toppingCost;
- }
- }
- import javax.swing.*;
- import java.awt.*;
- public class BBH_CoffeePanel extends JPanel{
- public final double NO_COFFEE = 0.0;
- public final double REGULAR_COFFEE = 1.25;
- public final double DECAF_COFFEE = 1.25;
- public final double CAPPUCCINO = 2.00;
- private JRadioButton noCoffee;
- private JRadioButton regularCoffee;
- private JRadioButton decafCoffee;
- private JRadioButton cappuccino;
- private ButtonGroup bg;
- public BBH_CoffeePanel() {
- setLayout(new GridLayout(4, 1));
- noCoffee = new JRadioButton("None", true);
- regularCoffee = new JRadioButton("Regular");
- decafCoffee = new JRadioButton("Decaffeinated");
- cappuccino = new JRadioButton("Cappuccino");
- bg = new ButtonGroup();
- bg.add(noCoffee);
- bg.add(regularCoffee);
- bg.add(decafCoffee);
- bg.add(cappuccino);
- setBorder(BorderFactory.createTitledBorder("Coffee"));
- add(noCoffee);
- add(regularCoffee);
- add(decafCoffee);
- add(cappuccino);
- }
- public double getCoffeeCost() {
- double coffeeCost = 0.0;
- if (noCoffee.isSelected())
- coffeeCost = NO_COFFEE;
- else if (regularCoffee.isSelected())
- coffeeCost = REGULAR_COFFEE;
- else if (decafCoffee.isSelected())
- coffeeCost = DECAF_COFFEE;
- else if (cappuccino.isSelected())
- coffeeCost = CAPPUCCINO;
- return coffeeCost;
- }
- }
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class BBH_OrderCalc extends JFrame {
- private BBH_BagelPanel bagels;
- private BBH_ToppingPanel toppings;
- private BBH_CoffeePanel coffee;
- private BBH_GreetingPanel banner;
- private JPanel buttonPanel;
- private JButton calcButton;
- private JButton exitButton;
- private final double TAX_RATE = 0.06;
- public BBH_OrderCalc() {
- setTitle("BBH Order Calculator");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLayout(new BorderLayout());
- banner = new BBH_GreetingPanel();
- bagels = new BBH_BagelPanel();
- toppings = new BBH_ToppingPanel();
- coffee = new BBH_CoffeePanel();
- buildButtonPanel();
- add(banner, BorderLayout.NORTH);
- add(bagels, BorderLayout.WEST);
- add(toppings, BorderLayout.CENTER);
- add(coffee, BorderLayout.EAST);
- add(buttonPanel, BorderLayout.SOUTH);
- pack();
- setVisible(true);
- }
- private void buildButtonPanel() {
- buttonPanel = new JPanel();
- calcButton = new JButton("Calculate Order");
- exitButton = new JButton("Exit");
- calcButton.addActionListener(new CalcButtonListener());
- exitButton.addActionListener(new ExitButtonListener()); //Error present
- buttonPanel.add(calcButton);
- buttonPanel.add(exitButton);
- }
- private class CalcButtonListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- double subtotal, tax, total;
- subtotal = bagels.getBagelCost() +
- toppings.getToppingCost() +
- coffee.getCoffeeCost();
- tax = subtotal * TAX_RATE;
- total = subtotal + tax;
- JOptionPane.showMessageDialog(null,
- String.format("Subtotal: $%,.2fn" +
- "Tax: $%,.2fn" +
- "Total: $%,.2f",
- subtotal, tax, total));
- private class ExitButtonListener implements ActionListener { //Error present
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- }
- }
- public static void main(String[] args) {
- new BBH_OrderCalc();
- }
- }
- Exception in thread "main" java.lang.Error: Unresolved compilation problem:
- ExitButtonListener cannot be resolved to a type
- at BBH_OrderCalc.buildButtonPanel(BBH_OrderCalc.java:50)
- at BBH_OrderCalc.<init>(BBH_OrderCalc.java:28)
- at BBH_OrderCalc.main(BBH_OrderCalc.java:86)
Add Comment
Please, Sign In to add comment