Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to create an applet that displays an interface related to fast-food sandwiches created at a fast-food company using Checkboxes.

After compiling the program, I receive the following errors:

C:\Java 1\New folder (2)\Chapter 04\Freddie.java:41: illegal start of expression
public void itemStateChanged(ItemEvent choice)
^
C:\Java 1\New folder (2)\Chapter 04\Freddie.java:43: ';' expected
}
^

What I have tried:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Freddie extends Applet implements ItemListener
{
	Label sandwichPromptLabel = new Label("sandwich");
	Label sandwichInputField = new TextField("Input");
	Label sizePromptLabel = new Label("Size");

	CheckboxGroup sandwichGroup = new CheckboxGroup();
	Checkbox catsupBox = new Checkbox("catsup",false,sandwichGroup);
	Checkbox mustardBox = new Checkbox("mustard",false,sandwichGroup);
	Checkbox picklesBox = new Checkbox("pickles",false,sandwichGroup);
	Checkbox sizeGroupBox = new Checkbox("sizeGroup",true,sandwichGroup);
	Checkbox smallBox = new Checkbox("small",false,sandwichGroup);
	Checkbox mediumBox = new Checkbox("medium",false,sandwichGroup);
	Checkbox largeBox = new Checkbox("large",false,sandwichGroup);

	public void init()
	{
		setBackground(red);
		add(promptLabel);
		add(inputField);
		add(size);
		add(catsup);
		add(mustard);
		add(pickles);
		add(sizeGroup);
		add(small);
		add(medium);
		add(large);

		public void itemStateChanged(ItemEvent choice) //First Error
		{}
	} //Second Error
}
Posted
Updated 21-Aug-18 10:46am
Comments
Kornfeld Eliyahu Peter 21-Aug-18 16:36pm    
Method inside a method?

1 solution

May be you should not define a function inside another function.
The positions of all the '{' and '}' matters.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900