Hello, there! I'm building an image-processing application in swing/clojure, and right now I need to develop an image panel in which I can click and compute data. Thanks to coobird, I now have a good idea on how to do it in Java, but I still don't get many issues on its integration with Clojure.
Let's take a look at how coobird suggested me doing. First, we should extend a class in Java. In clojure, we do this with the proxy
macro, so we'd have something like this:
(def painting-panel (proxy [JPanel] []))
The next step is to create the class constructor and set some variables.
I can define functions after the second argument of proxy, but how can I create the constructor? Is painting-panel the name of this class (therefore the name of the function I should create)?
How can I deal with class variables? Should I define them with a
let
, like I did?Are
this
andsuper
available for me to use, like I did below?
(def painting-panel (let [background-image (Image.) point-clicked (Point.)] (proxy [JPanel] [] (paintCompone*emphasized text*nt [g] (do ((.paintComponent super) g) (doto g (.drawImage background-image 0 0 nil) (.fillRect (.x point-clicked) (.y point-clicked) 1 1)))) (painting-panel []; constructor? ((.addMouseListener this) (proxy [MouseAdapter] [] (mouseClicked [e] (do (def point-clicked (.getPoint e)) (.repaint this)))))))))
Suggestions and code corrections are also welcome!
Thank you!