Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 7th, 2012  |  syntax: None  |  size: 0.97 KB  |  views: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Point;
  6. import java.util.ArrayList;
  7.  
  8. import javax.swing.JPanel;
  9.  
  10. public class LightningPanel extends JPanel {
  11.    
  12.     private static final long serialVersionUID = 1L;
  13.     private ArrayList<Point> thePoints;
  14.    
  15.     public void setPoints(ArrayList<Point> points) {
  16.         this.thePoints = points;
  17.     }
  18.  
  19.     public void paintComponent(Graphics g) {
  20.         super.paintComponent(g);
  21.  
  22.         Graphics2D g2d = (Graphics2D) g;
  23.  
  24.         g2d.setColor(Color.blue);
  25.         g2d.setStroke(new BasicStroke(5));
  26.  
  27.         for (int i = 0; i < thePoints.size() - 1; i++) {
  28.             int x1 = (int) thePoints.get(i).getX();
  29.             int y1 = (int) thePoints.get(i).getY();
  30.             int x2 = (int) thePoints.get(i+1).getX();
  31.             int y2 = (int) thePoints.get(i+1).getY();
  32.             g2d.drawLine(x1, y1, x2, y2);    
  33.         }
  34.     }
  35. }