Drawing a Line using Java 2D Graphics API : Line « 2D Graphics GUI « Java

Drawing a Line using Java 2D Graphics API


import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;

public class Main extends javax.swing.JFrame {

  public Main() {
    setSize(600, 600);

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Line2D lin = new Line2D.Float(100, 100, 250, 260);

  public static void main(String args[]) {
    new Main().setVisible(true);


Related examples in the same category

1.Line StylesLine Styles
2.Dash style line
3.Line dashes style 2
4.Lines Dashes style 3
5.Line Dash Style 4
6.Program to draw gridsProgram to draw grids
7.Xsplinefun displays colorful moving splines in a window
8.Draw a point: use a drawLine() method
9.A line is drawn using two points
10.Line-graph drawable
11.Draw Dashed
12.Draw Optimized Line
13.Draw with Line2D.Double and Ellipse2D.Double