Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Closed Thread
Thread Tools Search this Thread
Old 12-05-2009
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

public static Color getColor(String cn)
choice = cn;
if(cn == red)

if(cn == blue)


if(cn == 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
Old 13-05-2009
Join Date: Feb 2009
Posts: 96
Re: JAVA code attached with explanation

i fixed it thank you though
Closed Thread

  TechArena Community > Software > Software Development
Tags: ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "JAVA code attached with explanation"
Thread Thread Starter Forum Replies Last Post
help me to understand java code (calendar java code) ? so0oma Software Development 2 10-01-2011 12:01 AM
help with java code unikshegz Software Development 2 24-10-2010 02:47 PM
Use Java code in PHP Gajendra1 Software Development 6 12-08-2010 10:18 AM
Need Explanation for java code javainfo Software Development 2 10-12-2009 01:56 AM
need explanation on nested group code vivekmohan Software Development 4 30-06-2009 03:09 PM

All times are GMT +5.5. The time now is 09:00 PM.