Hi.
I'm trying to create a java.io.Writer proxy (which writes to a
JTextArea) but I can't get it to work.
Here is my clojure code so far:
(def text-area (javax.swing.JTextArea.))
(def frame
(let [f (javax.swing.JFrame.)]
(.. f getContentPane (add text-area))
(.setMinimumSize f (java.awt.Dimension. 200 200))
(.setVisible f true)
f))
(def text-area-writer
(proxy [java.io.Writer] []
(close [])
(flush [])
(write [^chars chrs ^int offs ^int len]
(.append text-area (String. chrs offs len)))))
When I load the code above I get an "IllegalArgumentException: Unable
to resolve classname: int" so I think I'm not type hinting correctly.
Here is a similar piece of java code which works as expected:
public class Main extends JFrame {
private JTextArea text;
public Writer writer;
public Main() {
text = new JTextArea();
getContentPane().add(text);
setVisible(true);
setMinimumSize(new Dimension(200, 200));
writer = new TextAreaWriter();
}
class TextAreaWriter extends Writer {
public void close() throws IOException {}
public void flush() throws IOException {}
public void write(char[] chrs, int offs, int len) throws IOException {
String str = new String(chrs, offs, len);
text.append(str);
}
}
public static void main(String[] args) throws IOException {
Main m = new Main();
m.writer.write("Hello, World!");
}
}
Any help is much appreciated!
/Jonas
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en