Skip to main content



      Home
Home » Eclipse Projects » GEF » About creating an Image
About creating an Image [message #162376] Tue, 21 December 2004 11:14 Go to next message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

Why I have to create an Image in this way:
InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
Image image = new Image(null, stream);
try {
stream.close();
} catch (IOException ioe) {
}
If I write like this:
Image image = new Image(null,"shapes.gif");
will throw an exception?

thanks
Re: About creating an Image [message #162387 is a reply to message #162376] Tue, 21 December 2004 11:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Please post the exception and Image. Probably you should ask on SWT
newsgroup.
"zhlmmc" <zhlmmc@hotmail.com> wrote in message
news:cq9i5l$bnf$1@www.eclipse.org...
> Why I have to create an Image in this way:
> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
> Image image = new Image(null, stream);
> try {
> stream.close();
> } catch (IOException ioe) {
> }
> If I write like this:
> Image image = new Image(null,"shapes.gif");
> will throw an exception?
>
> thanks
>
Re: About creating an Image [message #162456 is a reply to message #162387] Tue, 21 December 2004 18:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

i/o exception FileNotFound
I put the .class and the .shapes in the same directory and my jface
application window can show the gif correctly,but my gef plugin throw
the exception.

Randy Hudson wrote:

> Please post the exception and Image. Probably you should ask on SWT
> newsgroup.
> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
> news:cq9i5l$bnf$1@www.eclipse.org...
>> Why I have to create an Image in this way:
>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>> Image image = new Image(null, stream);
>> try {
>> stream.close();
>> } catch (IOException ioe) {
>> }
>> If I write like this:
>> Image image = new Image(null,"shapes.gif");
>> will throw an exception?
>>
>> thanks
>>
Re: About creating an Image [message #162478 is a reply to message #162456] Tue, 21 December 2004 21:03 Go to previous messageGo to next message
Eclipse UserFriend
Of course you should get that exception. When you omit the path of the
file name, it is assumed that your file is located in the directory your
jvm started up rather than the directory which contains both your
specified class and that image file.

zhlmmc wrote:
> i/o exception FileNotFound
> I put the .class and the .shapes in the same directory and my jface
> application window can show the gif correctly,but my gef plugin throw
> the exception.
>
> Randy Hudson wrote:
>
>> Please post the exception and Image. Probably you should ask on SWT
>> newsgroup.
>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>> news:cq9i5l$bnf$1@www.eclipse.org...
>>
>>> Why I have to create an Image in this way:
>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>> Image image = new Image(null, stream);
>>> try {
>>> stream.close();
>>> } catch (IOException ioe) {
>>> }
>>> If I write like this:
>>> Image image = new Image(null,"shapes.gif");
>>> will throw an exception?
>>>
>>> thanks
>>>
>
>
Re: About creating an Image [message #162494 is a reply to message #162478] Tue, 21 December 2004 22:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

I see...but could you tell me why my jface application can find the file?
I think I'm not clear about the mechanism of the plugin loader in Eclipse.

thanks :)
Cloudor Pu wrote:

> Of course you should get that exception. When you omit the path of the
> file name, it is assumed that your file is located in the directory your
> jvm started up rather than the directory which contains both your
> specified class and that image file.

> zhlmmc wrote:
>> i/o exception FileNotFound
>> I put the .class and the .shapes in the same directory and my jface
>> application window can show the gif correctly,but my gef plugin throw
>> the exception.
>>
>> Randy Hudson wrote:
>>
>>> Please post the exception and Image. Probably you should ask on SWT
>>> newsgroup.
>>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>>> news:cq9i5l$bnf$1@www.eclipse.org...
>>>
>>>> Why I have to create an Image in this way:
>>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>>> Image image = new Image(null, stream);
>>>> try {
>>>> stream.close();
>>>> } catch (IOException ioe) {
>>>> }
>>>> If I write like this:
>>>> Image image = new Image(null,"shapes.gif");
>>>> will throw an exception?
>>>>
>>>> thanks
>>>>
>>
>>
Re: About creating an Image [message #162502 is a reply to message #162494] Tue, 21 December 2004 23:56 Go to previous messageGo to next message
Eclipse UserFriend
I think it is because of your eclipse launcher set the working directory
for your jface application. However, calling new Image(null, filename)
is equivalent to calling new Image(null, new FileInputStream(
filename)). You might want to print the URLs constructed by
new File(".").toURL() in both applications to see the difference.

zhlmmc wrote:
> I see...but could you tell me why my jface application can find the file?
> I think I'm not clear about the mechanism of the plugin loader in Eclipse.
>
> thanks :)
> Cloudor Pu wrote:
>
>> Of course you should get that exception. When you omit the path of the
>> file name, it is assumed that your file is located in the directory
>> your jvm started up rather than the directory which contains both your
>> specified class and that image file.
>
>
>> zhlmmc wrote:
>>
>>> i/o exception FileNotFound
>>> I put the .class and the .shapes in the same directory and my jface
>>> application window can show the gif correctly,but my gef plugin throw
>>> the exception.
>>>
>>> Randy Hudson wrote:
>>>
>>>> Please post the exception and Image. Probably you should ask on SWT
>>>> newsgroup.
>>>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>>>> news:cq9i5l$bnf$1@www.eclipse.org...
>>>>
>>>>> Why I have to create an Image in this way:
>>>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>>>> Image image = new Image(null, stream);
>>>>> try {
>>>>> stream.close();
>>>>> } catch (IOException ioe) {
>>>>> }
>>>>> If I write like this:
>>>>> Image image = new Image(null,"shapes.gif");
>>>>> will throw an exception?
>>>>>
>>>>> thanks
>>>>>
>>>
>>>
>
>
Re: About creating an Image [message #162519 is a reply to message #162502] Wed, 22 December 2004 00:18 Go to previous message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

file:/D:/Program
Files/eclipse-SDK-3.0.1-win32/eclipse/workspace/HelloWorld/. /
file:/D:/Program Files/eclipse-SDK-3.0.1-win32/eclipse/./

It's clear now :)
Thank you!

Cloudor Pu wrote:

> I think it is because of your eclipse launcher set the working directory
> for your jface application. However, calling new Image(null, filename)
> is equivalent to calling new Image(null, new FileInputStream(
> filename)). You might want to print the URLs constructed by
> new File(".").toURL() in both applications to see the difference.

> zhlmmc wrote:
>> I see...but could you tell me why my jface application can find the file?
>> I think I'm not clear about the mechanism of the plugin loader in Eclipse.
>>
>> thanks :)
>> Cloudor Pu wrote:
>>
>>> Of course you should get that exception. When you omit the path of the
>>> file name, it is assumed that your file is located in the directory
>>> your jvm started up rather than the directory which contains both your
>>> specified class and that image file.
>>
>>
>>> zhlmmc wrote:
>>>
>>>> i/o exception FileNotFound
>>>> I put the .class and the .shapes in the same directory and my jface
>>>> application window can show the gif correctly,but my gef plugin throw
>>>> the exception.
>>>>
>>>> Randy Hudson wrote:
>>>>
>>>>> Please post the exception and Image. Probably you should ask on SWT
>>>>> newsgroup.
>>>>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>>>>> news:cq9i5l$bnf$1@www.eclipse.org...
>>>>>
>>>>>> Why I have to create an Image in this way:
>>>>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>>>>> Image image = new Image(null, stream);
>>>>>> try {
>>>>>> stream.close();
>>>>>> } catch (IOException ioe) {
>>>>>> }
>>>>>> If I write like this:
>>>>>> Image image = new Image(null,"shapes.gif");
>>>>>> will throw an exception?
>>>>>>
>>>>>> thanks
>>>>>>
>>>>
>>>>
>>
>>
Previous Topic:How to add figures programmatically
Next Topic:What is GEF
Goto Forum:
  


Current Time: Sun Jul 06 14:30:38 EDT 2025

Powered by FUDForum. Page generated in 0.04292 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top