Java - Applet - fillRect
The fillRect() method of Java Applet is used to draw a solid rectangle on the screen. It takes four arguments: the x and y coordinates of the upper left corner of the rectangle, its width, and its height. Here is an example code snippet that demonstrates the usage of the fillRect() method:
import java.applet.*;
import java.awt.*;
public class MyFirstApplet extends Applet {
public void paint(Graphics g) {
g.setColor(Color.blue);
g.fillRect(50, 50, 100, 100);
}
}
In this example, we have created a class named MyFirstApplet that extends the Applet class. In the paint() method, we have created a Graphics object named g which is used to draw on the screen. We have set the color of the g object to blue using the setColor() method. Then we have drawn a filled rectangle with the fillRect() method with the x and y coordinates of (50,50), width of 100 pixels and height of 100 pixels.
When this applet runs, it will draw a blue rectangle on the screen at the location (50,50) with width 100 and height 100.