Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

imageObserver -- still don't understand

Thread view: 
Dmitriy.pindrik@gmail.com - 18 Apr 2006 14:18 GMT
I've read all I can about what imageObserver is and how to
implement/use it.  After several hours of reading, I am still failing.
Here is a piece of my code - any help, pointer, or comments is
appreciated because as of right now, it's not fuctioning at all.

All that is supposed to happen is I want image map7bg.bmp to paint...
simple as that.

<code>
public class Engine extends Applet implements KeyListener,
ImageObserver
{
  <--code omited-->
  public void paint(Graphics g)
  {
     Image i = (Toolkit.getDefaultToolkit()).getImage
("C:/map7bg.bmp");
     g.drawImage(i,1,1, this); //also tried null instead of null
  }

  public boolean imageUpdate(Image img, int infoflags, int x, int y,
int width,int height)
  {
     return false;
  }
}
</code>

I added that imageUpdate method after reading about it online, seems I
need it for imageObserver to work.

Thanks in advance for any help,
Dima
Thomas Fritsch - 18 Apr 2006 14:58 GMT
> I've read all I can about what imageObserver is and how to
> implement/use it.  After several hours of reading, I am still failing.
[quoted text clipped - 13 lines]
>       Image i = (Toolkit.getDefaultToolkit()).getImage
> ("C:/map7bg.bmp");
There are several problems with the line above:
(*) Toolkit.getImage doesn't support BMP files (only GIF, JPEG, XBM, PNG).
(*) "C:/map7bg.bmp" has the wrong slash. Use "C:\\map7bg.bmp" on Windows.
(*) Applet security normally forbids accessing local files.
(*) Your paint-method might be called several hundred times per second.
   It is therefore a bad idea to call getImage(...) here. You should
   make i a member variable and put the 'i = ...;' code somewhere else,
   may be in your applet's init() method.

>       g.drawImage(i,1,1, this); //also tried null instead of null
>    }
[quoted text clipped - 5 lines]
>    }
> }
Normally you should *not* implement an imageUpdate(...) method of your own.
java.applet.Applet has already an imageUpdate(...) method (inherited from
java.awt.Component) which does a fine job. Your implmenentation is
especially wrong, because your "return false;" means: 'I have received the
complete image now. Don't call imageUpdate(...) again!'. See also the API
doc Component#imageUpdate and may be the source code of
Component#imageUpdate, too.

> </code>
>
[quoted text clipped - 3 lines]
> Thanks in advance for any help,
> Dima

Signature

"Thomas:Fritsch$ops.de".replace(':', '.').replace('$', '@')

alexandre_paterson@yahoo.fr - 18 Apr 2006 15:59 GMT
...
> (*) "C:/map7bg.bmp" has the wrong slash. Use "C:\\map7bg.bmp" on Windows.

Actually the forward slash works just fine as a file separator under
Windows in this case.

:)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.