JAVA Help - Background change by color matching
I have a JTextField and a jbutton and when i enter data on the field and hit the button i want the back ground to change color if the color matches the ones stored. How do i verify that the color matches the stored color?
public void actionPerformed(ActionEvent e) //make the actions
{
String red, white, blue;
Object source = e.getSource(); //get the source
String aColor = choice.getText();
if(aColor == "red")
panel02.setBackground(Color.RED);
//panel02.setBackground(Color.RED);
//panel03.setBackground(Color.BLUE);
//panel04.set
//catch(Exception ex)
//
// error.setText("Wrong Color Choice");
// }
}
the // are parts that dont work and neither does the color check but when the color check is removed the panes change color to the stored ones.
Re: JAVA Help - Background change by color matching
what i need is the following:
Create an applet that has a JTextField for the user to enter the name of a color. If the color entered is not either red, white, blue, then your applet should throw an Exception and tell the user the color entered was not valid. Otherwise change the background color to the appropriate color.
Re: JAVA Help - Background change by color matching
Quote:
Originally Posted by
Daren
what i need is the following:
Create an applet that has a JTextField for the user to enter the name of a color. If the color entered is not either red, white, blue, then your applet should throw an Exception and tell the user the color entered was not valid. Otherwise change the background color to the appropriate color.
So in that case, my assumption would be best as per your need. You just use
Syntax: public static Color getColor(String nm)
where nm - the name of the color property
You except the user entered color in "nm" and check if that color matches your requirement. If yes then do what you need, else through an exception.
Its very simple, isn't it?