PROGRAM:
COLOR PALETTE:
import
java.awt.*;
import
java.applet.*;
import
java.awt.event.*;
//<applet
code="color1.class" height=400 width=450></applet>
public
class color1 extends Applet implements ItemListener
{
int
currcolor=5;
int
flag=1;
String
text="check any of the button";
Button
buttons[]=new Button[5];
String
colors[]={"Red","Blue","Green","Yellow","Orange"};
Image
img;
CheckboxGroup
cbg=new CheckboxGroup();
Checkbox
box1=new Checkbox("Background Color",cbg,true);
Checkbox
box2=new Checkbox("Text Color" ,cbg,false);
Checkbox
box3=new Checkbox("Loading Image",cbg,false);
public
void init(){
for(int
i=0;i<5;i++){
buttons[i]=new
Button(" ");
add(buttons[i]);}
buttons[0].setBackground(Color.red);
buttons[1].setBackground(Color.blue);
buttons[2].setBackground(Color.green);
buttons[3].setBackground(Color.yellow);
buttons[4].setBackground(Color.orange);
add(box1);
add(box2);
add(box3);
box1.addItemListener(this);
box2.addItemListener(this);
box3.addItemListener(this);}
public
void itemStateChanged(ItemEvent e){
if(box1.getState()==true)
flag=1;
else
if(box2.getState()==true){
text="defalult
color is black";
flag=2;}
else
if(box3.getState()==true){
img=getImage(getDocumentBase(),"purple-flowers.jpg");
flag=3;}
repaint();}
public
void paint(Graphics g){
if(flag==2){
g.drawString(text,30,100);
switch(currcolor){
case
0:g.setColor(Color.red);
break;
case
1:g.setColor(Color.blue);
break;
case
2:g.setColor(Color.green);
break;
case
3:g.setColor(Color.yellow);
break;
case
4:g.setColor(Color.orange);
break;}
g.drawString(text,30,100);}
else
if(flag==1){
g.drawString(text,30,100);
switch(currcolor){
case
0:setBackground(Color.red);
break;
case
1:setBackground(Color.blue);
break;
case
2:setBackground(Color.green);
break;
case
3:setBackground(Color.yellow);
break;
case
4:setBackground(Color.orange);
break;}}
else
if(flag==3){
g.drawImage(img,20,90,this);}}
public
boolean action(Event e, Object o){
for(int
i=0;i<5;i++){
if(e.target==buttons[i]){
currcolor=i;
text="you
have chosen "+colors[i];
repaint();
return
true;}}
return
false;}}
Color1.html
<html>
<applet
code="color1.class" height=200 width=320>
</applet>
</html>
No comments:
Post a Comment