HI,

You'd be best served overriding the JPanel's paint or paintComponent
method (I'm fuzzy on the difference), and then calling repaint
periodically (at your desired frame rate).  IIRC, repaint is safe to
call from any thread, and it will cause the paint methods to be called
in the swing thread.  Also, try to ensure your swing setup code runs
in the swing thread if possible (see Brian's reply).

See also :
Background on Java 2D: http://java.sun.com/docs/books/tutorial/2d/TOC.html
contrib has a do-swing macro for evaling in the swing thread:
http://richhickey.github.com/clojure-contrib/swing-utils-api.html

Ryan


On Jul 24, 9:11 am, Mate Toth <totm...@gmail.com> wrote:
> Hi,
>
> my problem is that during execution my presentation java applet is
> flashing. There are many components which paint to a JPanel using it's
> Graphics (.getGraphics). I think maybe the problem is that I don't
> have any "paint everything now" routine..(I don't know which Java
> routine to use, how I have to synchronize it etc..) Thanks for your
> time and help.
>
> I've the following code for the gui part (fe stands for "flocking-
> enviroment", I'm making a flocking library):
>
> The main loop:
>
> (defn main [starting-fe]
>   (let [first-fe starting-fe
>         panel (new JPanel)
>         frame (new JFrame)]
>
>     ;; configuring panel
>     (. panel setPreferredSize (new Dimension width height))
>
>     ;; configuring frame
>     (. frame add panel)
>     (. frame pack)
>     (. frame setVisible true)
>
>     (loop [fe first-fe]
>       (draw-fe fe panel)
>       (Thread/sleep 100)
>       (recur ((:update-f fe) fe)))))
>
> Blanking the screen:
>
> (defn blank-panel [panel]
>     (let [g (. panel getGraphics)]
>       (. g setColor (. Color BLACK))
>       (. g fillRect 0 0 width height))))
>
> At the end every boid drawed by this(called by the draw-fe function):
>
> (defn draw-boid [boid panel]
>     (let [[x0 x1] (:pos boid)]
>       (let [g (. panel getGraphics)]
>         (. g setColor (:color boid))
>         (. g fillRect (- x0 2) (- x1 2) 5 5)))))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to