<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2F2D_Graphics_GUI%2FLine</id>
		<title>Java/2D Graphics GUI/Line - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2F2D_Graphics_GUI%2FLine"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/2D_Graphics_GUI/Line&amp;action=history"/>
		<updated>2026-04-21T15:47:54Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/2D_Graphics_GUI/Line&amp;diff=8109&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/2D_Graphics_GUI/Line&amp;diff=8109&amp;oldid=prev"/>
				<updated>2010-06-01T06:54:03Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:54, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/2D_Graphics_GUI/Line&amp;diff=8108&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/2D_Graphics_GUI/Line&amp;diff=8108&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A line is drawn using two points ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
import java.awt.BasicStroke;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class LinesDashes1 extends JPanel {&lt;br /&gt;
  public void paintComponent(Graphics g) {&lt;br /&gt;
    super.paintComponent(g);&lt;br /&gt;
    Graphics2D g2d = (Graphics2D) g;&lt;br /&gt;
    float[] dash1 = { 2f, 0f, 2f };&lt;br /&gt;
    g2d.drawLine(20, 40, 250, 40);&lt;br /&gt;
    BasicStroke bs1 = new BasicStroke(1, &lt;br /&gt;
        BasicStroke.CAP_BUTT, &lt;br /&gt;
        BasicStroke.JOIN_ROUND, &lt;br /&gt;
        1.0f, &lt;br /&gt;
        dash1,&lt;br /&gt;
        2f);&lt;br /&gt;
    g2d.setStroke(bs1);&lt;br /&gt;
    g2d.drawLine(20, 80, 250, 80);&lt;br /&gt;
    }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    LinesDashes1 lines = new LinesDashes1();&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;Lines&amp;quot;);&lt;br /&gt;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    frame.add(lines);&lt;br /&gt;
    frame.setSize(280, 270);&lt;br /&gt;
    frame.setLocationRelativeTo(null);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Dash style line ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
import java.awt.BasicStroke;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class LinesDashes1 extends JPanel {&lt;br /&gt;
  public void paintComponent(Graphics g) {&lt;br /&gt;
    super.paintComponent(g);&lt;br /&gt;
    Graphics2D g2d = (Graphics2D) g;&lt;br /&gt;
    float[] dash1 = { 2f, 0f, 2f };&lt;br /&gt;
    g2d.drawLine(20, 40, 250, 40);&lt;br /&gt;
    BasicStroke bs1 = new BasicStroke(1, &lt;br /&gt;
        BasicStroke.CAP_BUTT, &lt;br /&gt;
        BasicStroke.JOIN_ROUND, &lt;br /&gt;
        1.0f, &lt;br /&gt;
        dash1,&lt;br /&gt;
        2f);&lt;br /&gt;
    g2d.setStroke(bs1);&lt;br /&gt;
    g2d.drawLine(20, 80, 250, 80);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    LinesDashes1 lines = new LinesDashes1();&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;Lines&amp;quot;);&lt;br /&gt;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    frame.add(lines);&lt;br /&gt;
    frame.setSize(280, 270);&lt;br /&gt;
    frame.setLocationRelativeTo(null);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Draw a point: use a drawLine() method ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
import java.awt.Color;&lt;br /&gt;
import java.awt.Dimension;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import java.util.Random;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class Points extends JPanel {&lt;br /&gt;
  public void paintComponent(Graphics g) {&lt;br /&gt;
    super.paintComponent(g);&lt;br /&gt;
    Graphics2D g2d = (Graphics2D) g;&lt;br /&gt;
    g2d.setColor(Color.red);&lt;br /&gt;
    for (int i = 0; i &amp;lt;= 100000; i++) {&lt;br /&gt;
      Dimension size = getSize();&lt;br /&gt;
      int w = size.width ;&lt;br /&gt;
      int h = size.height;&lt;br /&gt;
      Random r = new Random();&lt;br /&gt;
      int x = Math.abs(r.nextInt()) % w;&lt;br /&gt;
      int y = Math.abs(r.nextInt()) % h;&lt;br /&gt;
      g2d.drawLine(x, y, x, y);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Points points = new Points();&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;Points&amp;quot;);&lt;br /&gt;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    frame.add(points);&lt;br /&gt;
    frame.setSize(250, 200);&lt;br /&gt;
    frame.setLocationRelativeTo(null);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Draw Dashed ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
/*&lt;br /&gt;
    GNU LESSER GENERAL PUBLIC LICENSE&lt;br /&gt;
    Copyright (C) 2006 The Lobo Project&lt;br /&gt;
    This library is free software; you can redistribute it and/or&lt;br /&gt;
    modify it under the terms of the GNU Lesser General Public&lt;br /&gt;
    License as published by the Free Software Foundation; either&lt;br /&gt;
    version 2.1 of the License, or (at your option) any later version.&lt;br /&gt;
    This library is distributed in the hope that it will be useful,&lt;br /&gt;
    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU&lt;br /&gt;
    Lesser General Public License for more details.&lt;br /&gt;
    You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
    License along with this library; if not, write to the Free Software&lt;br /&gt;
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA&lt;br /&gt;
    Contact info: lobochief@users.sourceforge.net&lt;br /&gt;
*/&lt;br /&gt;
import java.awt.*;&lt;br /&gt;
public class GUITasks {&lt;br /&gt;
  public static Frame getTopFrame() {&lt;br /&gt;
    Frame[] frames = Frame.getFrames();&lt;br /&gt;
    for(int i = 0; i &amp;lt; frames.length; i++) {&lt;br /&gt;
      if(frames[i].getFocusOwner() != null) {&lt;br /&gt;
        return frames[i];&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    if(frames.length &amp;gt; 0) {&lt;br /&gt;
      return frames[0];&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public static void drawDashed(Graphics g, int x1, int y1, int x2, int y2, int dashSize, int gapSize) {&lt;br /&gt;
    if(x2 &amp;lt; x1) {&lt;br /&gt;
      int temp = x1;&lt;br /&gt;
      x1 = x2;&lt;br /&gt;
      x2 = temp;&lt;br /&gt;
    }&lt;br /&gt;
    if(y2 &amp;lt; y1) {&lt;br /&gt;
      int temp = y1;&lt;br /&gt;
      y1 = y2;&lt;br /&gt;
      y2 = temp;&lt;br /&gt;
    }&lt;br /&gt;
    int totalDash = dashSize + gapSize;&lt;br /&gt;
    if(y1 == y2) {&lt;br /&gt;
      int virtualStartX = (x1 / totalDash) * totalDash;&lt;br /&gt;
      for(int x = virtualStartX; x &amp;lt; x2; x += totalDash) {&lt;br /&gt;
        int topX = x + dashSize;&lt;br /&gt;
        if(topX &amp;gt; x2) {&lt;br /&gt;
          topX = x2;&lt;br /&gt;
        }&lt;br /&gt;
        int firstX = x;&lt;br /&gt;
        if(firstX &amp;lt; x1) {&lt;br /&gt;
          firstX = x1;&lt;br /&gt;
        }&lt;br /&gt;
        if(firstX &amp;lt; topX) {&lt;br /&gt;
          g.drawLine(firstX, y1, topX, y1);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    else if(x1 == x2) {&lt;br /&gt;
      int virtualStartY = (y1 / totalDash) * totalDash;&lt;br /&gt;
      for(int y = virtualStartY; y &amp;lt; y2; y += totalDash) {&lt;br /&gt;
        int topY = y + dashSize;&lt;br /&gt;
        if(topY &amp;gt; y2) {&lt;br /&gt;
          topY = y2;&lt;br /&gt;
        }&lt;br /&gt;
        int firstY = y;&lt;br /&gt;
        if(firstY &amp;lt; y1) {&lt;br /&gt;
          firstY = y1;&lt;br /&gt;
        }&lt;br /&gt;
        if(firstY &amp;lt; topY) {&lt;br /&gt;
          g.drawLine(x1, firstY, x1, topY);&lt;br /&gt;
        }&lt;br /&gt;
      }     &lt;br /&gt;
    }&lt;br /&gt;
    else {&lt;br /&gt;
      // Not supported&lt;br /&gt;
      g.drawLine(x1, y1, x2, y2);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Drawing a Line using Java 2D Graphics API ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import java.awt.geom.Line2D;&lt;br /&gt;
public class Main extends javax.swing.JFrame {&lt;br /&gt;
  public Main() {&lt;br /&gt;
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);&lt;br /&gt;
    setSize(600, 600);&lt;br /&gt;
  }&lt;br /&gt;
  public void paint(Graphics g) {&lt;br /&gt;
    Graphics2D g2 = (Graphics2D) g;&lt;br /&gt;
    Line2D lin = new Line2D.Float(100, 100, 250, 260);&lt;br /&gt;
    g2.draw(lin);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    new Main().setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Draw Optimized Line ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (C) 2004 NNL Technology AB&lt;br /&gt;
 * Visit www.infonode.net for information about InfoNode(R) &lt;br /&gt;
 * products and how to contact NNL Technology AB.&lt;br /&gt;
 *&lt;br /&gt;
 * This program is free software; you can redistribute it and/or&lt;br /&gt;
 * modify it under the terms of the GNU General Public License&lt;br /&gt;
 * as published by the Free Software Foundation; either version 2&lt;br /&gt;
 * of the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This program is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
 * GNU General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU General Public License&lt;br /&gt;
 * along with this program; if not, write to the Free Software&lt;br /&gt;
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, &lt;br /&gt;
 * MA 02111-1307, USA.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// $Id: GraphicsUtil.java,v 1.4 2005/12/04 13:46:04 jesper Exp $&lt;br /&gt;
&lt;br /&gt;
import javax.swing.*;&lt;br /&gt;
import java.awt.*;&lt;br /&gt;
/**&lt;br /&gt;
 * @author johan&lt;br /&gt;
 */&lt;br /&gt;
public class GraphicsUtil {&lt;br /&gt;
  public static void drawOptimizedLine(Graphics g, int x1, int y1, int x2, int y2) {&lt;br /&gt;
    if (g.getColor().getAlpha() &amp;lt; 255 &amp;amp;&amp;amp; (x1 == x2 || y1 == y2))&lt;br /&gt;
      g.fillRect(x1 &amp;lt; x2 ? x1 : x2, y1 &amp;lt; y2 ? y1 : y2, Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1);&lt;br /&gt;
    else&lt;br /&gt;
      g.drawLine(x1, y1, x2, y2);&lt;br /&gt;
  }&lt;br /&gt;
  public static Rectangle calculateIntersectionClip(int x, int y, int width, int height, Shape originalClip) {&lt;br /&gt;
    Rectangle bounds = originalClip.getBounds();&lt;br /&gt;
    SwingUtilities.ruputeIntersection(x, y, width, height, bounds);&lt;br /&gt;
    return bounds;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Line dashes style 2 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
import java.awt.BasicStroke;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class LinesDashes2 extends JPanel {&lt;br /&gt;
  public void paintComponent(Graphics g) {&lt;br /&gt;
    super.paintComponent(g);&lt;br /&gt;
    Graphics2D g2d = (Graphics2D) g;&lt;br /&gt;
    g2d.drawLine(20, 40, 250, 40);&lt;br /&gt;
    float[] dash2 = { 1f, 1f, 1f };&lt;br /&gt;
    BasicStroke bs2 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash2,2f);&lt;br /&gt;
    g2d.setStroke(bs2);&lt;br /&gt;
    g2d.drawLine(20, 20, 250, 20);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    LinesDashes2 lines = new LinesDashes2();&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;Lines&amp;quot;);&lt;br /&gt;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    frame.add(lines);&lt;br /&gt;
    frame.setSize(280, 270);&lt;br /&gt;
    frame.setLocationRelativeTo(null);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Line Dash Style 4 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
import java.awt.BasicStroke;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class LinesDashes4 extends JPanel {&lt;br /&gt;
  public void paintComponent(Graphics g) {&lt;br /&gt;
    super.paintComponent(g);&lt;br /&gt;
    Graphics2D g2d = (Graphics2D) g;&lt;br /&gt;
    &lt;br /&gt;
    float[] dash4 = { 4f, 4f, 1f };&lt;br /&gt;
    BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash4,&lt;br /&gt;
        2f);&lt;br /&gt;
        &lt;br /&gt;
    g2d.setStroke(bs4);&lt;br /&gt;
    g2d.drawLine(20, 20, 250, 20);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    LinesDashes4 lines = new LinesDashes4();&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;Lines&amp;quot;);&lt;br /&gt;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    frame.add(lines);&lt;br /&gt;
    frame.setSize(280, 270);&lt;br /&gt;
    frame.setLocationRelativeTo(null);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Line-graph drawable ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;  &lt;br /&gt;
/**&lt;br /&gt;
 * &lt;br /&gt;
 * LibSparkline : a free Java sparkline chart library&lt;br /&gt;
 * &lt;br /&gt;
 *&lt;br /&gt;
 * Project Info:  http://reporting.pentaho.org/libsparkline/&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright 2008, by Larry Ogrodnek, Pentaho Corporation and Contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This library is free software; you can redistribute it and/or modify it under the terms&lt;br /&gt;
 * of the Apache License 2.0.&lt;br /&gt;
 *&lt;br /&gt;
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;&lt;br /&gt;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the Apache License 2.0 along with this library;&lt;br /&gt;
 * if not, a online version is available at http://www.apache.org/licenses/&lt;br /&gt;
 *&lt;br /&gt;
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.&lt;br /&gt;
 * in the United States and other countries.]&lt;br /&gt;
 *&lt;br /&gt;
 * ------------&lt;br /&gt;
 * LineGraphDrawable.java&lt;br /&gt;
 * ------------&lt;br /&gt;
 */&lt;br /&gt;
import java.awt.Color;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import java.awt.geom.Line2D;&lt;br /&gt;
import java.awt.geom.Rectangle2D;&lt;br /&gt;
/**&lt;br /&gt;
 * A very fast and very simple line-graph drawable. This code is based on the&lt;br /&gt;
 * LineGraph class writen by Larry Ogrodnek but instead of producing a&lt;br /&gt;
 * low-resolution image, this class writes the content into a Graphics2D&lt;br /&gt;
 * context.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Thomas Morgner&lt;br /&gt;
 */&lt;br /&gt;
public class LineGraphDrawable {&lt;br /&gt;
  private static final int DEFAULT_SPACING = 2;&lt;br /&gt;
  private int spacing;&lt;br /&gt;
  private Color color;&lt;br /&gt;
  private Color background;&lt;br /&gt;
  private Number[] data;&lt;br /&gt;
  /**&lt;br /&gt;
   * Creates a default bargraph drawable with some sensible default colors and&lt;br /&gt;
   * spacings.&lt;br /&gt;
   */&lt;br /&gt;
  public LineGraphDrawable() {&lt;br /&gt;
    this.color = Color.black;&lt;br /&gt;
    this.spacing = DEFAULT_SPACING;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns the numeric data for the drawable or null, if the drawable has no&lt;br /&gt;
   * data.&lt;br /&gt;
   * &lt;br /&gt;
   * @return the data.&lt;br /&gt;
   */&lt;br /&gt;
  public Number[] getData() {&lt;br /&gt;
    return data;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Defines the numeric data for the drawable or null, if the drawable has no&lt;br /&gt;
   * data.&lt;br /&gt;
   * &lt;br /&gt;
   * @param data&lt;br /&gt;
   *          the data (can be null).&lt;br /&gt;
   */&lt;br /&gt;
  public void setData(final Number[] data) {&lt;br /&gt;
    this.data = data;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns the main color for the bars.&lt;br /&gt;
   * &lt;br /&gt;
   * @return the main color for the bars, never null.&lt;br /&gt;
   */&lt;br /&gt;
  public Color getColor() {&lt;br /&gt;
    return color;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Defines the main color for the bars.&lt;br /&gt;
   * &lt;br /&gt;
   * @param color&lt;br /&gt;
   *          the main color for the bars, never null.&lt;br /&gt;
   */&lt;br /&gt;
  public void setColor(final Color color) {&lt;br /&gt;
    if (color == null) {&lt;br /&gt;
      throw new NullPointerException();&lt;br /&gt;
    }&lt;br /&gt;
    this.color = color;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns the color for the background of the graph. This property can be&lt;br /&gt;
   * null, in which case the bar will have a transparent background.&lt;br /&gt;
   * &lt;br /&gt;
   * @return color for the background or null, if the graph has a transparent&lt;br /&gt;
   *         background color.&lt;br /&gt;
   */&lt;br /&gt;
  public Color getBackground() {&lt;br /&gt;
    return background;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Defines the color for the background of the graph. This property can be&lt;br /&gt;
   * null, in which case the bar will have a transparent background.&lt;br /&gt;
   * &lt;br /&gt;
   * @param background&lt;br /&gt;
   *          the background or null, if the graph has a transparent background&lt;br /&gt;
   *          color.&lt;br /&gt;
   */&lt;br /&gt;
  public void setBackground(final Color background) {&lt;br /&gt;
    this.background = background;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns the spacing between the bars.&lt;br /&gt;
   * &lt;br /&gt;
   * @return the spacing between the bars.&lt;br /&gt;
   */&lt;br /&gt;
  public int getSpacing() {&lt;br /&gt;
    return spacing;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Defines the spacing between the bars.&lt;br /&gt;
   * &lt;br /&gt;
   * @param spacing&lt;br /&gt;
   *          the spacing between the bars.&lt;br /&gt;
   */&lt;br /&gt;
  public void setSpacing(final int spacing) {&lt;br /&gt;
    this.spacing = spacing;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Draws the bar-graph into the given Graphics2D context in the given area.&lt;br /&gt;
   * This method will not draw a graph if the data given is null or empty.&lt;br /&gt;
   * &lt;br /&gt;
   * @param graphics&lt;br /&gt;
   *          the graphics context on which the bargraph should be rendered.&lt;br /&gt;
   * @param drawArea&lt;br /&gt;
   *          the area on which the bargraph should be drawn.&lt;br /&gt;
   */&lt;br /&gt;
  public void draw(final Graphics2D graphics, final Rectangle2D drawArea) {&lt;br /&gt;
    if (graphics == null) {&lt;br /&gt;
      throw new NullPointerException();&lt;br /&gt;
    }&lt;br /&gt;
    if (drawArea == null) {&lt;br /&gt;
      throw new NullPointerException();&lt;br /&gt;
    }&lt;br /&gt;
    final int height = (int) drawArea.getHeight();&lt;br /&gt;
    if (height &amp;lt;= 0) {&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    final Graphics2D g2 = (Graphics2D) graphics.create();&lt;br /&gt;
    if (background != null) {&lt;br /&gt;
      g2.setPaint(background);&lt;br /&gt;
      g2.draw(drawArea);&lt;br /&gt;
    }&lt;br /&gt;
    if (data == null || data.length == 0) {&lt;br /&gt;
      g2.dispose();&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    g2.translate(drawArea.getX(), drawArea.getY());&lt;br /&gt;
    float d = getDivisor(data, height);&lt;br /&gt;
    final int spacing = getSpacing();&lt;br /&gt;
    final int w = (((int) drawArea.getWidth()) - (spacing * (data.length - 1))) / (data.length - 1);&lt;br /&gt;
    float min = Float.MAX_VALUE;&lt;br /&gt;
    for (int index = 0; index &amp;lt; data.length; index++) {&lt;br /&gt;
      Number i = data[index];&lt;br /&gt;
      if (i == null) {&lt;br /&gt;
        continue;&lt;br /&gt;
      }&lt;br /&gt;
      final float value = i.floatValue();&lt;br /&gt;
      if (value &amp;lt; min) {&lt;br /&gt;
        min = value;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    int x = 0;&lt;br /&gt;
    int y = -1;&lt;br /&gt;
    if (d == 0.0) {&lt;br /&gt;
      // special case -- a horizontal straight line&lt;br /&gt;
      d = 1.0f;&lt;br /&gt;
      y = -height / 2;&lt;br /&gt;
    }&lt;br /&gt;
    final Line2D.Double line = new Line2D.Double();&lt;br /&gt;
    for (int i = 0; i &amp;lt; data.length - 1; i++) {&lt;br /&gt;
      final int px1 = x;&lt;br /&gt;
      x += (w + spacing);&lt;br /&gt;
      final int px2 = x;&lt;br /&gt;
      g2.setPaint(color);&lt;br /&gt;
      final Number number = data[i];&lt;br /&gt;
      final Number nextNumber = data[i + 1];&lt;br /&gt;
      if (number == null &amp;amp;&amp;amp; nextNumber == null) {&lt;br /&gt;
        final float delta = height - ((0 - min) / d);&lt;br /&gt;
        line.setLine(px1, y + delta, px2, y + delta);&lt;br /&gt;
      } else if (number == null) {&lt;br /&gt;
        line.setLine(px1, y + (height - ((0 - min) / d)), px2, y&lt;br /&gt;
            + (height - ((nextNumber.floatValue() - min) / d)));&lt;br /&gt;
      } else if (nextNumber == null) {&lt;br /&gt;
        line.setLine(px1, y + (height - ((number.floatValue() - min) / d)), px2, y&lt;br /&gt;
            + (height - ((0 - min) / d)));&lt;br /&gt;
      } else {&lt;br /&gt;
        line.setLine(px1, y + (height - ((number.floatValue() - min) / d)), px2, y&lt;br /&gt;
            + (height - ((nextNumber.floatValue() - min) / d)));&lt;br /&gt;
      }&lt;br /&gt;
      g2.draw(line);&lt;br /&gt;
    }&lt;br /&gt;
    g2.dispose();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Computes the scale factor to scale the given numeric data into the target&lt;br /&gt;
   * height.&lt;br /&gt;
   * &lt;br /&gt;
   * @param data&lt;br /&gt;
   *          the numeric data.&lt;br /&gt;
   * @param height&lt;br /&gt;
   *          the target height of the graph.&lt;br /&gt;
   * @return the scale factor.&lt;br /&gt;
   */&lt;br /&gt;
  public static float getDivisor(final Number[] data, final int height) {&lt;br /&gt;
    if (data == null) {&lt;br /&gt;
      throw new NullPointerException(&amp;quot;Data array must not be null.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    if (height &amp;lt; 1) {&lt;br /&gt;
      throw new IndexOutOfBoundsException(&amp;quot;Height must be greater or equal to 1&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    float max = Float.MIN_VALUE;&lt;br /&gt;
    float min = Float.MAX_VALUE;&lt;br /&gt;
    for (int index = 0; index &amp;lt; data.length; index++) {&lt;br /&gt;
      Number i = data[index];&lt;br /&gt;
      if (i == null) {&lt;br /&gt;
        continue;&lt;br /&gt;
      }&lt;br /&gt;
      final float numValue = i.floatValue();&lt;br /&gt;
      if (numValue &amp;lt; min) {&lt;br /&gt;
        min = numValue;&lt;br /&gt;
      }&lt;br /&gt;
      if (numValue &amp;gt; max) {&lt;br /&gt;
        max = numValue;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    if (max &amp;lt;= min) {&lt;br /&gt;
      return 1.0f;&lt;br /&gt;
    }&lt;br /&gt;
    if (height == 1) {&lt;br /&gt;
      return 0;&lt;br /&gt;
    }&lt;br /&gt;
    return (max - min) / (height - 1);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lines Dashes style 3 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
import java.awt.BasicStroke;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
public class LinesDashes3 extends JPanel {&lt;br /&gt;
  public void paintComponent(Graphics g) {&lt;br /&gt;
    super.paintComponent(g);&lt;br /&gt;
    Graphics2D g2d = (Graphics2D) g;&lt;br /&gt;
    &lt;br /&gt;
    float[] dash3 = { 4f, 0f, 2f };&lt;br /&gt;
    BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash3,&lt;br /&gt;
        2f);&lt;br /&gt;
    &lt;br /&gt;
    g2d.setStroke(bs3);&lt;br /&gt;
    g2d.drawLine(20, 60, 250, 60);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    LinesDashes3 lines = new LinesDashes3();&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;Lines&amp;quot;);&lt;br /&gt;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;
    frame.add(lines);&lt;br /&gt;
    frame.setSize(280, 270);&lt;br /&gt;
    frame.setLocationRelativeTo(null);&lt;br /&gt;
    frame.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Line Styles ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2000 David Flanagan.  All rights reserved.&lt;br /&gt;
 * This code is from the book Java Examples in a Nutshell, 2nd Edition.&lt;br /&gt;
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.&lt;br /&gt;
 * You may study, use, and modify it for any non-commercial purpose.&lt;br /&gt;
 * You may distribute it non-commercially as long as you retain this notice.&lt;br /&gt;
 * For a commercial use license, or to purchase the book (recommended),&lt;br /&gt;
 * visit http://www.davidflanagan.ru/javaexamples2.&lt;br /&gt;
 */&lt;br /&gt;
import java.awt.BasicStroke;&lt;br /&gt;
import java.awt.Color;&lt;br /&gt;
import java.awt.Font;&lt;br /&gt;
import java.awt.Graphics;&lt;br /&gt;
import java.awt.Graphics2D;&lt;br /&gt;
import java.awt.RenderingHints;&lt;br /&gt;
import java.awt.Stroke;&lt;br /&gt;
import java.awt.event.WindowAdapter;&lt;br /&gt;
import java.awt.event.WindowEvent;&lt;br /&gt;
import java.awt.geom.GeneralPath;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JPanel;&lt;br /&gt;
/** A demonstration of Java2D line styles */&lt;br /&gt;
public class LineStyles extends JPanel{&lt;br /&gt;
  public String getName() {&lt;br /&gt;
    return &amp;quot;LineStyles&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  public int getWidth() {&lt;br /&gt;
    return 450;&lt;br /&gt;
  }&lt;br /&gt;
  public int getHeight() {&lt;br /&gt;
    return 180;&lt;br /&gt;
  }&lt;br /&gt;
  int[] xpoints = new int[] { 0, 50, 100 }; // X coordinates of our shape&lt;br /&gt;
  int[] ypoints = new int[] { 75, 0, 75 }; // Y coordinates of our shape&lt;br /&gt;
  // Here are three different line styles we will demonstrate&lt;br /&gt;
  // They are thick lines with different cap and join styles&lt;br /&gt;
  Stroke[] linestyles = new Stroke[] {&lt;br /&gt;
      new BasicStroke(25.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL),&lt;br /&gt;
      new BasicStroke(25.0f, BasicStroke.CAP_SQUARE,&lt;br /&gt;
          BasicStroke.JOIN_MITER),&lt;br /&gt;
      new BasicStroke(25.0f, BasicStroke.CAP_ROUND,&lt;br /&gt;
          BasicStroke.JOIN_ROUND), };&lt;br /&gt;
  // Another line style: a 2 pixel-wide dot-dashed line&lt;br /&gt;
  Stroke thindashed = new BasicStroke(2.0f, // line width&lt;br /&gt;
      /* cap style */BasicStroke.CAP_BUTT,&lt;br /&gt;
      /* join style, miter limit */BasicStroke.JOIN_BEVEL, 1.0f,&lt;br /&gt;
      /* the dash pattern */new float[] { 8.0f, 3.0f, 2.0f, 3.0f },&lt;br /&gt;
      /* the dash phase */0.0f); /* on 8, off 3, on 2, off 3 */&lt;br /&gt;
  // Labels to appear in the diagram, and the font to use to display them.&lt;br /&gt;
  Font font = new Font(&amp;quot;Helvetica&amp;quot;, Font.BOLD, 12);&lt;br /&gt;
  String[] capNames = new String[] { &amp;quot;CAP_BUTT&amp;quot;, &amp;quot;CAP_SQUARE&amp;quot;, &amp;quot;CAP_ROUND&amp;quot; };&lt;br /&gt;
  String[] joinNames = new String[] { &amp;quot;JOIN_BEVEL&amp;quot;, &amp;quot;JOIN_MITER&amp;quot;,&lt;br /&gt;
      &amp;quot;JOIN_ROUND&amp;quot; };&lt;br /&gt;
  /** This method draws the example figure */&lt;br /&gt;
  public void paint(Graphics g1) {&lt;br /&gt;
    Graphics2D g = (Graphics2D) g1;&lt;br /&gt;
    // Use anti-aliasing to avoid &amp;quot;jaggies&amp;quot; in the lines&lt;br /&gt;
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,&lt;br /&gt;
        RenderingHints.VALUE_ANTIALIAS_ON);&lt;br /&gt;
    // Define the shape to draw&lt;br /&gt;
    GeneralPath shape = new GeneralPath();&lt;br /&gt;
    shape.moveTo(xpoints[0], ypoints[0]); // start at point 0&lt;br /&gt;
    shape.lineTo(xpoints[1], ypoints[1]); // draw a line to point 1&lt;br /&gt;
    shape.lineTo(xpoints[2], ypoints[2]); // and then on to point 2&lt;br /&gt;
    // Move the origin to the right and down, creating a margin&lt;br /&gt;
    g.translate(20, 40);&lt;br /&gt;
    // Now loop, drawing our shape with the three different line styles&lt;br /&gt;
    for (int i = 0; i &amp;lt; linestyles.length; i++) {&lt;br /&gt;
      g.setColor(Color.gray); // Draw a gray line&lt;br /&gt;
      g.setStroke(linestyles[i]); // Select the line style to use&lt;br /&gt;
      g.draw(shape); // Draw the shape&lt;br /&gt;
      g.setColor(Color.black); // Now use black&lt;br /&gt;
      g.setStroke(thindashed); // And the thin dashed line&lt;br /&gt;
      g.draw(shape); // And draw the shape again.&lt;br /&gt;
      // Highlight the location of the vertexes of the shape&lt;br /&gt;
      // This accentuates the cap and join styles we&amp;quot;re demonstrating&lt;br /&gt;
      for (int j = 0; j &amp;lt; xpoints.length; j++)&lt;br /&gt;
        g.fillRect(xpoints[j] - 2, ypoints[j] - 2, 5, 5);&lt;br /&gt;
      g.drawString(capNames[i], 5, 105); // Label the cap style&lt;br /&gt;
      g.drawString(joinNames[i], 5, 120); // Label the join style&lt;br /&gt;
      g.translate(150, 0); // Move over to the right before looping again&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] a){&lt;br /&gt;
      JFrame f = new JFrame();&lt;br /&gt;
      f.addWindowListener(new WindowAdapter() {&lt;br /&gt;
      public void windowClosing(WindowEvent e) {&lt;br /&gt;
        System.exit(0);&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
      f.setContentPane(new LineStyles());&lt;br /&gt;
      f.setSize(450,200);&lt;br /&gt;
      f.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Xsplinefun displays colorful moving splines in a window ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;   &lt;br /&gt;
/**&lt;br /&gt;
 * Xsplinefun displays colorful moving splines in a window.&lt;br /&gt;
 * &lt;br /&gt;
 * Taken from xsplinefun, Distribution of 02may92, by Jef Poskanzer,&lt;br /&gt;
 * jef@netcom.ru, jef@well.sf.ca.us&lt;br /&gt;
 * &lt;br /&gt;
 * @copyright (C) 1992 by Jef Poskanzer&lt;br /&gt;
 * &lt;br /&gt;
 * Permission to use, copy, modify, and distribute this software and its&lt;br /&gt;
 * documentation for any purpose and without fee is hereby granted, provided&lt;br /&gt;
 * that the above copyright notice appear in all copies and that both that&lt;br /&gt;
 * copyright notice and this permission notice appear in supporting&lt;br /&gt;
 * documentation. This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty.&lt;br /&gt;
 * &lt;br /&gt;
 * First step in converting to Java was to junk all the X Windows stuff; in the&lt;br /&gt;
 * process we lost all the customization (need to re-add with getopt?).&lt;br /&gt;
 */&lt;br /&gt;
public class XSplineFun {&lt;br /&gt;
  public static final int POINTS = 20;&lt;br /&gt;
  public static final int DEFAULT_MAX_COLORS = 20;&lt;br /&gt;
  /* Spline-fun smarts. */&lt;br /&gt;
  static int x[] = new int [POINTS]; &lt;br /&gt;
    static int y[]= new int [POINTS];&lt;br /&gt;
         static int  dx[] = new int [POINTS];&lt;br /&gt;
                static int dy[]= new int [POINTS];&lt;br /&gt;
  static int nred, ngreen, nblue, dred, dgreen, dblue;&lt;br /&gt;
  static int color;&lt;br /&gt;
  static Color xcolors[] = new Color[DEFAULT_MAX_COLORS];&lt;br /&gt;
  public static void main(String[] av) {&lt;br /&gt;
    Frame f = new Frame(&amp;quot;Spline Fun&amp;quot;);&lt;br /&gt;
    XSplineFun xf = new XSplineFun();&lt;br /&gt;
    xf.init_splines();&lt;br /&gt;
    f.add(xf);&lt;br /&gt;
    while(true)&lt;br /&gt;
      try {&lt;br /&gt;
        xf.move_splines();&lt;br /&gt;
        Thread.sleep(150);    // msec&lt;br /&gt;
      } catch (Exception e) {&lt;br /&gt;
        System.out.println(e);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  static void&lt;br /&gt;
  init_splines()&lt;br /&gt;
  {&lt;br /&gt;
    int i;&lt;br /&gt;
    /* Initialize points. */&lt;br /&gt;
    for ( i = 0; i &amp;lt; POINTS; ++i )&lt;br /&gt;
    {&lt;br /&gt;
    x[i] = random() % width;&lt;br /&gt;
    y[i] = random() % height;&lt;br /&gt;
    dx[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;&lt;br /&gt;
    if ( dx[i] &amp;lt;= 0 ) --dx[i];&lt;br /&gt;
    dy[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;&lt;br /&gt;
    if ( dy[i] &amp;lt;= 0 ) --dy[i];&lt;br /&gt;
    }&lt;br /&gt;
    /* Initalize colors. */&lt;br /&gt;
    for ( color = 0; color &amp;lt; ncolors; ++color )&lt;br /&gt;
    {&lt;br /&gt;
    xcolors[color].red = xcolors[color].green = xcolors[color].blue = 0;&lt;br /&gt;
    xcolors[color].pixel = pixels[color];&lt;br /&gt;
    xcolors[color].flags = DoRed|DoGreen|DoBlue;&lt;br /&gt;
    }&lt;br /&gt;
    color = 0;&lt;br /&gt;
    nred = ngreen = nblue = 0;&lt;br /&gt;
    dred = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;&lt;br /&gt;
    if ( dred &amp;lt;= 0 ) --dred;&lt;br /&gt;
    dgreen = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;&lt;br /&gt;
    if ( dgreen &amp;lt;= 0 ) --dgreen;&lt;br /&gt;
    dblue = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;&lt;br /&gt;
    if ( dblue &amp;lt;= 0 ) --dblue;&lt;br /&gt;
  }&lt;br /&gt;
  static void&lt;br /&gt;
  rotate_colormap()&lt;br /&gt;
  {&lt;br /&gt;
    int t, i;&lt;br /&gt;
    if ( forwards )&lt;br /&gt;
    {&lt;br /&gt;
    t = xcolors[0].pixel;&lt;br /&gt;
    for ( i = 0; i &amp;lt; ncolors - 1; ++i )&lt;br /&gt;
      xcolors[i].pixel = xcolors[i + 1].pixel;&lt;br /&gt;
    xcolors[ncolors - 1].pixel = t;&lt;br /&gt;
    XStoreColors(display, cmap, xcolors, ncolors );&lt;br /&gt;
    }&lt;br /&gt;
    else if ( backwards )&lt;br /&gt;
    {&lt;br /&gt;
    t = xcolors[ncolors - 1].pixel;&lt;br /&gt;
    for ( i = ncolors - 1; i &amp;gt; 0; --i )&lt;br /&gt;
      xcolors[i].pixel = xcolors[i - 1].pixel;&lt;br /&gt;
    xcolors[0].pixel = t;&lt;br /&gt;
    XStoreColors(display, cmap, xcolors, ncolors );&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  static void&lt;br /&gt;
  new_color()&lt;br /&gt;
  {&lt;br /&gt;
    int t;&lt;br /&gt;
    for ( ; ; )&lt;br /&gt;
    {&lt;br /&gt;
    t = (int) nred + dred;&lt;br /&gt;
    if ( t &amp;gt;= 0 &amp;amp;&amp;amp; t &amp;lt; 65536 ) break;&lt;br /&gt;
    dred = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;&lt;br /&gt;
    if ( dred &amp;lt;= 0 ) --dred;&lt;br /&gt;
    }&lt;br /&gt;
    xcolors[color].red = nred = t;&lt;br /&gt;
    for ( ; ; )&lt;br /&gt;
    {&lt;br /&gt;
    t = (int) ngreen + dgreen;&lt;br /&gt;
    if ( t &amp;gt;= 0 &amp;amp;&amp;amp; t &amp;lt; 65536 ) break;&lt;br /&gt;
    dgreen = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;&lt;br /&gt;
    if ( dgreen &amp;lt;= 0 ) --dgreen;&lt;br /&gt;
    }&lt;br /&gt;
    xcolors[color].green = ngreen = t;&lt;br /&gt;
    for ( ; ; )&lt;br /&gt;
    {&lt;br /&gt;
    t = (int) nblue + dblue;&lt;br /&gt;
    if ( t &amp;gt;= 0 &amp;amp;&amp;amp; t &amp;lt; 65536 ) break;&lt;br /&gt;
    dblue = random() % ( MAX_COLOR_DELTA * 2 ) - MAX_COLOR_DELTA;&lt;br /&gt;
    if ( dblue &amp;lt;= 0 ) --dblue;&lt;br /&gt;
    }&lt;br /&gt;
    xcolors[color].blue = nblue = t;&lt;br /&gt;
    XStoreColor(display, cmap, &amp;amp;(xcolors[color]) );&lt;br /&gt;
    XSetForeground( display, gc, xcolors[color].pixel );&lt;br /&gt;
    if ( ++color &amp;gt;= ncolors ) color -= ncolors;&lt;br /&gt;
  }&lt;br /&gt;
  static void&lt;br /&gt;
  move_splines()&lt;br /&gt;
  {&lt;br /&gt;
    int i, t, px, py, zx, zy, nx, ny;&lt;br /&gt;
    /* Rotate colormap if necessary. */&lt;br /&gt;
    rotate_colormap();&lt;br /&gt;
    /* Choose new color. */&lt;br /&gt;
    new_color();&lt;br /&gt;
    /* Backwards rotation requires two new colors each loop. */&lt;br /&gt;
    if ( backwards )&lt;br /&gt;
    new_color();&lt;br /&gt;
    /* Move the points. */&lt;br /&gt;
    for ( i = 0; i &amp;lt; POINTS; i++ )&lt;br /&gt;
    {&lt;br /&gt;
    for ( ; ; )&lt;br /&gt;
      {&lt;br /&gt;
      t = x[i] + dx[i];&lt;br /&gt;
      if ( t &amp;gt;= 0 &amp;amp;&amp;amp; t &amp;lt; width ) break;&lt;br /&gt;
      dx[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;&lt;br /&gt;
      if ( dx[i] &amp;lt;= 0 ) --dx[i];&lt;br /&gt;
      }&lt;br /&gt;
    x[i] = t;&lt;br /&gt;
    for ( ; ; )&lt;br /&gt;
      {&lt;br /&gt;
      t = y[i] + dy[i];&lt;br /&gt;
      if ( t &amp;gt;= 0 &amp;amp;&amp;amp; t &amp;lt; height ) break;&lt;br /&gt;
      dy[i] = random() % ( MAX_DELTA * 2 ) - MAX_DELTA;&lt;br /&gt;
      if ( dy[i] &amp;lt;= 0 ) --dy[i];&lt;br /&gt;
      }&lt;br /&gt;
    y[i] = t;&lt;br /&gt;
    }&lt;br /&gt;
    /* Draw the figure. */&lt;br /&gt;
    px = zx = ( x[0] + x[POINTS-1] ) / 2;&lt;br /&gt;
    py = zy = ( y[0] + y[POINTS-1] ) / 2;&lt;br /&gt;
    for ( i = 0; i &amp;lt; POINTS-1; ++i )&lt;br /&gt;
    {&lt;br /&gt;
    nx = ( x[i+1] + x[i] ) / 2;&lt;br /&gt;
    ny = ( y[i+1] + y[i] ) / 2;&lt;br /&gt;
    XDrawSpline(g, px, py, x[i], y[i], nx, ny );&lt;br /&gt;
    px = nx;&lt;br /&gt;
    py = ny;&lt;br /&gt;
    }&lt;br /&gt;
    XDrawSpline(g, px, py, x[POINTS-1], y[POINTS-1], zx, zy );&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* X spline routine. */&lt;br /&gt;
  int abs(x) {&lt;br /&gt;
    return x &amp;lt; 0 ? -x : x;&lt;br /&gt;
  }&lt;br /&gt;
  static void&lt;br /&gt;
  XDrawSpline(Graphics g, int x0, y0, x1, y1, x2, y2) {&lt;br /&gt;
    register int xa, ya, xb, yb, xc, yc, xp, yp;&lt;br /&gt;
    xa = ( x0 + x1 ) / 2;&lt;br /&gt;
    ya = ( y0 + y1 ) / 2;&lt;br /&gt;
    xc = ( x1 + x2 ) / 2;&lt;br /&gt;
    yc = ( y1 + y2 ) / 2;&lt;br /&gt;
    xb = ( xa + xc ) / 2;&lt;br /&gt;
    yb = ( ya + yc ) / 2;&lt;br /&gt;
    xp = ( x0 + xb ) / 2;&lt;br /&gt;
    yp = ( y0 + yb ) / 2;&lt;br /&gt;
    if ( abs( xa - xp ) + abs( ya - yp ) &amp;gt; SPLINE_THRESH )&lt;br /&gt;
    XDrawSpline( display, d, gc, x0, y0, xa, ya, xb, yb );&lt;br /&gt;
    else&lt;br /&gt;
    XDrawLine( display, d, gc, x0, y0, xb, yb );&lt;br /&gt;
    xp = ( x2 + xb ) / 2;&lt;br /&gt;
    yp = ( y2 + yb ) / 2;&lt;br /&gt;
    if ( abs( xc - xp ) + abs( yc - yp ) &amp;gt; SPLINE_THRESH )&lt;br /&gt;
    XDrawSpline( display, d, gc, xb, yb, xc, yc, x2, y2 );&lt;br /&gt;
    else&lt;br /&gt;
    XDrawLine( display, d, gc, xb, yb, x2, y2 );&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>