Advertisement
Guest User

Untitled

a guest
Dec 7th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement