Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Beverage selector // Milk and cola are $3 // all other drinks are $2 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DebugFourteen4 extends

// Beverage selector // Milk and cola are $3 // all other drinks are $2 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DebugFourteen4 extends JFrame implements ItemListener { FlowLayout flow = new FlowLayout(); String title = new String("Beverage Selector"); Font bigFont = new Font("Arial", Font.PLAIN, 24); ButtonGroup drinkGrp = new ButtonGroup(); JCheckBox cola = new JCheckBox("Cola",false); JCheckBox lemon = new JCheckBox("Lemonade",false); JCheckBox tea = new JCheckBox("Iced tea"); JCheckBox milk = new JCheckBox("Milk"); JCheckBox coffee = new JCheckBox("Coffee"); JTextField totPrice = new JTextField(10); String output; int totalPrice = 0; final int HIGH_PRICE = 3; final int LOW_PRICE = 2; public FixDebugFourteen4() { super("Beverage Selector"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(flow); add(cola); cola.addItemListener(this); add(lemon); add(tea); tea.addItemListener(this); add(milk); milk.addItemListener(this); add(totPrice); drinkGrp.add(cola); drinkGrp.add(lemon); drinkGrp.add(milk); drinkGrp.add(coffee); totPrice.setText("0"); } public static void main(String[] arguments) { JFrame bFrame = new DebugFourteen4(); bFrame.setSize(350, 100); bFrame.setVisible(true); } @Override public void itemStateChanged(ItemEvent check) { Object source = check.getItem(); if(source == cola && source == milk) { totPrice.setText("$" + HIGH_PRICE); } else { totPrice.setText("$" + LOW_PRICE); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions