draw Point - Java 2D Graphics

Java examples for 2D Graphics:Point

Description

draw Point

Demo Code

/*******************************************************************************
 * Copyright (c)  2012  Wompi /*from   w  ww  .  j  a va2s.  c  o m*/
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the ZLIB
 * which accompanies this distribution, and is available at
 * http://robowiki.net/wiki/ZLIB
 * 
 * Contributors:
 *     Wompi - initial API and implementation
 ******************************************************************************/
//package com.java2s;
import java.awt.BasicStroke;
import java.awt.Color;

import java.awt.Graphics2D;
import java.awt.Stroke;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

public class Main {
    public static void drawPoint(Point2D point, Color color, Graphics2D g2,
            float size) {
        Stroke old = g2.getStroke();
        g2.setStroke(new BasicStroke(size));
        g2.setColor(color);
        g2.drawLine((int) point.getX(), (int) point.getY(),
                (int) point.getX(), (int) point.getY());
        g2.setStroke(old);
    }

    public static void drawLine(Line2D line, Graphics2D g, Color color) {
        if (line == null)
            return;
        if (Double.isInfinite(line.getP1().distance(line.getP2())))
            return;
        g.setColor(color);
        g.draw(line);
    }

    public static void drawLine(Point2D start, Point2D ende, Graphics2D g2,
            Color color) {
        if (start == null || ende == null)
            return;
        g2.setColor(color);
        g2.drawLine((int) start.getX(), (int) start.getY(),
                (int) ende.getX(), (int) ende.getY());
    }
}

Related Tutorials