Re: Giving an application a window icon in a sensible way



Twisted wrote:
Daniel Dyer wrote:
It should take less than a second to create a JAR file, unless you have
hundreds of classes in it or a very slow machine. It should also be
trivial to make it part of the automated build process even if you are not
using Ant.

I'd still be
leery of its only home being in the jar; properly, files like that are
part of the source code too and should be housed with it and just
*copied* into the jar. Preferably automatically. Now maybe this can be
done, but if so, nobody has bothered to tell me so, or suggest how.

You have to recognise that there are three broad types of file that we
are discussing here, source files, compiled files, and resources.
Images, XML documents, property files etc are resources, not source
files. Your jar file can simply have a 'resources' directory with your
resource files inside and you can use
getResource("resources/myimage.gif"). If you do not have a jar file
(but I would strongly recommend it) you just make sure the resources
directory is at one of your classpath roots (which doesnt have to be
global, can be set in a start up script) and it will work just the
same.

The automatic solution you seek is ant. I can only repeat what others
have said, ant is a very worthwhile tool to add to your repotoire and
is not hard to learn at all. When you have put your ant build together
(and consider looking at open source projects for examples) you will
have grown as a developer and will wonder why you ever did it any
other way... you have my personal guarentee on that (for what it is
worth).

The problem I see with your approach is there is a lot more work if you
want to change the image. This might not be a problem right now but is
something to keep in mind.

I changed it several times, tweaking it, without difficulty last night
-- it's a matter of re-exporting the image, then pasting in a different
string array literal, and that's all.

You are in a common situation, you have a solution that works, but
others are telling you to do it another way. In software development,
"but my way works fine!" is a wonderful defence, and in your current
application, I can see no immediate reason to change.

However, recognise that your solution will not easily scale. You may
soon be working on applications where there are many non-java
resources. There many be many different people, with many different
skills working on these resources. Very quickly, you will get into a
situation where you are constantly updating these bizarre,
uninterpretable strings. You wont know which string represents which
file, you will find that you do a build and have forgotten to update
the string to the new one representing the last update your gfx
designer has made etc etc. What people are trying to tell you is, that
while you solution works functionally, it could be regarded as a bad
habit. If you break it now, and accept that while your solution is very
novel, there is a reason why the rest of the Java community uses the
provided getResource method, you will be better off in the long term...
another personal guarentee on that.

* Find out how to make it get included in the jar automatically;

Ant

* Find out how to make it build the jar for every test automatically;

Ant

* Have the application do I/O and error recovery on startup, which it
didn't previously have to do;

The fact that IOException is checked (or infact that java even has
checked exceptions) is a point of theorectical debate. It is reasonable
for your code to catch and IOException, print and error and exit. If
you get this error, somebody has tampered with the Jar file after
release. If I took a hex editor to winword.exe and removed some stuff,
I would expect it to error out also :)

* Now that it can die at startup with a file not found or whatever
error, make it gracefully report the problem when it does so, and
suggest fixes;

Again, this can only happen if your users are tampering. As long as you
build your jar file and deliver it with the image inside, it will not
just out by itself.

In general, I have to say, I admire the way you stick to your guns, and
this isnt really a question of "right and wrong". It is just that there
are disadvantages to your approach that you are either unwilling or
unable to see, and advantages to getResource that you are treating in
the same way. You refuse to learn ant because it is "yet another thing"
but correct use of this tool will solve most of the problems you have.
If you are pushed for time on delivery of your current software, then
continue with your current approach, it works. You should, however, put
aside some time to see how everyone else is solving the problem. Learn,
grow and get the same satisfaction out of working with standard tools
as you did in coming up with your unconvential yet functional solution
to the problem at hand.

I wish you luck.

.



Relevant Pages

  • Re: Server Control Deployment and Client Scripts?
    ... for these resources when they render the HTML tags. ... public string HandlerName ... private void ShowEmbeddedResources(HttpContext context) ... private void ExtractEmbeddedResource ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: Property name
    ... class Resource // This class is autogenerated by Visual Studio. ... Logging a message from resources. ... If I hover the mouse over M001 in Visual Studio, ... I don't want to get "param" as a string here. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: One resource file per CDialog or VSS solution
    ... via member variables, a dialog never needs to see any variables of the application. ... The first part of the solution to this problem is to **checkin resources as ... there is an easy solution: Allocate a string id range to each ... Actually we are 4 programmers building interfaces. ...
    (microsoft.public.vc.mfc)
  • Help with WNetOpenEnum and WNetEnumResource
    ... I'm trying to enumerate all the resources on my network (domain, ... Using this class the string data pointed to seemed to be ... were stored in VB string types after enumerated? ...
    (microsoft.public.vb.general.discussion)
  • Re: Why cant CLASSPATH be set on the fly
    ... Is it part of the security of Java, ... I have an application that finds plugin jars in the right directory. ... Classes in the plugin jar file can see classes in the main application, ... and had a static utility method to fetch resources. ...
    (comp.lang.java.programmer)