After discovering Clojure, reading everything I could about it, and
loving everything I saw, the next logical step was to start playing
with it.

Being a complete Java novice, I have absolutely no experience with its
libraries and was hoping to become more acquainted with them. One of
the first things I've tried to do is create a simple Swing app that
loads and displays an image, based mostly on the code here:
http://java.sun.com/docs/books/tutorial/2d/basic2d/examples/WeatherWizard.java

I have a fairly simple question as well as a problem that have arisen
from my attempts.

In trying to create a basic image loading function based on this:

    private BufferedImage loadImage(String name) {
        String imgFileName = "images/weather-"+name+".png";
        URL url = WeatherWizard.class.getResource(imgFileName);
        BufferedImage img = null;
        try {
            img =  ImageIO.read(url);
        } catch (Exception e) {
        }
        return img;
    }

I've come up with the following function (which obviously has no
exception handling and unlike the original takes a full filename as an
argument):

(defn load-image [name]
  #^BufferedImage (. ImageIO (read (new File name))))

Firstly: is this an acceptable/possible/necessary use of type hints?
Would this be equivalent?

(defn  #^BufferedImage load-image [name]
  (. ImageIO (read (new File name))))

Or this:

(def #^BufferedImage load-image (fn [name]
                                                  (. ImageIO (read
(new File name)))))

Secondly, and seemingly unrelated to the type hint: This function does
not work. I get a "java.lang.Exception: Unable to resolve symbol:
ImageIO in this context." This has been frustrating me, since it seems
like such a trivial function to be porting. Is this simply my not
understanding some part of the underlying libraries, or am I so dense
that I'm not grasping some basic Clojure syntax?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to