Java Applet | Draw a line using drawLine() method Last Updated : 18 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report This article shall be explaining the code to draw a line using paint in Java. This uses drawLine() method. Syntax: drawLine(int x1, int y1, int x2, int y2) Parameters: The drawLine method takes four arguments: x1 - It takes the first point's x coordinate. y1 - It takes first point's y coordinate. x2 - It takes second point's x coordinate. y2 - It takes second point's y coordinate Result: This method will draw a line starting from (x1, y1) co-ordinates to (x2, y2) co-ordinates. Below programs illustrate the above problem: Example: Java // Java program to draw a line in Applet import java.awt.*; import javax.swing.*; import java.awt.geom.Line2D; class MyCanvas extends JComponent { public void paint(Graphics g) { // draw and display the line g.drawLine(30, 20, 80, 90); } } public class GFG1 { public static void main(String[] a) { // creating object of JFrame(Window popup) JFrame window = new JFrame(); // setting closing operation window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // setting size of the pop window window.setBounds(30, 30, 200, 200); // setting canvas for draw window.getContentPane().add(new MyCanvas()); // set visibility window.setVisible(true); } } Output : Note: The above function are a part of java.awt package and belongs to java.awt.Graphics class. Also, these codes might not run in an online compiler please use an offline compiler. The x1, x2, y1 and y2 coordinates can be changed by the programmer according to their need. Comment More infoAdvertise with us Next Article Java Applet | Draw a line using drawLine() method R rohitprasad3 Follow Improve Article Tags : Java Java Programs java-applet Practice Tags : Java Similar Reads Drawing a Line in a PDF Document using Java In this article, we will learn how to Draw a line in a PDF document using Java. For drawing a line in a PDF, we will use the iText library. These are the steps that should be followed to Draw a line in a PDF using java. 1. Creating a PdfWriter object The PdfWriter class represents the DocWriter for 3 min read Draw a ellipse and a rectangle in Java Applet Java applets are application that can be executed in web browsers or applet viewers . We can draw shapes on the Java applet. In this article we will draw a ellipse on Java applet by two ways . By using the drawOval(int x, int y, int width, int height) or by using mathematical formula (X= A * sin a, 4 min read How to Create Bezier Curve Animation Using Java Applet? An applet is a Java program that can be embedded into a web page. Applets are small Java applications that can be accessed on an Internet server, and transported over the Internet. Before getting into it let's check some software requirements Java SE Development Kit 8u361 by OracleTo Download JDK 8 6 min read Java Program to Print a New Line in String Java is the most powerful programming language, by which we can perform many tasks and Java is an industry preferable language. So it is filled with a huge amount of features. Here we are going to discuss one of the best features of Java, that is how to print a new line in a string using Java. Metho 3 min read Using Above Below Primitive to Test Whether Two Lines Intersect in Java Above Below Primitive is the method to check whether the lines are intersecting or not by comparing their endpoints. Here is a JAVA program which uses above below primitive to test whether two lines intersect with each other or not. This approach only returns true if one endpoint of the line is on t 3 min read Like