JAVA code attached with explanation
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.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Colors extends JApplet implements ActionListener //make the class
{
private GridLayout layout = new GridLayout(3, 1);
JPanel panel02 = new JPanel(new FlowLayout()); //make panels
JPanel panel03 = new JPanel(new FlowLayout());
JPanel panel04 = new JPanel(new FlowLayout());
Container con = getContentPane();
FlowLayout Lay = new FlowLayout(FlowLayout.CENTER);
JLabel head = new JLabel("Please enter a color");
JTextField choice = new JTextField("",10);
JButton enter = new JButton("Press After Typing");
JLabel error = new JLabel("");
JPanel pane = new JPanel() ; //make a new panel
public void init()
{
con.setLayout(layout);//set the layout
con.add(panel02);
con.add(panel03);
con.add(panel04);
panel02.add(head);
panel03.add(choice);
panel03.add(enter);
enter.addActionListener(this);
panel04.add(error);
}
public static Color getColor(String cn)
choice = cn;
{
try
{
if(cn == red)
panel02.setBackground(Color.RED);
else
if(cn == blue)
panel03.setBackground(Color.BLUE);
else
if(cn == white)
panel04.setBackground(Color.WHITE);
}
catch(Exception ex)
{
error.setText("Wrong Color Choice");
}
}
}
errors i get
Colors.java:42: ';' expected
public static Color getColor(String cn)
^
Colors.java:101: class, interface, or enum expected
}
^
2 errors
Re: JAVA code attached with explanation
i fixed it thank you though