Swing example and exiting, do I need a thread

9 views
Skip to first unread message

BerlinBrown

unread,
Apr 24, 2008, 3:57:24 PM4/24/08
to Clojure
I am creating a simple swing application. This is essentially the
core jframe creation code. Without the sleep thread, the frame
exits. I didn't think I needed an infinite loop to wait till the
frame exited.

Or maybe this is a basic swing question. Or is there something about
clojure and threads that is different than regular java code.

-----------

(defn createReaderFrame []
;; Create the simple reader frame
(let [simpleFrame (new JFrame "Swing View Client")]
(init-swing simpleFrame)
(. simpleFrame (pack))
(. simpleFrame (setVisible true))))

(defn lisp-main []
;; Main entry point, create the jframe and attach the widget
components then
;; start the jframe thread"
(println "INFO: creating panel objects")
(createReaderFrame))

(lisp-main)
(. Thread (sleep 20000))
(println "INFO: exiting.")

BerlinBrown

unread,
Apr 24, 2008, 4:30:13 PM4/24/08
to Clojure
And another similar question:

(defn initMenus [jframe]
(let [bar (new JMenuBar)
fileMenu (new JMenu "File")
newMenuItem (new JMenuItem "New")
openMenuItem (new JMenuItem "Open")
exitMenuItem (new JMenuItem "Exit")]
(. fileMenu (add newMenuItem))
(. fileMenu (add openMenuItem))
(. fileMenu (add exitMenuItem))
(. bar (add fileMenu))
(. jframe (setJMenuBar bar))
;;---------------------
;; Attach the listeners
;;---------------------
(. exitMenuItem
(addActionListener
(implement [ActionListener]
(actionPerformed [evt]
(println "INFO: Exiting")
(exit)))))))

-------------

Caused by: java.lang.Exception: Unable to resolve symbol: implement in
this cont
ext
at clojure.lang.Compiler.resolveIn(Compiler.java:3539)
at clojure.lang.Compiler.resolve(Compiler.java:3514)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:3499)
at clojure.lang.Compiler.analyze(Compiler.java:3305)
at clojure.lang.Compiler.analyze(Compiler.java:3292)
at clojure.lang.Compiler.access$100(Compiler.java:37)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2435)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:3427)


I get this error when using "implement"; I thought implement is a new
function.

I am assuming the code from maven, as of 2 days ago. I wonder what
would create this error.

Christophe Grand

unread,
Apr 25, 2008, 4:12:43 AM4/25/08
to Clojure
When you run a program as a script (outside of the repl), clojure
automatically exits when it reach the end of the program.
Rich added this auto-exit feature because people using agents where
complaining that their scripts never end. (See:
http://groups.google.com/group/clojure/browse_thread/thread/dad4f2d740cc6e1e/94c44d50d433e1ee?lnk=gst&q=thread+daemon#94c44d50d433e1ee)

A possible workaround: http://groups.google.com/group/clojure/browse_thread/thread/90db306dd734c39b#

Christophe

Christophe Grand

unread,
Apr 25, 2008, 4:19:45 AM4/25/08
to Clojure
On Apr 24, 10:30 pm, BerlinBrown <berlin.br...@gmail.com> wrote:
> I get this error when using "implement"; I thought implement is a new
> function.

"implement" has been superceded by "proxy".

Christophe
Reply all
Reply to author
Forward
0 new messages