Loading Image in An Applet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • final farewell
    New Member
    • Jul 2007
    • 3

    #1

    Loading Image in An Applet

    Hello

    I am trying to do a simple java applet which loads image from a specified url.

    Here is the code I have now, but it cant seem to work.

    Code:
    import java.applet.*;
    import java.awt.*;
    
    public class ATestofLoadImage extends Applet {
    
    	Image image;
        public void init() {
            // Load image
            image = getImage(getDocumentBase(), "http://127.0.0.1:8550/epe/map/render?name=Tag%201");
        }
        public void paint(Graphics g) {
            // Draw image
            g.drawImage(image, 0, 0, this);
        }
    }
    When i compiled the program, there was no errors, but the applet doesnt load the image. The URL specified is correct; it can be loaded in the web browser.
    What might be the problem?

    Thank you for your help.
  • praveen2gupta
    New Member
    • May 2007
    • 200

    #2
    Originally posted by final farewell
    Hello

    I am trying to do a simple java applet which loads image from a specified url.

    Here is the code I have now, but it cant seem to work.

    Code:
    import java.applet.*;
    import java.awt.*;
    
    public class ATestofLoadImage extends Applet {
    
    	Image image;
        public void init() {
            // Load image
            image = getImage(getDocumentBase(), "http://127.0.0.1:8550/epe/map/render?name=Tag%201");
        }
        public void paint(Graphics g) {
            // Draw image
            g.drawImage(image, 0, 0, this);
        }
    }
    When i compiled the program, there was no errors, but the applet doesnt load the image. The URL specified is correct; it can be loaded in the web browser.
    What might be the problem?

    Thank you for your help.
    Hi
    There are two problems
    1. use applet tag before the class name
    ex.
    Code:
     /*
     <applet code="ATestofLoadImage" height="500" width="500">
     </applet>
     */
    2. Test your URL in the browser first then apply in the code. It seems that Your url is not working. http://127.0.0.1:8550/epe/map/render?name=Tag %201

    if you are getting the image in the browser then will will also be getting it in the applet.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by final farewell
      Hello

      I am trying to do a simple java applet which loads image from a specified url.

      Here is the code I have now, but it cant seem to work.

      Code:
      import java.applet.*;
      import java.awt.*;
      
      public class ATestofLoadImage extends Applet {
      
      	Image image;
          public void init() {
              // Load image
              image = getImage(getDocumentBase(), "http://127.0.0.1:8550/epe/map/render?name=Tag%201");
          }
          public void paint(Graphics g) {
              // Draw image
              g.drawImage(image, 0, 0, this);
          }
      }
      When i compiled the program, there was no errors, but the applet doesnt load the image. The URL specified is correct; it can be loaded in the web browser.
      What might be the problem?

      Thank you for your help.
      Only the first argument is supposed to represent a URL; the second parameter
      is just the name of the image. You could just use the second parameter only.
      Read the API documents for the Applet class to see the exact meaning of both
      parameters.

      kind regards,

      Jos

      Comment

      Working...