I see 2 things:
1) It's best to explicitly start your Swing UI on Swing's event dispatch
thread. The java code to do this is:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new App(); // OR whatever you're started UI code is
}
});
2) You're calling Thread.sleep on the same thread you're drawing your UI. If
that's the EventDispatchThread, you're stopping all drawing events while the
thread is sleeping.
Cheers
B
On Sat, Jul 24, 2010 at 06:11, Mate Toth <[email protected]> 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 [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]<clojure%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Brian Schlining
[email protected]
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en