Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HOWTO make an Applet that show an Image in Netscape

Posted on 2001-06-18
7
Medium Priority
?
174 Views
Last Modified: 2013-11-23
Hello!
My source:
import java.applet.*;
import java.awt.*;
public class A extends Applet {
     Image img;
     public void init() {
          img = getImage(getCodeBase(), "img.gif");
     }    
     public void paint(Graphics g) {
          g.drawImage(img, 0, 0, this);
     }
}
I compile: javac A.java to produce A.class, then I type:
jar -cvf A.jar A.class img.gif
to produce A.jar
After I make this html file:
<html><body>
Keypad<applet code="A.class" archive="A.jar" width="200" height="300">
</applet></body></html>

public on PWS an run Netscape on htis page.
It doesn't work. Why?
If I don't use jar and take off archive"A.jar" It works well.
I can't undertand.
OBS: With IE it works well to.
My Netscape vertions: 4.03, ..., 4.73

thanks a lot!
0
Comment
Question by:jussara
6 Comments
 
LVL 2

Expert Comment

by:iDeb
ID: 6204255
you might want to specify the full path to the archive, or include the codebase attribute
0
 
LVL 2

Expert Comment

by:iDeb
ID: 6204265
I also suggest use the OBJECT tag instead of APPLET, since the latter has been deprecated in favor of the former.... http://www.webspawner.com/cc/html/object.html
0
 
LVL 2

Expert Comment

by:iDeb
ID: 6204266
I also suggest use the OBJECT tag instead of APPLET, since the latter has been deprecated in favor of the former.... http://www.webspawner.com/cc/html/object.html
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Accepted Solution

by:
tonus earned 200 total points
ID: 6206490
To Load an image from a jar file, you got use
 getResource() or getResourceAsStream()

Added below a sample code which returns an image from the jar file

 public Image getImageFromJAR(String s) {
    InputStream inputstream = getClass().getResourceAsStream(s);
    if(inputstream == null) {
      return null;
    }
    ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
    byte abyte0[] = new byte[1024];
    try {
      int i;
      do {
        i = inputstream.read(abyte0);
        if(i != -1)
        bytearrayoutputstream.write(abyte0, 0, i);
      } while(i != -1);
      inputstream.close();
    }catch(IOException _ex) {
      try {
        inputstream.close();
      } catch(IOException _ex2) { }
      return null;
    }
    return Toolkit.getDefaultToolkit().createImage(bytearrayoutputstream.toByteArray());
  }
0
 

Author Comment

by:jussara
ID: 6328755
From wich version of netscape the tonus sample works?
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9010003
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to tonus]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question