my dog learned polymorphism
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

Painting ArrayList objects to Panel

Krysten Thomas

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: 10745

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

Joined: Oct 27, 2005
Posts: 20080

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.

How To Ask Questions How To Answer Questions
Have you checked out Aspose?
subject: Painting ArrayList objects to Panel
It's not a secret anymore!