Solved

HOWTO make an Applet that show an Image in Netscape

Posted on 2001-06-18
7
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Accepted Solution

by:
tonus earned 50 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate jars 4 61
null output 3 43
ejb example issues 3 56
Java Eclipse Loop 3 31
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 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