Answer to Question #45913 in Java | JSP | JSF for myu3438

Question #45913
Help me with my code so if the tortilla chips is checked it should display its extras cost and description.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class MyProgram extends JFrame implements ActionListener{
public JCheckBox bp,tchips,csoup,cpasta,
gbread;
public JTextField itemcost;
public JTextArea itemdesc;
public JLabel idesc,icost,extras;
public MyProgram(){
Container pane=getContentPane();
pane.setLayout(null);

pane.add(extras=new JLabel("Extras"));
extras.setBounds(34,50,70,20);
pane.add(bp=new JCheckBox("Baked Potato"));
bp.setBounds(30,80,150,20);
bp.setOpaque(false);
//baked potato description: oven baked potato halves
//item cost: $4.00
pane.add(tchips=new JCheckBox("Tortilla Chips"));
tchips.setBounds(30,110,150,20);
tchips.setOpaque(false);
//Tortilla Chips description: light & crispy corn chips
//item cost: $10.90

pane.add(csoup=new JCheckBox("Chicken Soup"));
csoup.setBounds(30,140,150,20);
csoup.setOpaque(false);
//chicken soup description: with
1
Expert's answer
2014-09-11T06:24:06-0400
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class MyProgram extends JFrame implements ActionListener {

public JCheckBox bp, tchips,csoup, cpasta,
gbread;
public JTextField itemcost;
public JTextArea itemdesc;
public JLabel idesc, icost,extras;
public JButton checkButton =new JButton("Check");

public MyProgram() {
Container pane =getContentPane();
pane.setLayout(null);
setPreferredSize(newDimension(250, 250));

pane.add(extras = newJLabel("Extras"));
extras.setBounds(34, 50,70, 20);
pane.add(bp = newJCheckBox("Baked Potato"));
bp.setBounds(30, 80, 150,20);
bp.setOpaque(false);
//baked potatodescription: oven baked potato halves
//item cost: $4.00
pane.add(tchips = newJCheckBox("Tortilla Chips"));
tchips.setBounds(30, 110,150, 20);
tchips.setOpaque(false);
//Tortilla Chipsdescription: light & crispy corn chips
//item cost: $10.90

pane.add(csoup = newJCheckBox("Chicken Soup"));
pane.add(checkButton);
checkButton.setBounds(30,170, 150, 20);
csoup.setBounds(30, 140,150, 20);
csoup.setOpaque(false);
//chicken soupdescription: with
checkButton.addActionListener(this);
pack();
}

@Override
public voidactionPerformed(ActionEvent e) {
if (tchips.isSelected()){
JOptionPane.showMessageDialog(null,"Tortilla chips cost: $10.90\nDescription: light & crispy corn
chips");
}
}

public static voidmain(String[] args) {
MyProgram gui = newMyProgram();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setVisible(true);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
09.09.14, 16:32

Dear visitor, Please submit your question to some online fileshare storage and provide us with the link to your source code.

45913
08.09.14, 16:09

(continue) steamed chicken and white soup //item cost: $4.90 pane.add(cpasta=new JCheckBox("Chicken Pasta")); cpasta.setBounds(30,170,150,20); cpasta.setOpaque(false); //chicken pasta description: chicken strips and roasted peanuts //item cost: $6.00 pane.add(gbread=new JCheckBox("Garlic Bread")); gbread.setBounds(30,200,150,20); gbread.setOpaque(false); //garlic bread description: baked oven sprinkled garlic //item cost: $4.98 pane.add(icost=new JLabel("Extras cost")); icost.setBounds(160,50,100

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS