trying to get this program to run and getting an odd error...does anyone know what I have to do
//packages to import
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class PetAdviceApplet extends Applet implements ItemListener
{
//declare variables and construct components
int housing;
double hours;
String pet;
Label promptLabel = new Label ("Enter the average number of hours you are home per week ");
TextField hoursField = new TextField(15);
CheckboxGroup housingGroup = new CheckboxGroup();
Checkbox houseBox = new Checkbox("House", false, housingGroup);
Checkbox apartmentBox = new Checkbox("Apartment", false, housingGroup);
Checkbox dormitoryBox = new Checkbox("Dormitory", false, housingGroup);
Checkbox hiddenBox = new Checkbox("",true,housingGroup);
Label housingLabel = new Label ("Select your type of housing to determine the best pet ");
Label outputLabel = new Label("Enter a valid number of hours between 0 and 168 ");
public void init()
{
setBackground(Color.red);
setForeground(Color.black);
add(promptLabel);
add(hoursField);
hoursField.requestFocus();
hoursField.setForeground(Color.black);
add(houseBox);
houseBox.addItemListener(this);
add(apartmentBox);
apartmentBox.addItemListener(this);
add(dormitoryBox);
dormitoryBox.addItemListener(this);
add(housingLabel);
add(outputLabel);
} //end init()
//This method is triggered by the user clicking an option button
public void itemStateChanged(ItemEvent choice)
{
try
{
housing = getHousing();
hours = getHours() ;
pet = getPet(hours, housing);
output(pet);
} //end try
catch(NumberFormatException e)
{
outputLabel.setText("Enter a valid number for hours between 0 and 168 ");
hiddenBox.setState(true);
hoursField.setText("");
hoursField.requestFocus();
} //end catch
}
public double getHours()
{
double hours = Double.parseDouble(hoursField.getText());
if ((hours <= 0) || (hours >= 168)) throw new NumberFormatException();
return hours;
} //end getHours()
public int getHousing()
{
int housing = 0;
if (houseBox.getState()) housing = 1;
else
if (apartmentBox.getState()) housing = 2;
else
if (dormitoryBox.getState()) housing = 3;
return housing;
} //end getHousing()
public String getPet(double hours, int housing)
{
//declare method variables
String pet = "";
switch(housing)
{
case 1: //pot-bellied pig
if ((housing == 1) && (hours>=18))
{
pet = "Pot-bellied pig";
}
case 2: //dog
if((housing == 1) && (hours>=10) && (hours < 18))
{
pet = "Dog";
}
case 3: //snake
if ((housing == 1) && (hours < 10))
{
pet = "Snake";
}
case 4: //cat
if ((housing == 2) && (hours >= 10))
{
pet = "Cat";
}
case 5: //hamster
if ((housing == 2) && (hours < 10))
{
pet = "Hamster";
}
case 6: //fish
if ((housing == 3) && (hours >= 6))
{
pet = "Fish";
}
case 7: //ant farm
if ((housing == 3) && (hours < 6))
{
pet = "Ant farm";
}
break;
}//end switch
return pet;
}//end getComm
public void output(String pet)
{
outputLabel.setText ("According to your requirements, I would recommend a ",(pet));
} //end output
}//end class
this is the error.....
H:\JAVA\PetAdviceApplet.java:157: setText(java.lang.String) in java.awt.Label cannot be applied to (java.lang.String,java.lang.String)
outputLabel.setText ("According to your requirements, I would recommend a ",(pet));