This applet program needs an html file to run. You should supply the file along with the program so that the reader can test it.
import java.applet.*;
import java.awt.*;
public class DrawRectangles extends Applet {
int width, height;
public void init() {
width = getSize().width;
height = getSize().height;
setBackground( Color.white );
}
public void paint( Graphics g ) {
//(back, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white and yellow)
drawRectangle(g,Color.black,10,10);
drawRectangle(g,Color.blue,10,40);
drawRectangle(g,Color.cyan,10,70);
drawRectangle(g,Color.darkGray,10,100);
drawRectangle(g,Color.pink,10,130);
drawRectangle(g,Color.green,10,170);
drawRectangle(g,Color.lightGray,10,200);
drawRectangle(g,Color.magenta,10,230);
drawRectangle(g,Color.orange,10,260);
drawRectangle(g,Color.red,10,290);
drawRectangle(g,Color.white,10,320);
drawRectangle(g,Color.yellow,10,350);
drawRectangle(g,Color.gray,10,380);
}
public void drawRectangle(Graphics g,Color c,int x,int y)
{
g.setColor( c );
g.fillRect( x, y, 280, 280 );
}
}
Attachment:- DrawRectangles.zip