Question
I cannot get this code to compile or run. Please help! import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Tin_Of_Popcorn extends JFrame{ /**
I cannot get this code to compile or run.
Please help!
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Tin_Of_Popcorn extends JFrame{
/**
*
* @author Alexandrea
*/
public Tin_Of_Popcorn(){
super("Tin_Of_Popcorn");
setLayout(new BorderLayout());
JPanel labelPanel=new JPanel(new GridLayout(10,1));
JPanel fieldPanel=new JPanel(new GridLayout(10,1));
add(labelPanel,BorderLayout.WEST);
add(fieldPanel,BorderLayout.CENTER);
String[]sizetext = new String[] {"1 Gallon","2 Gallon","3 Gallon"};
String[]flavortext = new String[] {"plain", "cheese","caramel"};
String[]colortext = new String[] {"red","green","blue"};
Label size = new Label("Size:");
Label flavor= new Label("Flavor:");
Label color= new Label("Color:");
Label mixed= new Label("Mixed:");
Label price= new Label("Price:");
Label gift= new Label("Gift:");
Label gift_message= new Label("Gift Message:");
JComboBox CSize = new JComboBox(sizetext);
JComboBox CFlavor = new JComboBox(flavortext);
JComboBox CColor = new JComboBox(colortext);
JRadioButton opt1 = new JRadioButton("Yes");
JRadioButton opt2 = new JRadioButton("No");
JRadioButton opt3 = new JRadioButton("Yes");
JRadioButton opt4 = new JRadioButton("No");
TextField textField1 = new TextField("",5);
TextField textField2 = new TextField("",15);
final Button create = new Button("Create");
Button clear = new Button("Clear");
ButtonGroup group1 = new ButtonGroup();
group1.add(opt1);
group1.add(opt2);
ButtonGroup group2 = new ButtonGroup();
group2.add(opt3);
group2.add(opt4);
labelPanel.add(size);fieldPanel.add(CSize);
labelPanel.add(color); fieldPanel.add(CColor);
labelPanel.add(flavor);fieldPanel.add(CFlavor);
labelPanel.add(mixed); fieldPanel.add(opt1); fieldPanel.add(opt2);
labelPanel.add(price); fieldPanel.add(textField1);
labelPanel.add(gift); fieldPanel.add(opt3); fieldPanel.add(opt4);
labelPanel.add(gift_message);
fieldPanel.add(textField2);
labelPanel.add(create);
fieldPanel.add(clear);
JTextArea txtArea=new JTextArea(5,50);
add(txtArea,BorderLayout.SOUTH);
create.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent evt)
{
Object src = evt.getSource();
if(src == create)
{
Popcorn popcorn=new Popcorn(Integer.parseInt(CSize.getSelectedItem().toString().charAt(0)+""),CColor.getSelectedItem().toString()
,CFlavor.getSelectedItem().toString(),Boolean.parseBoolean(group1.getSelection().getActionCommand()),Double.parseDouble(textField1.getText()),Boolean.parseBoolean(group2.getSelection().getActionCommand()),gift_message.getText());
txtArea.setText(txtArea.getText()+" "+popcorn);
}
else if(src==clear)
fieldPanel.repaint();
} });
}
public static void main(String[] args)
{
Tin_Of_Popcorn tp=new Tin_Of_Popcorn();
tp.setSize (650,350);
tp.setVisible (true);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started