Solved

HOWTO make an Applet that show an Image in Netscape

Posted on 2001-06-18
7
163 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
7 Comments
 
LVL 2

Expert Comment

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

Expert Comment

by:iDeb
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Accepted Solution

by:
tonus earned 50 total points
Comment Utility
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
Comment Utility
From wich version of netscape the tonus sample works?
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now