import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/**
<applet code=”ColorPalatte” width=500 height=500>
</applet>
*/
public class ColorPalatte extends Applet implements ActionListener
{
Button red,green,blue;
Checkbox c1,c2;
CheckboxGroup cbg;
TextArea ta;
Image im1;
public void init()
{
ta=new TextArea(“Welcome\nTo\nJava\nProgramming”,50,50,TextArea.SCROLLBARS_BOTH);
cbg=new CheckboxGroup();
im1=getImage(getDocumentBase(),”Vista08”);
red=new Button(“Red”);
green=new Button(“Green”);
blue=new Button(“Blue”);
red.addActionListener(this);
green.addActionListener(this);
blue.addActionListener(this);
c1=new Checkbox(“Background”,cbg,true);
c2=new Checkbox(“Foreground”,cbg,false);
add(ta);
add(red);
add(green);
add(blue);
add(c1);
add(c2);
}
public void actionPerformed(ActionEvent ae)
{
if(c1.getState())
{
if(ae.getSource()==red)
{
ta.setBackground(Color.red);
}
else if(ae.getSource()==green)
{
ta.setBackground(Color.green);
}
else
{
ta.setBackground(Color.blue);
}
}
else if(c2.getState())
{
if(ae.getSource()==red)
{
ta.setForeground(Color.red);
}
else if(ae.getSource()==green);
{
ta.setFoerground(Color.green);
}
else
{
ta.setForeground(Color.blue);
}
}
}
public void paint(Graphics g)
{
g.drawImage(im1,0,0,this);
}
}
No comments:
Post a Comment