Java program to implement a Color Section from a given set of Color.

To implement a Color Section from a given set of Color.

import java.awt*;
import java.awt.event.*;
import java.applet.*;
 
public class fillcolor extends Applet implement Item Listener
{
	checkbox red,yellow,black,blue.orange;
	CheckboxGroup cbg;
	String msg;
	String s1="red";
	String s2="yellow";
	String s3="black";
	String s4="orange";
	public void init()
	{
		cbg = new CheckboxGroup();
		red = new Chechbox("red",cbg,true);
		yellow= new Checkbox("yellow",cbg,false);
		black = new checkbox("black",cbg,false);
		blue = new Checkbox("blue",cbg,false);
		orange = new checkbox("orange".cbg.false);
		add(red);
		add(yellow);
		add(black);
		add(blue);
		add(orange);
		red.addItemListener(this);
		yellow.addItemListener(this);
		black.addItemListener(this);
		blue.addItemListener(this);
		orange.addItemListener(this);
	}
	publice void itemStartechanged(ItemEvent ie)
	{
		repaint();
	}
	publice void paint (Graphics g)
	{
		msg = cbg.getSelectedCheckbox().getLabel();
		if(msg.compareTo(s1)==0)
		{	
		    setBackground(Color.red);
		}
		else if (msg.compareTo(s2)==0)
		{
		    setBackground(Color.yellow);
		}
		else if(msg.compare To(s3)==0)
		{
		    setBackground(color.black);
		}
		else if (msg.compareTo(s4)==o)
		{
		    setBackground(Color.blue);
		}
		else
		{
		    set Background(Color.orange);
		}
	}
}

7 Responses to “Java program to implement a Color Section from a given set of Color.”

  1. shweta

    thanx really wid these simple programs which r too easy to grasp…

    Reply
  2. shweta

    plzz upload d code to implement spell checker using dictionary…

    Reply
  3. ohhhhh it has errors……. ofcourse i cleared. but one error is sucking……… !!!! :( :(

    fillcolor.java:5: fillcolor is not abstract and does not override abstract metho
    d itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
    public class fillcolor extends Applet implements ItemListener

    Reply
  4. contains lots of errors : i have solve it a bit bt a problm still there .

    import java.applet.Applet;
    import java.awt.Checkbox;
    import java.awt.CheckboxGroup;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;

    public class FillTheWindow extends Applet implements ItemListener{

    Checkbox red,yellow,black,blue,orange;
    CheckboxGroup cbg;
    String msg;
    String s1=”red”;
    String s2=”yellow”;
    String s3=”black”;
    String s4=”orange”;
    public void init()
    {
    cbg = new CheckboxGroup();
    red = new Checkbox(“red”,cbg,true);
    yellow= new Checkbox(“yellow”,cbg,false);
    black = new Checkbox(“black”,cbg,false);
    blue = new Checkbox(“blue”,cbg,false);
    orange = new Checkbox(“orange”,cbg,false);
    add(red);
    add(yellow);
    add(black);
    add(blue);
    add(orange);
    red.addItemListener(this);
    yellow.addItemListener(this);
    black.addItemListener(this);
    blue.addItemListener(this);
    orange.addItemListener(this);
    }
    public void itemStartechanged(ItemEvent ie)
    {
    repaint();
    }
    public void paint (Graphics g)
    {
    msg = cbg.getSelectedCheckbox().getLabel();
    if(msg.compareTo(s1)==0)
    {
    setBackground(Color.red);
    }
    else if (msg.compareTo(s2)==0)
    {
    setBackground(Color.yellow);
    }
    else if(msg.compareTo(s3)==0)
    {
    setBackground(Color.black);
    }
    else if (msg.compareTo(s4)==0)
    {
    setBackground(Color.blue);
    }
    else
    {
    setBackground(Color.orange);
    }
    }

    }

    Reply
  5. JITHIN MOHAN

    Lot of errors in the program i solved all and here is the corrected code..thanks for your code
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    /*

    */
    public class fillcolor extends Applet implements ItemListener
    {
    Checkbox red,yellow,black,blue,orange;
    CheckboxGroup cbg;
    String msg;
    String s1=”red”;
    String s2=”yellow”;
    String s3=”black”;
    String s4=”orange”;
    public void init()
    {
    cbg = new CheckboxGroup();
    red = new Checkbox(“red”,cbg,true);
    yellow= new Checkbox(“yellow”,cbg,false);
    black = new Checkbox(“black”,cbg,false);
    blue = new Checkbox(“blue”,cbg,false);
    orange = new Checkbox(“orange”,cbg,false);
    add(red);
    add(yellow);
    add(black);
    add(blue);
    add(orange);
    red.addItemListener(this);
    yellow.addItemListener(this);
    black.addItemListener(this);
    blue.addItemListener(this);
    orange.addItemListener(this);
    }
    public void itemStateChanged(ItemEvent ie)
    {
    repaint();
    }
    public void paint (Graphics g)
    {
    msg = cbg.getSelectedCheckbox().getLabel();
    if(msg.compareTo(s1)==0)
    {
    setBackground(Color.red);
    }
    else if (msg.compareTo(s2)==0)
    {
    setBackground(Color.yellow);
    }
    else if(msg.compareTo(s3)==0)
    {
    setBackground(Color.black);
    }
    else if (msg.compareTo(s4)==0)
    {
    setBackground(Color.blue);
    }
    else
    {
    setBackground(Color.orange);
    }
    }
    }

    Reply

Leave a Reply