aspose file tools*
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
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: 10451
    
    8

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: 19722
    
  20

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Painting ArrayList objects to Panel