Thursday, 28 April 2011

JAVA PROGRAM TO IMPLEMENT COLOR SECTIONS


www.javalearing.blogspot.com importjava.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.compareTo(s3)==0)
  {
      setBackground(color.black);
  }
  else if (msg.compareTo(s4)==o)
  {
      setBackground(Color.blue);
  }
  else
  {
      set Background(Color.orange);
  }
 }
}
Java 2: The Complete Reference, Fifth Edition

No comments:

Post a Comment