Java AWT Line2D class

Description

Java AWT Line2D class

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

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {
  @Override//from  w  ww .j  a  va 2 s  . c o  m
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g; // cast g to Graphics2D

    // draw 2D lines in green and yellow
    g2d.setPaint(Color.GREEN);
    g2d.draw(new Line2D.Double(35, 30, 320, 150));
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame("Drawing 2D shapes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Main Main = new Main();
    frame.add(Main);
    frame.setSize(425, 200);
    frame.setVisible(true);
  }
}



PreviousNext

Related