CHANGING BACKGROUND COLOR DYNAMICALLY
PROGRAM
import [Link].*;
import [Link].*;
import [Link].*;
/* <applet code="dynamicColor" width=300 height=350>
</applet>
*/
public class dynamicColor extends Applet implements
MouseListener,ItemListener,ActionListener,AdjustmentListener
{
Label demo,colorLabel,colorChoose,colorRadio,colorButton,colorScroll,coLabelChoice;
TextField colorText;
Checkbox redCheck,greenCheck,blueCheck;
CheckboxGroup cbg;
Checkbox redRadio,greenRadio,blueRadio;
Button redBut,greenBut,blueBut;
Scrollbar redScroll,greenScroll,blueScroll;
Choice colorChoice;
public void init()
{
demo=new Label("CHANGING BACKGROUND COLOR DYNAMICALLY");
coLabelChoice=new Label("Select Your Choice from Choice list ");
colorLabel=new Label("Enter Color : ");
colorText=new TextField(20);
colorChoose=new Label("Choose any color : ");
redCheck=new Checkbox("Red");
greenCheck=new Checkbox("Green");
blueCheck=new Checkbox("Blue");
colorRadio=new Label("Choose any color : ");
colorButton=new Label("Click any Button : ");
redBut=new Button("Red");
greenBut=new Button("Green");
blueBut=new Button("Blue");
colorScroll=new Label("Adjust ScrollBar to Change COLOR ");
redScroll=new Scrollbar([Link],0,5,0,255);
greenScroll=new Scrollbar([Link],0,5,0,255);
blueScroll=new Scrollbar([Link],0,5,0,255);
colorChoice=new Choice();
[Link]("Red");
[Link]("Green");
[Link]("Blue");
cbg=new CheckboxGroup();
redRadio=new Checkbox("Red",cbg,false);
greenRadio=new Checkbox("Green",cbg,false);
blueRadio=new Checkbox("Blue",cbg,false);
setLayout(new FlowLayout([Link]));
add(demo);
add(colorLabel);
add(colorText);
add(colorChoose);
add(redCheck);
add(greenCheck);
add(blueCheck);
add(colorRadio);
add(redRadio);
add(greenRadio);
add(blueRadio);
add(colorButton);
add(redBut);
add(greenBut);
add(blueBut);
add(colorScroll);
add(redScroll);
add(greenScroll);
add(blueScroll);
add(coLabelChoice);
add(colorChoice);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent ae)
{
if([Link]()==redBut)
setBackground([Link]);
else if([Link]()==greenBut)
setBackground([Link]);
else if([Link]()==blueBut)
setBackground([Link]);
else if([Link]()==colorText)
{
if([Link]().equals("red"))
setBackground([Link]);
else if([Link]().equals("green"))
setBackground([Link]);
else if([Link]().equals("blue"))
setBackground([Link]);
}
ChangeLabelColor();
}
public void itemStateChanged(ItemEvent ie)
{
Color c;
if([Link]()==true && [Link]()==true
&&[Link]()==true)
setBackground(new Color(255,255,255));
else if([Link]()==true && [Link]()==true
&&[Link]()==false)
setBackground(new Color(255,255,0));
else if([Link]()==true && [Link]()==false
&&[Link]()==true)
setBackground(new Color(255,0,255));
else if([Link]()==true && [Link]()==false
&&[Link]()==false)
setBackground(new Color(255,0,0));
else if([Link]()==false && [Link]()==true
&&[Link]()==true)
setBackground(new Color(0,255,255));
else if([Link]()==false && [Link]()==true
&&[Link]()==false)
setBackground(new Color(0,255,0));
else if([Link]()==false && [Link]()==false
&&[Link]()==true)
setBackground(new Color(0,0,255));
else if([Link]()==false && [Link]()==false
&&[Link]()==false)
setBackground(new Color(0,0,0));
ChangeLabelColor();
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
Color c=new
Color([Link](),[Link](),[Link]());
setBackground(c);
ChangeLabelColor();
}
public void ChangeLabelColor()
{
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
[Link](getBackground());
}
public void mouseClicked(MouseEvent me)
{
if([Link]()==redRadio)
setBackground([Link]);
else if([Link]()==greenRadio)
setBackground([Link]);
else if([Link]()==blueRadio)
setBackground([Link]);
else if([Link]()=="Red")
setBackground([Link]);
else if([Link]()=="Green")
setBackground([Link]);
else if([Link]()=="Blue")
setBackground([Link]);
ChangeLabelColor();
}
public void mouseEntered(MouseEvent me)
{}
public void mouseExited(MouseEvent me)
{}
public void mousePressed(MouseEvent me)
{}
public void mouseReleased(MouseEvent me)
{}
}
OUTPUT