Question

PLEASE HELP DEBUG. IN JAVA! // Beverage selector // Milk and cola are $3 // all...

PLEASE HELP DEBUG. IN JAVA!

// 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 uses 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 DebugFourteen4
{
super("Beverage Selector");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(flow);
add(cola);
cola.addItemListener(this);
add(lemon);
lemon.addItemListener(this);
add(tea);
tea.addItemListener(this);
add(milk);
milk.addItemListener(this);
add(coffee);
coffee.addItemListener(this);
add(totPrice);

drinkGrp.add(cola);
drinkGrp.add(lemon);
drinkGrp.add(milk);
drinkGrp.add(tea);
drinkGrp.add(coffee);
totPrice.setText("0");
}
public static void main(String[] arguments)
{
JFrame bFrame = DebugFourteen4();
bFrame.setSize(350, 100);
bFrame.setVisible(true);
}
@Override
public void itemStateChanged(ItemEvent check)
{
Object source = checkgetItem();
if(source == cola || source == milk)
{
totPrice.setText("$" + HIGH_PRICE);
}
else
{
totPrice.setText("$" + LOWEST_PRICE);
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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 DebugFourteen4() {
       super("Beverage Selector");
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setLayout(flow);
       add(cola);
       cola.addItemListener(this);
       add(lemon);
       lemon.addItemListener(this);
       add(tea);
       tea.addItemListener(this);
       add(milk);
       milk.addItemListener(this);
       add(coffee);
       coffee.addItemListener(this);
       add(totPrice);

       drinkGrp.add(cola);
       drinkGrp.add(lemon);
       drinkGrp.add(milk);
       drinkGrp.add(tea);
       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);
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
PLEASE HELP DEBUG. IN JAVA! // Beverage selector // Milk and cola are $3 // all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...

    import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {    public static void createAndShowGUI() {        JFrame frame = new JFrame("Q1");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Font courierFont = new Font("Courier", Font.BOLD, 40);        Font arialFont = new Font("Arial", Font.BOLD, 40);        Font sansFont = new Font("Sans-serif", Font.BOLD, 20);        JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);        Font font1 = new Font("Sans-serif", Font.BOLD, 40);       ...

  • How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

    How can i make the java class seperate into an MVC pattern? public class ChatView implements ActionListener {    public static void main(String[] args)    {        JFrame chatFrame = new JFrame();        JFrame chatFrame1 = new JFrame();        JFrame chatFrame2 = new JFrame();               JPanel chatPanel = new JPanel();        JPanel chatPanel1 = new JPanel();        JPanel chatPanel2 = new JPanel();        chatFrame.setContentPane(chatPanel);        chatFrame1.setContentPane(chatPanel1);        chatFrame2.setContentPane(chatPanel2);        chatFrame.setLayout(new FlowLayout());        chatFrame1.setLayout(new FlowLayout());        chatFrame2.setLayout(new FlowLayout());        JTextField chatWrite = new JTextField();        JTextField chatWrite1 = new JTextField();        JTextField chatWrite2 = new JTextField();        JTextArea chatDisplay...

  • Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with...

    Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) {     myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame {    myJPanel6 p6;    public myJFrame6 ()    {        super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField        p6 = new myJPanel6(); //------------------------------------------------------...

  • Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame(&#3...

    Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame("Lab"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("Sans-serif", Font.BOLD, 20); JLabel label = new JLabel("Enter a word"); label.setFont(font); JTextField textField = new JTextField(10); textField.setFont(font); JButton button = new JButton("Enter"); button.setFont(font); Font font1 = new Font("Sans-serif", Font.BOLD, 30); JCheckBox sansSerif = new JCheckBox("Sans-serif"); sansSerif.setFont(font1); JCheckBox serif= new JCheckBox("Serif"); serif.setFont(font1); Font font2 = new Font("Sans-serif", Font.ITALIC, 15); JRadioButton...

  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • Please design a Java GUI application with two JTextField for user to enter the first name...

    Please design a Java GUI application with two JTextField for user to enter the first name and last name. Add two JButtons with action events so when user click on one button to generate a full name message from the user input and put it in a third JTextField which is not editable; and click on the other button to clear all three JTextField boxes. Please run the attached nameFrame.class file (Note: because there is an actionhandler inner class in...

  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

  • Java question so right now this code is work perfectly the problem is I also want...

    Java question so right now this code is work perfectly the problem is I also want to know if possible to get the X and Y value outside the JFrame? import java.awt.FlowLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JLabel; public class MouseEventDemo extends JFrame implements MouseListener { //It is a class which generate a JFrame and implements MouseListener interface //These all are text that show x , y coordinates on mouse click event JLabel lclick; JLabel lpressed; JLabel lreleased;...

  • Java please answer A and B a.         Describe the purpose of action listener in push button...

    Java please answer A and B a.         Describe the purpose of action listener in push button jbtnCompare.(from the code below) b.         Explain why there are not action listeners added to text fields of this program.(from the code below) code import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; class SwingFC implements ActionListener { JTextField jtfFirst; // holds the first file name JTextField jtfSecond; // holds the second file name JButton jbtnComp; // button to compare the files JLabel jlabFirst, jlabSecond; //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT