The simple gui example doesn't seem to be working correctly in svn or 03292008

1 view
Skip to first unread message

akopa

unread,
Apr 4, 2008, 2:39:21 AM4/4/08
to Clojure
The http://en.wikibooks.org/wiki/Clojure_Programming#Examples gui
example doesn't seem to work when saved to a file and loaded as a
script. I've have tried both with the current release and svn head. A
window briefly flashes, then goes away. This happens on java 1.6 in
windows, and java 1.5 in os-x and linux. When I enter the program
instead in the clojure-slime repl, I get a frame with no buttons.

Matt

Geoff

unread,
Apr 17, 2008, 3:31:41 AM4/17/08
to Clojure
In the previous version of Clojure, the program would stay alive as
long as the window was open. Now the program stops and the window
closes when it reaches the end of the file.

You can see the intended effect by adding (. Thread (sleep 10000)) to
the end of the file.

Of course, you then need to break the program once you close the
window, because it's still busy sleeping. I'm sure there's a better
way, but I'm new to this.

Christophe Grand

unread,
Apr 17, 2008, 4:27:25 AM4/17/08
to clo...@googlegroups.com
Geoff a écrit :

> In the previous version of Clojure, the program would stay alive as
> long as the window was open. Now the program stops and the window
> closes when it reaches the end of the file.
>
> You can see the intended effect by adding (. Thread (sleep 10000)) to
> the end of the file.
>
I guess you're using clojure.lang.Script. Since r749 System.exit(0) is
called at the end of the program execution (on main thread).
In your case, you can work around this by:
- adding (let [o (new Object)] (locking o (. o (wait))))
at the end of the file causing the main thread to wait (and thus
preventing System.exit to be executed)

- uncommenting (setDefaultCloseOperation (. JFrame EXIT_ON_CLOSE)) (to
exit when the main window is closed).

Hope this helps.

Christophe

Reply all
Reply to author
Forward
0 new messages