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);
}
}
} |
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);
}
}
}
Editorial Team
We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.
thanx really wid these simple programs which r too easy to grasp…
plzz upload d code to implement spell checker using dictionary…
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);
}
}
}
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);
}
}
}
check the spelling it should be itemStateChanged(ItemEvent ie)