Fill Rectangle & Square in Applet Window Example /*         Fill Rectangle & Square in Applet Window Example  ...

Fill Rectangle & Square in Applet Window Example

03:04 PASSOVE INCOME 0 Comments

Fill Rectangle & Square in Applet Window Example

    1. /*
    2.         Fill Rectangle & Square in Applet Window Example
    3.         This java example shows how to draw filled rectangles and squares in an
    4.         applet window using fillRect method of Graphics class.
    5. */
    6. /*
    7. <applet code="FilledRectangleExample" width=200 height=200>
    8. </applet>
    9. */
    10. import java.applet.Applet;
    11. import java.awt.Color;
    12. import java.awt.Graphics;
    13. public class FilledRectangleExample extends Applet{
    14.         public void paint(Graphics g){
    15.                
    16.                 //set color to red
    17.                 setForeground(Color.red);
    18.                
    19.                 /*
    20.                  * to draw a filled rectangle in an applet window use,
    21.                  * void fillRect(int x1,int y1, int width, int height)
    22.                  * method.
    23.                  *
    24.                  * This method draws a filled rectangle of specified width and
    25.                  * height at (x1,y1)
    26.                  */
    27.                
    28.                 //this will draw a filled rectangle of width 50 & height 100 at (10,10)
    29.                 g.fillRect(10,10,50,100);
    30.                
    31.                 /*
    32.                  * If you speficy same width and height, the fillRect method
    33.                  * will draw a filled square!
    34.                  */
    35.                
    36.                 //this will draw a filled square
    37.                 g.fillRect(100,100,50,50);
    38.         }
    39. }
    Example Output

0 comments: