Two Errors in Java code Please help?

Hi could someone please assist me in correcting these two errors?

code: import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Label.*;

public class Freddie extends Applet implements ItemListener
{
//Construct Components
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(sizePromptLabel);
add(sandwichInputField);
add(sizePromptLabel);
add(catsupBox);
catsupBox.addItemListener(this);
add(mustardBox);
mustardBox.addItemListener(this);
add(picklesBox);
picklesBox.addItemListener(this);
add(sizeGroupBox);
sizeGroupBox.addItemListener(this);
add(smallBox);
smallBox.addItemListener(this);
add(mediumBox);
mediumBox.addItemListener(this);
add(largeBox);
largeBox.addItemListener(this);
}

public void itemStateChanged(ItemEvent choice)
{
}
}

Errors: C:\Course Technology\59850d\Chapter 04\Freddie.java:22: incompatible types
found : java.awt.TextField
required: java.awt.Label
Label sandwichInputField = new TextField("Input");
^
C:\Course Technology\59850d\Chapter 04\Freddie.java:36: cannot find symbol
symbol : variable red
location: class Freddie
setBackground(red);
^
2 errors

Thank You :-)

?2012-02-06T06:24:09Z

Favorite Answer

as for setbackgroung it should be

setBackground(color.red);


and how label is = to a new text field
it should be
TextField sandwichInputField = new TextField("Input");


other people are copying my solution into their answer to this question !? come on !

MANOJ2012-02-06T06:25:00Z

import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Color;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class Freddie extends Applet implements ItemListener
{
//Construct Components
Label sandwichPromptLabel = new Label("sandwich");
TextField 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(Color.RED);
add(sizePromptLabel);
add(sandwichInputField);
add(sizePromptLabel);
add(catsupBox);
catsupBox.addItemListener(this);
add(mustardBox);
mustardBox.addItemListener(this);
add(picklesBox);
picklesBox.addItemListener(this);
add(sizeGroupBox);
sizeGroupBox.addItemListener(this);
add(smallBox);
smallBox.addItemListener(this);
add(mediumBox);
mediumBox.addItemListener(this);
add(largeBox);
largeBox.addItemListener(this);
}

public void itemStateChanged(ItemEvent choice)
{
}
}

http://javacodespot.blogspot.com/

AnalProgrammer2012-02-06T08:18:44Z

Well the first error is quite obvious. You even have the line number of the error.
The second one should be
setBackground(Color.RED);
Though this works too.
setBackground(Color.red);


Perhaps you should look into using either Eclipse, Netbeans or Notepad++.

Have fun.