Loading Images into Applets

I've been having problems loading an image into an Applet. I've found that when the getImage() call is put into the init() method it loads the image fine, also implementing an imageUpdate call. However, now I'm trying to expand on this by putting it into a button click, it hangs indefinitely while waiting for the image to load.
Another interesting point I've noticed is that the Canvas subclass ImageSegmentSelector uses a PixelGrabber in its constructor to put the Image into a buffer - when this class is created from the imageUpdate() call, NOT the init() call, the grabPixels() call hangs indefinitely too!!
Any feedback, please,
Jonathan Pendrous
import java.applet.*;
import java.net.*;
import jmpendrous.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class XplaneGlobalSceneryDownloader extends Applet implements ActionListener{
ImageSegmentSelector worldMap;
Image img;
URL url;
int longtitude = 36;
int latitude = 18;
boolean imageLoaded;
TextField t1, t2,t3;
Label l1,l2,l3;
Button b1;
Applet a1;
public void init() {
a1 = this;
l1 = (Label) add(new Label("Number of horizontal sections: "));
t1 = (TextField) add(new TextField("45",3));
l2 = (Label) add(new Label("Number of vertical sections: "));
t2 = (TextField) add(new TextField("45",3));
l3 = (Label) add(new Label("URL of image file: "));
t3 = (TextField) add(new TextField("file:///C:/java/work/xplane_project/source/world-landuse.GIF",60));
b1 = (Button) add(new Button("Load image"));
b1.addActionListener(this);
validate();
// THIS CODE WORKS FINE ...
/*try { url = new URL("file:///C:/java/work/xplane_project/source/world-landuse.GIF"); }
catch(MalformedURLException e) { System.exit(0);   }
img = getImage(url);
//int w=img.getWidth(this);
while(imageLoaded==false) { try { Thread.sleep(1000);   } catch(InterruptedException e) {System.exit(0);    } }
worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
add(worldMap);
//resize(worldMap.getWidth(), worldMap.getHeight());
validate();*/
//repaint();
//worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
//repaint();
public void actionPerformed(ActionEvent e) {
try { longtitude = Integer.parseInt(t1.getText()); } catch (NumberFormatException ex) {System.exit(0); }
try { latitude = Integer.parseInt(t2.getText()); } catch (NumberFormatException e2) {System.exit(0); }
try { url = new URL(t3.getText()); }
catch(MalformedURLException e3) { System.exit(0);   }
img = getImage(url);
//int w=img.getWidth(this);
while(imageLoaded==false)
{ try { Thread.sleep(1000);   } //KEEPS ON LOOPING
catch(InterruptedException e4) {System.exit(0);    } }
worldMap = new ImageSegmentSelector(a1, img, longtitude, latitude);
add(worldMap);
//resize(worldMap.getWidth(), worldMap.getHeight());
validate();
public boolean imageUpdate(Image i, int flags, int x, int y, int w, int h){
// THIS NEVER GETS CALLED AT ALL //
if (((flags & ImageObserver.WIDTH) != 0) && ((flags & ImageObserver.HEIGHT) != 0)) {
//worldMap = new ImageSegmentSelector(this, i, longtitude, latitude);
//add(worldMap);
//validate();
//repaint();
imageLoaded = true;
return false;
return true;
}

Sorry, thought this had been lost.
You can load a file if the applet itself is run from the local filesystem - it loads it fine from the init(), but not otherwise. But I haven't got the applet to run from a browser yet without crashing (it's OK in the IDE debugger), so that's the next step.

Similar Messages

  • Loading images into memory

    I have an applet that I need to load images into memory. For instance, lets say I am in the first section of the applet. While that section is being showed, I want to load the background image of the second section into memory.
    To load the initial image into momory, I am just using a Mediatracker. No problem there. But I don't want to load all 20 backgrounds into memory at the same time as they take a lot of time. My understanding is that if I create a new MediaTracker while the first chapter is running, it will potentially cause some chaos, as that will stop my thread from running while I have an image loading.
    Somebody told me perhaps I could create a new thread and have that thread load the backgroudn into momory? Perhaps something like this?
    public class TestClass extends JApplet {
         private TestClass thisClass;
         public void init() {
              thisClass = this;
              Runnable r = new Runnable() {
                   public void run() {
                        MediaTracker tracker = new MediaTracker(thisClass);
                        Image nextImage = getImage( getDocumentBase(), getImagePath() +"img1.jpg");
                        tracker.addImage(nextImage,0);
                        try {
                             tracker.waitForID(0);
                        } catch (InterruptedException ie) {
                             System.out.println(ie.toString());
              Thread t = new Thread(r);
              t.setDaemon(false);
              t.start();
              while(t.isAlive()) {
                   int i = 1;     
              t.stop();
              t.destroy();
    }No idea if I am on the right track or not? Another friend told me something about swing helpers but couldn't tell me much more?
    Thanks in advance!

    I use media tracker when I need information about how percent the image is loaded. you can use JLabel to load the images since it has own image observer in it.
    hope you just want to deal with it. easiest way I can offer :)

  • Photoshop CC 2014 - Stack Mode Disabled - Load Image Into Stack Has No "Convert To Smart Object" Option

    Hi,
    I have just installed Photoshop CC 2014.1 and I have "Stack Mode" command disabled.
    Also, I have no option to convert layers into smart object  when I run "Load Image Into Stack" command.
    Can you please tell me how to enable these features?
    Thank you very much.
    Luca

    The 512 MB are a minimum requirement, not some optional thing. Without it, 3D will never work.
    Mylenium

  • Load image into Photo Album

    I'm new to Oracle.
    Can I load image into database by using Photo Album by no writing any code?
    And how?
    If not,how to load image into database?

    Yes you can. You can load media into the database into the photo album tables.
    Is this what you want to do? What exactly are you trying to accomplish.
    You can also use PL/SQL to put images into the database into your own schema (as with other database information)
    http://www.oracle.com/technology/sample_code/products/intermedia/htdocs/bulkload.html
    Larry

  • How to load image into picturebox

    Hi! Does anyone know how to load image into picturebox by using J2ME? And how to crete the picturebox in the forst place?
    Thanks!
    Regards,
    Jaceline

    You want java.awt.Toolkit.getImage() and java.awt.Graphics.drawImage().
    Ted.

  • Load image into holderMC

    Hi,
    I'm working on an application which places instances from my
    library onto the stage. Every instance has a movieclip inside it
    which is called holderMC. What I want to do is to load external
    images into holderMC except I can't seem to get it working. How
    does one load images into a pre-defined movieclip?

    Oh, sorry, wasn't looking properly. You cannot load images
    into MovieClips like in AS2, you have to use a Loader or the
    UILoader component.
    If you want to be able to position the loader visually, then
    you can give an instance of the UILoader component and instance
    name within the THEPhoto MC, and use the following code:
    MovieClip(photo).holder.load(photoRequest); //where holder is
    the instance name of the loader.
    OR
    Within the ThePhoto class you could create a new Loader:
    public var imgLoader:Loader = new Loader();
    public function ThePhoto () {
    imgLoader.x = 0;
    imgLoader.y = 0;
    addChild(imgLoader);
    and then use:
    MovieClip(photo).imgLoader.load(photoRequest);

  • How to dynamically load images into Flash

    I have a movie clip on the stage that I want to dynamically
    load images into (that constantly change), how would I go about
    doing this? Thanks.

    Use the Loader class to load in images.
    Then use addChild to add the Loader class into your MovieClip
    on the stage.
    As far as "constantly change" what
    do you mean by that? You could use setInterval, ther enterFrame
    event, or any other means to trigger a new image to be loaded into
    the Loader instance.
    Finally, you can use the Tween class to create some nice
    effects for the images (fade it, blur in, photo blend, masks,
    etc)

  • Problem loading image into texture memory

    Hi there, I am currently porting our new casual PC game over to the iPad using the pfi, the game was written in Flash so the porting process isn't that hard thankfully, it's mainly just optimizing the graphics.
    So far things are going smoothly, I was initially worried about graphical performance, but since we put everything into the GPU that's no longer a concern- it runs super smooth at 60fps at 1024x768, we can have a hundred large bitmaps rotating and alphaing at once with no slowdown.
    However there is one weird problem which is really worrying me at this point- it seems that the speed at which images are loaded into video memory as textures is vastly different depending on what else is being run on the iPad, for example:
    * If I run my game with nothing else in memory, it will run fine at 60fps, and load up large images into texture memory very fast.
    * If I run another App, in this case a Virtual piano app for a while, then close that App via the Home button (so the piano app is still in memory but suspended due to the multitasking), then when I run my game, it will run ok initially, but when I try to load a large (1024x512) image into texture memory it pauses the whole game for several seconds.
    * To make matters worse, if I repeat the same test using the RAGE app from ID software (which is very graphically intense), my game actually slows down to 1 fps and runs extremely slowly as soon as I run it and the frame rate never returns to normal. If I then double-click the home button, shut down RAGE, then go back to my game, it will run fine.
    I have read that sometimes when you load images into texture memory it will have to reclaim that memory from other apps, but that doesnt exaplain why it slows down every time I want to load something, or why the game would slow right down to a crawl.
    So then it seems that having other Apps in memory is slowing down my game, or stopping it from working altogether. Obviously this is not ideal and would stop us from releasing, so is there any way I can stop this, has anyone come across the problem? Please help!
    PS. this problem also happens on an iPhone 4, as I have performed the same tests.

    Hi _mz84
    First thing I noticed, is that you did not close your
    <embed> tag
    <embed src="gallery1.swf" bgcolor="#421628" width="385"
    height="611" wmode="transparent" />
    If that doesn't solve your troubles, try the following
    container.
    <object type="application/x-shockwave-flash" height="611"
    width="385" align="middle" data="gallery1.swf">
    <param name="allowScriptAccess" value="never" />
    <param name="allowNetworking" value="internal" />
    <param name="movie" value="gallery1.swf" />
    <param name="quality" value="high" />
    <param name="scale" value="noscale" />
    <param name="wmode" value="transparent" />
    <param name="bgcolor" value="#421628" />
    </object>
    hope this helps out.

  • Making a loaded swf-file loading images into the movie..

    Trying to convert my problem from norwegian into english
    isn't always that easy... :)
    Anyway..
    I've created som cool buttons that I want to be loaded into a
    movie (let's call i MainMovie.swf) and from there I want the
    buttons to be able to load images into a movieclip (ImageContainer)
    inside the MainMovie.swf.
    Is it possible to make the MainMovie.swf communicate with the
    the loaded buttons (each button is a swf-file containing the
    actionscript, objects, etc.) so when the buttons are clicked they
    load different images into the ImageContainer?
    My idea here is to include an as.file into the MainMovie.swf
    as well containing the url's to the images that I want to be loaded
    into ImageContainer.
    I've tried to create a button on a layer above the buttons
    that's loaded into the MainMovie.swf but I end up with the loaded
    buttons not working properlu because of the button that I've
    created and placed above them.
    Now, I don't want the url's inside the buttons thats loaded
    into the MainMovie.swf as I want the ability to be able to replace
    those buttons-files without having to use too much time writing the
    url's in each button.
    Thanks folks.

    are all your swfs using as3 or as2? if as3, you won't be
    loading into a movieclip: you'll use a loader instance and you can
    reference (or communictae with) the loaded as3 objects using the
    content property of your loader once you cast it as a
    movieclip.

  • Loading Images into LONG RAW column using SQL or PL/SQL

    Hi!
    I am trying to load images into a LONG RAW column. Can anybody tell me how to do this using SQL or PL/SQL. I do not want to use Forms to do this. And, I have a limitation using BLOBs.
    Thanks in Advance,
    Kotesh.

    You wrote that you cannot use a java class to insert a picture. We are working on a school project and HAVE to use java as a client and Oracle 7 as a server.
    Can you tell us how this is to be done?
    Thank you in advance,
    Bart van der Heijden

  • Best place to load Images in applet game

    Sorry for the double post but I just realised I originally posted this in completely the wrong forum!
    Hello,
    I have made a fairly basic game of 21/BlackJack and was wondering where the best place to load the card Images is/was...
    Currently I am loading the images into an Image[ ] in the applet class, but was thinking maybe the loading should be done in the deck or card class?
    In the applet class I use an ordered version of the deck to assign the cards in the image[ ], then to call an image I generate an index number based on the current cards value and suit....
    However this method means I have to create an instance of the deck in the main program, whereas before I had it as a private member of the dealer class, so only the dealer could access it (which seems "safer", no?)
    So would a better idea be to have a loadImage() method in the deck class, which populates an Image[ ] with the cards and pass this to the main program?
    Thanks

    Ken,
    Loading images is slow so you only want to do it once... maybe when you generate the deck ... and "image" is definately an attribute of the card, yes... I'd actually implement the loadImage() as a method in the card class so set a private image variable... and then get the the dealer to call the loadImage method for each card as "he" builds the deck.
    But that's just how I would do it... and I'm no guru so don't take it as gospel... I'd be surprised if there wasn't atleast one "purer" way of doing it.

  • Loading Images in Applets

    Is it possible to use the Toolkit class to load images in "unsigned" applets. I tried that but it throws a security exception:
    com.ms.security.SecurityExceptionEx[MyApplet.init]: cannot access file http://localhost/MyApplet/images/Image1.gif
    Though I am reading the image from the server not the client machine.
    Any help would be appreciated.
    Thanks in advance,
    Samer Meqdad

    Here's the code:
    Image img;
    img = Toolkit.getDefaultToolkit ().getImage (getCodeBase() +  "images/MyImage.gif");The exception thrown is:
    com.ms.security.SecurityExceptionEx[Host]: java.io.IOException: bad path: C:\Documents and Settings\samerm\Desktop\file:\C:\MyApplet\images\MyImage.gif
         at com/ms/security/permissions/FileIOPermission.check (FileIOPermission.java)
         at com/ms/security/PolicyEngine.deepCheck (PolicyEngine.java)
         at com/ms/security/PolicyEngine.checkPermission (PolicyEngine.java)
         at com/ms/security/StandardSecurityManager.chk (StandardSecurityManager.java)
         at com/ms/security/StandardSecurityManager.checkRead (StandardSecurityManager.java)
         at com/ms/awt/WToolkit.getImageFromHash (WToolkit.java)
         at com/ms/awt/WToolkit.getImage (WToolkit.java)
         at DiamondsApplet.init (DiamondsApplet.java:54)
         at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
         at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.run (AppletPanel.java)
         at java/lang/Thread.run (Thread.java)

  • Loading Images into BLOB.

    I have written pl/sql code for mass load of images into blob. When user is trying to access it from front end. some of the images are corrupted. means blank page is displayed but for other the actual image is displayed. So is there any size limitation on blob images???mostly images i am storing is of 20kb - 300kb.
    Thanks in advance.

    There is a definite limit to the size of blobs you can store. That limit is (4GB-1 byte)*(block size) which means between 8 and 128TB.
    I highly doubt your issue is storing the BLOBs in the Oracle database though since you thought it unimportant to post version information, DDL, or DML no one can possibly tell for sure.
    I would be far more suspicious of whatever tool, also unmentioned, being used to retrieve and display them.

  • Loading images into user_sdo_styles?

    We would like to automate the complete process of loadiing our themes and styles in our installation.
    Currently we use SQL scripts similar to defaultstyles.sql in the demo application.
    insert into user_sdo_styles (name, type, description, definition) values (
    'M.DEVICE_INTERFACE', 'MARKER',
    'Device Interface (Triangle, red wih black border)',
    '<?xml version="1.0" standalone="yes"?>
    <svg width="1in" height="1in">
    <desc></desc>
    <g class="marker" style="stroke:#000000;fill:#FF0000;width:15;height:15;font-family:Dialog;font-size:12;font-fill:#6666FF">
    <polyline points="201.0,200.0,0.0,200.0,101.0,0.0"/>
    </g>
    </svg>');
    Is there a way I can modify the insert statement to also load the image (gif image marker type) column so our users don't have to use the mapbuilder application for this install step?

    Hi,
    you can try the following:
    1) In SQlPlus with system user create a directory where your files will be, and grant read access to a user.
    CREATE DIRECTORY images AS '/tmp';
    GRANT READ ON DIRECTORY images TO mvdemo;
    2) Now connect to MVDEMO user
    connect mvdemo/mvdemo;
    and execute the following script (change the file name for your case).
    DECLARE
      file_lob   BFILE;
      binary_lob BLOB;
    BEGIN
      insert into user_sdo_styles (name, type, description, definition,image) values (
         'M.EARTH', 'MARKER',
         'Image marker',
         '<?xml version="1.0" standalone="yes"?>
          <svg width="1in" height="1in">
           <desc/>
            <g class="marker" style="width:15;height:16;font-family:Dialog;font-size:12;font-fill:#FFFFFF">
            <image x="0" y="0" width="1" height="1" markerType="gif" href="dummy.gif"/>
          </g>
         </svg>',
         empty_blob()) returning image into binary_lob;
      -- Open up the file in the IMAGES directory named file_name,
      -- load that file into the newly created LOB locator, and
      -- close the file
      file_lob  := BFILENAME( 'IMAGES', 'earth16.gif' );
      dbms_lob.fileOpen    ( file_lob, dbms_lob.file_readOnly );
      dbms_lob.loadFromFile( binary_lob,
                             file_lob,
                             dbms_lob.getLength( file_lob ) );
      dbms_lob.fileClose   ( file_lob );
      commit;
    END;
    /If the script is executed without errors, you can check in MapBuilder your style.
    Joao

  • Muse CC crashes loading images into a slideshow

    Hi,
    I am having a problem with Muse crashing. I am starting with an empty page in an otherwise empty site, I insert slideshow, then click load images in the slideshow settings window. I have gotten this to work with very small numbers of files, but never with more than about 24. Usually I get this error dialog almost right after I browse to and select the group of images to load:
    Each image is approximately 350K. I am running Windows 7 Professional 64-bit with 8GB RAM. Does anyone know what my problem might be?
    Thanks in advance!

    I'm not sure what you mean by "optimize those images," would you mind explaining a little bit? I'm new to this.
    I could import a few at a time, but I have a gallery of thousands of images and I'd rather not go that route, if
    I can help it.
    Thanks for your tips, hoping I can find a good solution.

Maybe you are looking for

  • Restrictions password

    I set a password for my restrictions a long while ago and I do not know it any more some people are saying connect to iclou but I have no computer source right now.. How can I figure it. Out? I need to figure it put my sound isn't working no music no

  • Materialized view excessive logging.  SOS

    The refresh of our materialized view is causing excessive logging. I altered the materialized view to NOLOGGING but it did not have any effect, not sure why? We either need to change the refresh time from 3 minutes to every 15 minutes(which is a bumm

  • Need advise from OA Framework experts

    I am working as Oracle Apps. developer for over 9 years. I want build forms (screens for 11i) for Applications using OA Framework. Could you pl. advise me of the pre-requisites for learing OA Framework... like: Which concepts do I concentrate when le

  • Application icons not showing in console

    Does anyone see application icons in the Configuration Manager console? There's an "Icons" column as if this is an intended feature, but it always shows the generic application icon. This is really annoying as I can't check applications icons unless

  • Necessary Matlab compiler options to integrate generated dll in VI

    What Matlab compiler (mcc) options are required for Labview to be able to import the generated dll? Using typical options, there are symbol definition problems with the header file.