Java - Applet - drawRect
The drawRect() method in Java Applet is used to draw a rectangle on the screen with the specified width and height. The syntax of the method is as follows:
public void drawRect(int x, int y, int width, int height)
where x and y are the starting point of the rectangle, and width and height are the dimensions of the rectangle.
Here's an example of how to use the drawRect() method in a Java Applet:
import java.applet.*;
import java.awt.*;
public class DrawRectExample extends Applet {
public void paint(Graphics g) {
g.drawRect(50, 50, 100, 50);
}
}
In this example, we are creating an applet that draws a rectangle with the drawRect() method. The starting point of the rectangle is (50, 50), and its dimensions are 100 pixels wide and 50 pixels high. The paint() method is overridden to draw the rectangle using the Graphics object.
The drawRect() method is just one of many methods available in the Graphics class for drawing shapes and lines in a Java Applet. By combining these methods, you can create complex drawings and animations within your applet.