Monthly Archives: December 2007

Loading images in Java

In the Java project I am working on I needed to load an image from a file (representing a unknown user profile) for display to the user. This is easy to do. However, in production the application runs from a jar file, so I want my app to find the image inside the jar file. There are a number of example web pages on how to load images from jar files.

But I wanted something that also worked when I was developing in Eclipse, and none of the examples I found worked unless the application was running from a jar file. Here’s my simple solution:


// Try to grab unknown profile icon from JAR file
URL picturePath = this.getClass().getResource("/images/unknown-profile.jpg");
// However, if we are running from Eclipse then no JAR file
if (picturePath == null) {
  try {
    picturePath = new URL("file://" + System.getProperty("user.dir")
        + "/images/unknown-profile.jpg");
  }
  catch (MalformedURLException e) {
    System.out.println(bogusErrMessage);
  }
}
if (picturePath != null) {
  this.picture = new ImageIcon(picturePath);
  this.profile.setPhotoUrl(picturePath.toString());
}

Of course you need to have an “images” directory at the top level of your project directory, and you need to write appropriate ant tasks to copy over your images directory to your build directory when you create the jar file.

Advertisements

December Govinda’s menu

Here’s the December menu for Govinda’s. Note that the UH outpost closes after Friday December 14th.

Mon 3rd
Marrakesh Curried Stew V
Thai Red Curry V

Tues 4th
Fresh Mashed Potatoes w/Sautéed Broccoli & Green Peas
Eggplant and Spinach Curry with Coconut Milk  V

Wed 5th
Thai Yellow Curry  V
Lasagna (served with brown rice or soup)

Thurs 6th
Walnut Dumplings with Mixed Veggies in a Sweet & Sour Sauce V
Palak Paneer (spinach & fresh cheese squares) with Cauliflower

Friday 7th
Roasted Eggplant & Orzo Casserole with Cheddar & Parmesan Cheese
Channa Massala (Organic Chickpeas with Tomatoes, Cauliflower and Organic
Tofu)  V

Mon 10th
Thai Red Curry   V
Enchilada’s

Tues 11th
Shahi Paneer (Braised Tofu with MixedVeggies, Indian style)
Vegetables au gratin

Wed 12th
Eggplant Parmesan
Thai Yellow Curry V

Thurs 13th
Eggplant and Mixed Veggie Curry in lightly spiced cream sauce
Kofta Balls with mixed Veggies & Tofu in Tomato Sauce  V

Friday 14th     (Last Day At UH Manoa)
Baked Ziti Casserole with Spinach & Green Peas (served with soup or brown rice)
Sweet Potato, Organic Tofu & Mixed Veggie Curry in Coconut Milk V

*Fort Street Remains Open:*

Mon 17th
Thai Yellow Curry V
Enchilada’s

Tues 18th
Sauteed Broccoli, Cauliflower, Green Pea & Potatoes in Spiced Cream Sauce
Corn Fritter with Zucchini and Celery in tomato sauce V

Wed 19th
Thai Red Curry V
Lasagna

Thurs 20th
Cauliflower Paneer and Green Peas in Tomato Sauce
Walnut Dumplings in a Sweet & Sour Veggie Sauce V

Friday 21st
Roasted Eggplant & Orzo Casserole with Cheddar & Parmesan Cheese
Cauliflower and Organic Mixed Veggie Curry with Braised Garbanzo’s

Mon 24th    Closed for Holiday

Tues 25th     Merry Christmas!  Closed

Wed 26th
Thai Yellow Curry V
Eggplant Parmesan

Thur 27th
Tuscan Vegetable Sauté   V
Homemade Seitan with Mixed Veggies & Tomato Sauce  V

Friday 28th
Roasted Eggplant & Orzo Casserole with Cheddar & Parmesan Cheese
Falafel Dumplings with Zucchini and Cauliflower in Coconut Milk Sauce  V

Mon 31st
Thai Red Curry
Enchilada’s