For a JFrame, you must add a drawing method that starts when the JVM is ready to draw the JFrame inside the class that inherits the JFrame class. Then, inside this, you would call the drawing method “drawLine” as shown (make sure the “Graphics” class has been imported and replaced X1, Y1, X2, Y2 with integers of your choice.):
public void paint(Graphics g) {
g.drawLine(X1,X2,Y1,Y2);
}
source
share