draw Line - Java 2D Graphics

Java examples for 2D Graphics:Line

Description

draw Line

Demo Code

/*******************************************************************************
 * Copyright (c)  2012  Wompi //w  ww  .  j  a va2  s.  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.Color;

import java.awt.Graphics2D;

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

public class Main {
    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