Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Java in General and the fly likes Painting ArrayList objects to Panel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Painting ArrayList objects to Panel" Watch "Painting ArrayList objects to Panel" New topic
Author

Painting ArrayList objects to Panel

Krysten Thomas
Greenhorn

Joined: Jul 06, 2011
Posts: 11
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

Joined: Jul 26, 2007
Posts: 10694
    
    9

Check out Graphics#drawLine()
Also don't forget to invoke super.paintComponent() inside your overridden paintComponent


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19958
    
  25

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: Painting ArrayList objects to Panel