Results 1 to 2 of 2

Thread: JAVA code attached with explanation

  1. #1
    Join Date
    Feb 2009
    Posts
    96

    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

  2. #2
    Join Date
    Feb 2009
    Posts
    96

    Re: JAVA code attached with explanation

    i fixed it thank you though

Similar Threads

  1. help me to understand java code (calendar java code) ?
    By so0oma in forum Software Development
    Replies: 2
    Last Post: 09-01-2011, 11:01 PM
  2. help with java code
    By unikshegz in forum Software Development
    Replies: 2
    Last Post: 24-10-2010, 02:47 PM
  3. Use Java code in PHP
    By Gajendra1 in forum Software Development
    Replies: 6
    Last Post: 12-08-2010, 10:18 AM
  4. Need Explanation for java code
    By javainfo in forum Software Development
    Replies: 2
    Last Post: 10-12-2009, 12:56 AM
  5. need explanation on nested group code
    By vivekmohan in forum Software Development
    Replies: 4
    Last Post: 30-06-2009, 03:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •