Java - Applet - drawLine

The drawLine() method in Java Applet is used to draw a straight line between two points on the applet window. The method takes in four arguments, which are the X and Y coordinates of the starting point and the X and Y coordinates of the ending point.

Here's an example code that demonstrates the drawLine() method:

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

public class LineExample extends Applet {
    public void paint(Graphics g) {
        // Draw a line from (10, 10) to (200, 100)
        g.drawLine(10, 10, 200, 100);
    }
}

In this example, we create a class called LineExample that extends the Applet class. We then override the paint() method, which is where we will draw our line. Inside the paint() method, we call the drawLine() method on the Graphics object, which is passed in as a parameter.

The drawLine() method takes four arguments: the X and Y coordinates of the starting point (10, 10), and the X and Y coordinates of the ending point (200, 100). This will draw a line from the point (10, 10) to the point (200, 100).

You can modify the X and Y coordinates to draw a line in a different location on the applet window.