# Draw 3D Rectangle & Square in Applet Window Example

1. /*
2.         Draw 3D Rectangle & Square in Applet Window Example
3.         This java example shows how to draw 3-D rectangles and squares in an applet
4.         window using draw3DRect method of Graphics class. It also shows how to
5.         draw a filled 3-D rectangles and squares.
6. */
7.
8. /*
9. <applet code="Draw3DRectanglesExample" width=200 height=200>
10. </applet>
11. */
12.
13.
14. import java.applet.Applet;
15. import java.awt.Color;
16. import java.awt.Graphics;
17.
18. public class Draw3DRectanglesExample extends Applet{
19.
20.         public void paint(Graphics g){
21.
22.                 g.setColor(Color.green);
23.                 /*
24.                  * To draw a 3-D rectangle in an applet window use,
25.                  * void draw3DRect(int x1,int y1, int width, int height, boolean raised)
26.                  * method.
27.                  *
28.                  * This method draws a 3-D rectangle of specified width and
29.                  * height at (x1,y1)
30.                  */
31.
32.                 //this will draw a 3-D rectangle of width 50 & height 100 at (10,10)
33.                 g.draw3DRect(10,10,50,100,true);
34.
35.                 /*
36.                  * If you speficy same width and height, the draw3DRect method
37.                  * will draw a 3-D square!
38.                  */
39.
40.                 //this will draw a 3-D square
41.                 g.draw3DRect(100,100,50,50,true);
42.
43.                 g.setColor(Color.orange);
44.
45.                 /*
46.                  * To draw a filled 3-D rectangle in an applet window use,
47.                  * void fill3DRect(int x1,int y1, int width, int height, boolean raised)
48.                  * method.
49.                  *
50.                  * This method draws a filled 3-D rectangle of specified width and
51.                  * height at (x1,y1)
52.                  */
53.
54.                 //this will draw a filled 3-D rectangle of width 50 & height 100 at (10,10)
55.                 g.fill3DRect(10,150,50,100,true);
56.
57.                 /*
58.                  * If you speficy same width and height, the fill3DRect method
59.                  * will draw a filled 3-D square!
60.                  */
61.
62.                 //this will draw a filled 3-D square
63.                 g.fill3DRect(100,200,50,50,true);
64.
65.         }
66. }

Example Output