1.3 Built an applet that displays a horizontal rectangle in its center. Let the rectangle fill with color from left to right.

FillingRect.java

import java.applet.*;
import java.awt.*;
/*
<applet code="FillingRect.class" width=600 height=400>
</applet>
*/
public class FillingRect extends Applet
{
public void paint(Graphics g)
{
Dimension d=getSize();
int x = d.width/2;
int y = d.height/2;
g.setColor(Color.green);
g.drawRect(x-25,y-25,100,50);
for(int i=100;i<200;i++)
{
try
{
Thread.sleep(30);
g.fillRect(i+(x-125),y-25,5,50);
}
catch(Exception e){}
}
}
}

Output


Try this code to see output with animation.

Happy Coding :)