Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

How does the disposition effect impact investors' tax obligations?

Answered: 1 week ago

Question

what is a peer Group? Importance?

Answered: 1 week ago