若要将侦听器添加到Seesaw中的UI元素,请执行以下操作:
(listen ui-element :action (fn [_] (...)))listen附加了一个监听器,当在‘`ui Element1上触发:action时,它会调用提供的函数。它还返回一个函数。如果执行该函数,它将删除与原始调用一起添加的侦听器。
我一直在使用Seesaw在REPL中创建UI原型,并且没有保存来自listen的返回值。
如果没有返回的函数,如何删除侦听器?
发布于 2013-05-23 05:06:42
您可以以以下粗俗的方式手动删除侦听器:
user=> (def b (button :text "HI"))
user=> (listen b :action #(alert % "HI!"))
user=> (-> (frame :content b) pack! show!)
; click the button, see the alert
; manually remove listeners
user=> (doseq [l (.getActionListeners b)] (.removeActionListener b l))
; click the button, nothing happens您可以将其放入助手函数中,并随时使用它。以某种方式将其内置到seesaw.event或seesaw.dev中也会很好。欢迎补丁。:)
发布于 2013-05-23 04:37:12
如果没有函数引用,就不能这样做。您可以做的是在REPL中使用*1特殊的vara,它基本上存储上一次执行表达式的结果,以便从REPL中删除处理程序。
https://stackoverflow.com/questions/16704743
复制相似问题