Menu

[Solved]Java Programming Please Help Following Errors Thank Code Class Ordercalculatorguiv2 Exten Q37155630

Java Programming.

Please help with the following errors. Thank you.

Exception in thread main java.lang.Error: Unresolved compilation problem: Cannot instantiate the type ExitButtonListener at

Code:

class OrderCalculatorGUIv2 extends JFrame
{
private JPanel bagelPanel; // Bagel panel
private JPanel toppingPanel; // Topping panel
private JPanel coffeePanel; // Coffee panel
private JPanel greetingPanel; // To display a greeting
private JPanel buttonPanel; // To hold the buttons

private JButton calcButton; // To calculate the cost
private JButton exitButton; // To exit the application

private JLabel greeting; // For the greetingPanel

private JRadioButton whiteBagel; // To select white
private JRadioButton wheatBagel; // To select wheat
private ButtonGroup bagelBg; // Radio button group

private JRadioButton noCoffee; // To select no coffee
private JRadioButton regularCoffee; // To select regularcoffee
private JRadioButton decafCoffee; // To select decaf
private JRadioButton cappuccino; // To select cappuccino
private ButtonGroup coffeeBg; // Radio button group

private JCheckBox creamCheese; // To select cream cheese
private JCheckBox butter; // To select butter
private JCheckBox peachJelly; // To select peach jelly
private JCheckBox blueberryJam; // To select blueberry jam

private final double TAX_RATE = 0.07; // Sales tax rate

public OrderCalculatorGUIv2() {

setTitle(“Order Calculator”);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new BorderLayout());

buildGreetingPanel();
buildBagelPanel();
buildToppingPanel();
buildCoffeePanel();

// Create the button panel.
buildButtonPanel();

add(greetingPanel, BorderLayout.NORTH);
add(bagelPanel, BorderLayout.WEST);
add(toppingPanel, BorderLayout.CENTER);
add(coffeePanel, BorderLayout.EAST);
add(buttonPanel, BorderLayout.SOUTH);

pack();
setVisible(true);
}

private void buildButtonPanel() {

buttonPanel = new JPanel();

calcButton = new JButton(“Calculate”);
exitButton = new JButton(“Exit”);

calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());

buttonPanel.add(calcButton);
buttonPanel.add(exitButton);
}

private void buildBagelPanel() {

bagelPanel = new JPanel();

bagelPanel.setLayout(new GridLayout(2, 1));

whiteBagel = new JRadioButton(“White”, true);
wheatBagel = new JRadioButton(“Wheat”);

bagelBg = new ButtonGroup();
bagelBg.add(whiteBagel);
bagelBg.add(wheatBagel);

bagelPanel.setBorder(BorderFactory.createTitledBorder(“Bagel”));

bagelPanel.add(whiteBagel);
bagelPanel.add(wheatBagel);
}

private void buildGreetingPanel() {
// Create a panel for greeting
greetingPanel = new JPanel();

greeting = new JLabel(“Welcome to Brandi’s Bagel House”);

greetingPanel.add(greeting);
}

private void buildCoffeePanel() {

coffeePanel = new JPanel();

coffeePanel.setLayout(new GridLayout(4, 1));

noCoffee = new JRadioButton(“None”);
regularCoffee = new JRadioButton(“Regular coffee”, true);
decafCoffee = new JRadioButton(“Decaf coffee”);
cappuccino = new JRadioButton(“Cappuccino”);

coffeeBg = new ButtonGroup();
coffeeBg.add(noCoffee);
coffeeBg.add(regularCoffee);
coffeeBg.add(decafCoffee);
coffeeBg.add(cappuccino);

coffeePanel.setBorder(BorderFactory.createTitledBorder(“Coffee”));

coffeePanel.add(noCoffee);
coffeePanel.add(regularCoffee);
coffeePanel.add(decafCoffee);
coffeePanel.add(cappuccino);
}

private void buildToppingPanel()
{

toppingPanel = new JPanel();

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”);
toppingPanel.setBorder(BorderFactory.createTitledBorder(“Toppings”));

toppingPanel.add(creamCheese);
toppingPanel.add(butter);
toppingPanel.add(peachJelly);
toppingPanel.add(blueberryJam);
}
}

///////////////////////////////////////////////////

public class CalcButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {

double subtotal, tax, total;

subtotal = getBagelCost() + getToppingCost() +getCoffeeCost();

tax = subtotal * TAX_RATE;

// Calculate the total.
total = subtotal + tax;

DecimalFormat dollar = new DecimalFormat(“0.00”);

JOptionPane.showMessageDialog(null, “Subtotal: $” +dollar.format(subtotal) + “n” + “Tax: $”
+ dollar.format(tax) + “n” + “Total: $” +dollar.format(total));
}
}

private double getBagelCost() {

final double WHITE_BAGEL = 1.25;
final double WHEAT_BAGEL = 1.50;

double bagelCost = 0.0;

if (whiteBagel.isSelected())
bagelCost = WHITE_BAGEL;
else
bagelCost = WHEAT_BAGEL;

return bagelCost;
}

private double getCoffeeCost() {

final double NO_COFFEE = 0.0;
final double REGULAR_COFFEE = 1.25;
final double DECAF_COFFEE = 1.25;
final double CAPPUCCINO = 2.00;

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;
}

private double getToppingCost() {

final double CREAM_CHEESE = 0.50;
final double BUTTER = 0.25;
final double PEACH_JELLY = 0.75;
final double BLUEBERRY_JAM = 0.75;

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;
}

}

//////////////////////////////////////////////

public abstract class ExitButtonListener implementsActionListener {
   public void actionPerformed(ActionEvent e) {
   System.exit(0);
   }
   }
///////////////////////////////////////////////

public class OrderCalculatorGUI {

public static void main(String[] args)
{
OrderCalculatorGUIv2 gui = new OrderCalculatorGUIv2();
}
}

Exception in thread “main” java.lang.Error: Unresolved compilation problem: Cannot instantiate the type ExitButtonListener at OrderCalculatorGUIv2.buildButtonPanel (OrderCalculatorGUIv2.java:77) at OrderCalculatorGUIv2.<init (OrderCalculatorGUIv2.java: 57) at OrderCalculatorGUI.main(OrderCalculatorGUI.java:4) Show transcribed image text Exception in thread “main” java.lang.Error: Unresolved compilation problem: Cannot instantiate the type ExitButtonListener at OrderCalculatorGUIv2.buildButtonPanel (OrderCalculatorGUIv2.java:77) at OrderCalculatorGUIv2.

Expert Answer


Answer to Java Programming. Please help with the following errors. Thank you. Code: class OrderCalculatorGUIv2 extends JFrame { pr… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *