java-interop

Trouble understanding :state in Clojure.

I understand what :state /does/. It creates a field, like in Java, in your class. What I don't understand is what is the point of this? It seems like I only see it done with Clojure-generated classes that extend other classes. http://www.fatvat.co.uk/2009/05/clojure-and-robocode.html being one example. I don't know Java, and I'm not very...

When you extend a Java class in Clojure and define a method of the same name as one in that class, what is happening?

I've been reading through Programming Clojure, and I've been having some trouble understanding Stuarts primary Java Interop example. He extends DefaultHandler, and creates a startElement method, and then passes that handler to an XML parser. What I don't understand, is what exactly is happening. Does his implementation of startElement ov...

Having trouble calling getCodeBase in Clojure

I'm trying to write a function to play a sound file once, using some resources I found. The code is as follows: (defn play [file] (let [songp (URL. (.getCodeBase) file) song (.newAudioClip songp)] (. song play))) The problem is, (.getCodeBase) is a malformed member expression. I'm not sure what to do. How do you call a meth...

Does Clojure have an equivalent of Java's import package.*?

Or do I have to specifically enumerate every class that I import? I'm just learning Clojure now, and it seems useful to be able to do something like this in the REPL: (import '(java.io *)) Not that this is valid syntax, but it would be nice to have something that does the equivalent. It would save some typing, especially when tink...

How do I pull `static final` constants from a Java class into a Clojure namespace?

I am trying to wrap a Java library with a Clojure binding. One particular class in the Java library defines a bunch of static final constants, for example: class Foo { public static final int BAR = 0; public static final int SOME_CONSTANT = 1; ... } I had a thought that I might be able to inspect the class and pull these ...

How can I define a clojure type that implements the servlet interface?

I'm attempting to use deftype (from the bleeding-edge clojure 1.2 branch) to create a java class that implements the java Servlet interface. I would expect the code below to compile (even though it's not very useful). (ns foo [:import [javax.servlet Servlet ServletRequest ServletResponse]]) (deftype servlet [] javax.servlet.Servle...

Hosting QT gui app within Java gui app

I have a gui app A, written in QT and another gui app B, written in Java. I wish to make app B the container of app A.I reparent windows in app A with windows in app B by passing proper handles to it. However, windows in app A dont get painted properly when app B is refreshed. Do I have to pass refresh events across to app A? Cant the ...

MPXJ in .NET converting java Date to .NET DateTime

I'm using the MPXJ library in .NET for parsing MS Project (MPP) files, and it's working great. The one issue I'm having is trying to translate the task Start and Finish date into .NET DateTime to use with my data models. I am going through all the tasks and calling task.getFinish() and task.getStart() that both return javva.util.Date o...

Clojure's :gen-class and double arrays

I am attempting to :gen-class a fn which takes a 2D array of Doubles as input. I have already seen the post and solution here concerning a similar topic, but I am still unable to produce a working solution. (ns gui.heatmap (:gen-class :name gui.Heatmap :methods [[heat-map2 ["[[D"] org.jfree.chart.JFreeChart]])) (defn foo [dbl...

Calling Java from Scala: protected constructor

This compiles without error on Scala 2.8.0 final: import javax.swing.tree.TreePath object A extends Application { val path1 = new TreePath() val path2 = new TreePath(path1, "foo") } However, on execution I get: java.lang.IllegalAccessError: tried to access method javax.swing.tree.TreePath.<init>()V from class A$ at A$.<init>...