Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Painting ArrayList objects to Panel

 
Krysten Thomas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've created a Point class where a Point holds an x and y coordinate.
If I have a while loop that updates x and y and then adds them as a point to my PointArray ArrayList, what would be the best way to paint each point to a panel.
I also would like the lines between each Point to appear. So it would paint first point, then paint 2nd point, drawing a continuous line between each point.

Condensed version of code:



 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out Graphics#drawLine()
Also don't forget to invoke super.paintComponent() inside your overridden paintComponent
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And check out concurrency in Swing. Right now you are either calling Thread.sleep on the EDT, causing it to block, or you're calling repaint on a thread other than the EDT. You should do neither.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic