by Dinesh Thakur

Point2D class does not draw anything; it is the representation of points Java2D. But yes you can draw shapes from points. Following is at able that lists some of the Constructors and methods of Point2D class:

Constructors and Methods


Point2D.Double ()

Creates a Point2D at (0, 0).

Point2D.Double (double X, double Y)

Creates a Point2D at (X, Y).

Point2D.Float ()

Creates a Point2D at (0, 0).

Point2D.Float (float X, float Y)

Creates a Point2D at (X, Y).

getX ()

Returns the horizontal coordinate of the point.

getY ()

Returns the vertical coordinate of the point.

Point2D.Float (float X, float Y)

Sets the location of the Point as (X, Y).

Drawingan Point2D exampleshownthecodeas follows:

import java.applet.Applet;

import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.image.*;
public class DrawPoint2DExample extends Applet {
public static void main(String[] args) {
Frame DrawPoint2D = new Frame("Draw Point2D Example");
DrawPoint2D.setSize(350, 250);
Applet DrawPoint2DExample = new DrawPoint2DExample();
DrawPoint2D.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
  public void paint(Graphics g) {
    g.setFont(new Font("Arial",Font.BOLD,14));
    g.drawString("Draw Point2D Example", 50, 40);
    g.setFont(new Font("Arial",Font.BOLD,10));
    g.drawString("", 200, 205);
                Graphics2D G2D = (Graphics2D)g;
                G2D.setStroke(new BasicStroke(3.0f));
                Point2D P2D = new Point2D.Float(23.5f, 48.9f);
                Point2D P2D2 = new Point2D.Float(158.0f, 173.0f);
                Line2D L2D = new Line2D.Float(P2D, P2D2);

Point2D Java Example