Practical-3 Built an applet that displays a horizontal rectangle in its center. Let the rectangle fill with color from left to right.
import java.applet.*;
import java.awt.*;
public class Practical3 extends Applet {
public void paint(Graphics g)
{
int width=10, height=50;
g.drawRect(30, 70, 240, 50);
g.setColor(Color.red);
for (int i=1;i<25;i++)
{
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("Exception generated");
}
g.fillRect(30, 70, width, height);
width=width+10;
}
}
}
Output:
Comments
Post a Comment