Re: Giving an application a window icon in a sensible way
Twisted wrote:
Let's consider the following points (ALL of which have been raised
before, but obviously in posts that some participants here have clearly
not bothered to read):
1. At the time I made the initial posting to this thread, a google
search had failed to reveal *any* "standard way" to include icons
whatsoever.
http://www.google.com/search?num=100&hs=w8D&hl=en&lr=&safe=off&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=java+resource+loading+&btnG=Search
I see quite a few links to ClassLoader.getResource, hmm, how about
that.
2. Before any replies had been made, further attempts at googling the
topic finally turned up a page on Sun's Java site describing a method
-- the method I actually used. This page also mentioned some other
methods, but those were only applicable to applets, not stand-alone
applications (they involved requesting the icon from a URL, either
relative to document base or code base, from the applet's host server),
while the first method was applicable to both.
Was this in a forum? Just because its on suns site doesn't mean its
reliable.
3. All of the replies appear to require additional tools (most commonly
Ant). The time investment involved in finding, obtaining, and learning
the additional tools is not justified until I've got more than a single
32x32 gif (and really only if I have stuff that should be localizable
or hot-swappable or something).
Actually, most of them suggested using ClassLoader.getResource, and
that if you thought it was difficult to create jar files, try using ant
instead. The suggestion may have been off topic, but it was only meant
to help.
5. The very last place to go for trustworthy information on doing stuff
in Java is www.sun.com. Google and wikipedia must also be stringently
avoided.
This seems to be what you do, I usually get my information from Google,
or perhaps a book written on the subject.
6. It's far more important to do things the Standard Way(tm) and
conform and fit in than to actually get something working, or to learn
or accomplish things on your own.
Actually, it is important to understand standards and to adhere to
common conventions and best practices. Just like the idea of Patterns
helps everyone communicate better, so does using the same approach to
solving the same problems. "I used the State pattern" is a whole lot
more concise than "I used an object that describes this other objects
current state and defines behaviors based on the state." Most
developers will see your use of ClassLoader.getResource, and know how
to handle, most will see your current solution and say "WTF?".
7. A simple solution is usually wrong; a complicated one that involves
at least two completely new build tools or distribution tools is
invariably better.
Actually, I think you've come up with a complicated solution.
Step 1, convert image to XPM,
Step 2, run some tool to convert it to a class file.
Step 3, move the class file into the correct place.
Step 4, use some uncommon third party tool to load and convert the
class's data..
Step 5, Fix the third party tool, because it was broken.
Step 6, Fix the third party tool again, because it was broken in
another way.
The way that most of us have suggested takes this form:
Step 1, move or copy your image into a directory in your project
Step 2, use ClassLoader.getResource() to retrieve the resource
Step 3, use standard Sun class (java.* and javax.*) to load the
resource as an image
Allrighty then ...
Yeah, Alrighty then.
If you're not going to take the advice of people on comp.lang.java.*,
then I suggest you stop wasting your time and ours.
There are a lot of smart people here who take time out of there day to
help people. If all you want to do is come up with your own way, and
then blame the standard library when you encounter a bug, be my guest.
Just don't waste MY time doing it.