Here there is the source Code For It ...
//J8 applet
import java.awt.* ;
import java.awt.event.* ;
import java.applet.* ;
//===========================
public class J8 extends Applet implements ActionListener
{
// declare class variables
Panel P1,P2;
Button B1,B2;
Label L1,L2;
int ColorIndex;
Color[] Col = {Color.red,Color.blue,Color.yellow,Color.white,
Color.green,Color.orange,Color.pink};
int XU,YU;
public void init()//applet initializer
{
//create panel first
P1=new Panel();
P2=new Panel();
//create control Buttons and label
B1 = new Button(" Change Color ");
B2 = new Button(" Move Rectangle ");
L1 = new Label( "Control Button ");
L1.setForeground(Color.red);
// ad the controls to p1 , order is important
P1.add(L1);
P1.add(B1);
P1.add(B2);
// create L2 and add it to panel 2
L2 = new Label("-----------------------------------------------------");
P2.add(L2);
// add action lstener
B1.addActionListener(this);
B2.addActionListener(this);
setLayout(new BorderLayout());
add("North",P1);
add("South",P2);
ColorIndex = 0;
XU=10;
YU=10;
}
//overload the paint functioned
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Col[ColorIndex]);
g.fill3DRect(XU,YU,50,80,true);
g.setColor(Color.black);
g.drawString("Rect",XU,YU);
}
// Action handler
public void actionPerformed(ActionEvent ev)
{
Object source = ev.getSource();
if(source==B1)
OnB1();
else if(source==B2)
OnB2();
}
//member method to handle B1
private void OnB1()//any name you want
{
ColorIndex = (ColorIndex+1)%Col.length;
L2.setText("Color Button was clicked");
repaint();
}
//member method to handle B2
private void OnB2()//any name you want
{
XU=(XU+10)%200;
YU=(YU+10)%200;
L2.setText("Move Rectangular Button Was Clicked");
repaint();
}
}
//----------------------------------------------------------------------------End
Of Program !!!!!!