The shapes applet


Define your own polygons, arcs, lines and ovals and fill them up with your own colors using multiple variations of the RGB Pattern. 


import java.applet.*;
import java.awt.*;
/*
<applet code="shapes" width = 300 height = 200>
</applet>
*/


public class rectangle extends Applet{
public void paint (Graphics g){

Color c1 = new Color (255,100,100);
Color c2 = new Color (155,200,70);
Color c3 = new Color (15,20,255);

g.setColor(c1);
g.drawRect(10,10,60,50);
g.fillRect(100,10,60,50);
g.drawRoundRect(190,10,60,50,15,15);
g.fillRoundRect(70,90,140,100,30,40);

g.setColor(c2);
g.drawOval(10,10,50,50);
g.fillOval(100,10,60,50);
g.drawOval(190,10,60,50);
g.fillOval(70,90,140,100);

g.setColor(c1);
g.drawArc(10,40,70,70,0,75);
g.fillArc(10,40,70,70,0,75);
g.drawArc(10,100,70,80,0,175);
g.fillArc(100,100,70,90,0,275);
g.drawArc(220,80,80,80,0,175);

}
}

Note : After you have studied the above code :
» Copy it onto your hard drive in Notepad or MS Word or any text editor. Save the file as "shapes.java".
» Open a new text document, mention the applet parameters within the html parameters and save this file as "shapes.html".
» Compile the .java file (from DOS  prompt if you are not using a visual editor like VJ++, etc.) to check for errors and to obtain the .class file.
» Run at DOS prompt, using the command : appletviewer shapes.java




Added on May 30, 2007 Comment
}