Article View: borland.public.jbuilder.java.api
Article #323Re: Problems with loading & displaying a picture
From: marcin brzoza
Date: Tue, 03 Feb 2004 08:00
Date: Tue, 03 Feb 2004 08:00
76 lines
3468 bytes
3468 bytes
hi,
Errata:
WRONG: ClassLoader loader = this.getClassLoader();
OK: ClassLoader loader = this.getClass().getClassLoader();
sorry :)
On Mon, 02 Feb 2004 22:29:57 +0100, Andreas Koch wrote:
>> They must be on the classpath.
> Forgive my stupidy. I have about 5 hours of java experience. What exactly
> is the "classpath"?
Classpath is like path ;) More about (in german):
http://uebb.cs.tu-berlin.de/infet/classpath.html
> /MyProject/classes ?
No, it is output directory for JBuilder. You can set it, ex.:
SET CLASSPATH=c:\projects\test2\classes\;%CLASSPATH%
BTW: JBuilder do it (in Messages: 'java -classpath "..."'), if you runs
the application from IDE ;)
>> For instance, if you have the package and class
>> org.myorg.views.MyPanel
> If have the project test2.jpx which has a class named
> ClockAnalogBuf.java. No idea what a package is :-)
Package is like Delphi Unit, is defined... as first in your class, ex.:
package test2;
> Ok, i put my images in two (identical) images subfolders:
>
> /test2
> /bak
> /classes
> /package cache
> *test2.dep2
> /test2
> *ClockAnalogBuf.class
> ...
> /images
> *0196.png
> ...
> /doc
> /src
> /test2
> *ClockAnalogBuf.java
> ...
> /images
> *0196.png
> ...
>
>> Given this packaging/directory structure, you would get your Image
>> using
>>
>> URL url = MyPanel.class.getResource("images/image1.png"); // with the
>> URL, you can now get your ImageIcon.
>
> Doesn't work:
> TileGfx[0] = toolkit.getImage("/images/0196.png");
> Doesn't work:
> TileGfx[0] = toolkit.getImage("images/0196.png");
The path to image should include the full name of package:
toolkit.getImage("test2/images/0196.png");
> Works:
> TileGfx[0] =
> toolkit.getImage("c:/projects/test2/classes/test2/images/0196.png");
You are using absolute path.
> Is there any difference in the file name handling of getResource vs.
> toolkit.getImage ?
Yes. If you use toolkit, you must use Mediatracker. With
ClassLoader.getResource() you can read resources (like text files or
images) from classpath or jar files.
good luck
marcin
Technical Details
Message-ID:
<pan.2004.02.03.08.00.17.788217@yahoo.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-05!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<401d06eb$1@newsgroups.borland.com> <pan.2004.02.02.08.34.02.603265@yahoo.de> <401e9d7b@newsgroups.borland.com> <401eb6e1@newsgroups.borland.com> <401ec0a4$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,cc9d3c5ba1462852 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2004-02-03 00:09:32 PST From: marcin brzoza <marcin4@yahoo.de> Subject: Re: Problems with loading & displaying a picture Date: Tue, 03 Feb 2004 09:00:18 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity. (Debian GNU/Linux)) Message-ID: <pan.2004.02.03.08.00.17.788217@yahoo.de> Newsgroups: borland.public.jbuilder.java.api References: <401d06eb$1@newsgroups.borland.com> <pan.2004.02.02.08.34.02.603265@yahoo.de> <401e9d7b@newsgroups.borland.com> <401eb6e1@newsgroups.borland.com> <401ec0a4$1@newsgroups.borland.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 80.141.21.245 X-Trace: newsgroups.borland.com 1075795290 80.141.21.245 (3 Feb 2004 00:01:30 -0800) Lines: 76 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-05!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail