Thursday 5 January 2017

Practical 3:Built an applet that display a horizontal rectangle in it's center.Let the rectangle fill with color from left to right.

Code:


import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;


/**
 *
 * @author Queue
 */
public class practical3 extends Applet  {

    public void init()
    {
        super.init();
        setSize(350,350);
    }
    public void paint(Graphics s)
    {
        int x1=100,y1=100,y2=50;
        s.setColor(Color.green);
        s.drawRect(100, 100, 100, 50);
      
        for(x1=100;x1<300;x1=x1+5)
        {
            try
            {
                Thread.sleep(1000);
                s.fillRect(x1, y1, 5, y2);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    } 

}


Output:

Thanks

Happy Coding ;)

1 comment: