Results 1 to 4 of 4
  1. #1
    RTP_123 is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Image Observer class

    Hey guys, I'm writing a code in the Java IDE Ready to Program, (for those of you who don't know its the IDE by Holtsoft, they're out of business now, but I need to use it). In my code I'm inputting several different images, and i need each image to be called upon several times. And when I run my program it works fine, the pictures appear, but when i try to call upon the image more than once it simply doesn't show up. Anyways, here is a simplified version of my program (just the image call and loop).


    // The "Help" class.
    import java.awt.*;
    import hsa.Console;
    import java.awt.image.*;
    public class Help
    {
    static Console c; // The output console
    static Image theGraphic;

    public static void main (String[] args)
    {
    c = new Console ();
    do
    {
    theGraphic ();
    c.getChar ();
    c.clear ();
    }
    while (2 > 1); //create an infinite loop, for testing puropses
    } // main method


    private static void theGraphic ()
    {
    Toolkit tk = Toolkit.getDefaultToolkit ();
    theGraphic = tk.getImage ("image location");
    tk.prepareImage (theGraphic, -1, -1, new Observer1 ());
    }//prepare the image


    static class Observer1 implements ImageObserver
    {
    public boolean imageUpdate (Image img, int infoflags, int x, int y, int width, int height)
    {
    c.drawImage (img, 0, 0, null);

    return true;
    }
    }//draw the image
    } // Help class


    if any one can tell me how to make it work the way i need it to work I would greatly appreciate it.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Image Observer class

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Image Observer class

    Since not many (if any) members will be familiar with the hsa.Console class, you may have a long wait for help with that code. However, I'll give you this: Toolkit caches an image obtained from a specific location and doesn't reload the image from the same location on demand. One way to force a reload is to flush() the Image.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Image Observer class

    Also, there's a fair probability that the infinite loop without so much as a sleep(...) is tying up system resources.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Observer/Observable help...
    By chyrl in forum Advanced Java
    Replies: 5
    Last Post: 01-14-2011, 05:41 PM
  2. Pattern Observer
    By brontolo in forum Advanced Java
    Replies: 6
    Last Post: 09-02-2010, 03:40 PM
  3. Problem with observer pattern
    By livnihai in forum New To Java
    Replies: 5
    Last Post: 10-11-2009, 03:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •