cannot find symbol
symbol : class InvalidColorException
location: class unit7project.JColorChange
else throw new InvalidColorException(answer);
symbol : class InvalidColorException
location: class unit7project.JColorChange
catch (InvalidColorException error){
2 errors
Now this code is similar to examples in my book and provided by the instructor. In fact at this point in an effort to at least get it running I am using a replica of one example to see if it could show me what I was doing wrong...and I am here so it did not help...haha.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*/
public class JColorChange extends JApplet implements ActionListener{
//declare necessary labels
JLabel header = new JLabel("Please enter your color choice.");
JLabel errortxt = new JLabel("");
//declare necessary textfield and button
JTextField userInput = new JTextField(20);
JButton select = new JButton("Select");
//declare necessary strings
String answer;
String redString = "red";
String whiteString = "white";
String blueString = "blue";
//create container
Container con = getContentPane();
public void init() {
//populate container
con.add(header);
con.add(userInput);
con.add(select);
con.add(errortxt);
//set container layout
con.setLayout(new FlowLayout());
//add action listener to button
select.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
//get user input from text field
answer = userInput.getText();
//try block to ensure data is valid or throw exception
try{
errortxt.setText("");
if(redString.equalsIgnoreCase(answer)){
getContentPane().setBackground(Color.RED);
}
else if(blueString.equalsIgnoreCase(answer)){
getContentPane().setBackground(Color.BLUE);
}
else if(whiteString.equalsIgnoreCase(answer)){
getContentPane().setBackground(Color.WHITE);
}
else throw InvalidColorException(answer);
}
catch (InvalidColorException error){
errortxt.setText("No color available");
getContentPane().add(errortxt);
}
}
}
Any help would be appreciated

New Topic/Question
Reply




MultiQuote









|