Running Swing applets in IE or Navigator

I have a problem running HTML pages containing the APPLET-tag which causes to run an applet using Swing.
My program works well in the AppletViewer but ti does not in Internet Explorer(4.0) nor in Netscape Navigator(4.05).
How can I solve this problem?

In the AUTOEXEC.BAT I have set the following environment variables:

SET JAVA_HOME=C:\JAVA\JDK1.1.6
SET SWING_HOME=%JAVA_HOME%\SWING-1.0.2
SET JDBCHOME=%JAVA_HOME%\LIB\classes.zip
SET CLASSPATH=.;%JAVA_HOME%\LIB\classes.zip;%SWING_HOME%\src.zip;%SWING_HOME%\swingall.jar
SET PATH=%PATH%;%JAVA_HOME%\BIN;C:\JAVA\IDE\KAWA30

...but how can a user run my JApplet in a browser? Must he set some environment variables, too?
I think that a user just wants to start the browser and then wants the applets run! ->Without setting any viariables!

I even copied the swingall.jar file to the C:\Windows\java\classes directory and to the java\classes directory of the Communicator:
Communicator shows: "error:java.lang.NoSuchMethodError: java.awt.Component: method enableEvents(J)V not found"

IE: NullPointerException

Thank you.

ulrich@tembit.com
dirkuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

msmolyakCommented:
With Netscape you probably need so called JDK 1.1 support. You can find and download it from http://developer.netscape.com/tech/java/index.html (follow link for "Download JDK 1.1 Support for Communicator")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dirkuAuthor Commented:
Any idea why it doesn't run in MS IE 4.0?

In Netscape Navigaotr I've got it run but now I have a further question. I want to do the following:
I load some data from a database into the JApplet. This works well. Then I want to update the entries of the JTable used within this JApplet. Therefore I want to read out a file from another host. I create a URL using: URL url = new URL(getDocumentBase(), "data/myFile.txt");
BufferedReader br = new BufferedReader(new FileReader(url));
try
{...}

Now I have an AppletSecurityException which says that reading of this file is not permitted.
How can I get permission to read out this file?

0
dirkuAuthor Commented:
Running a simple test program (you can see the text below) it results in an AppletSecurityException when running Windos95. Running the program under Windows NT there are no problems.
Why? What can I do to make it run on both OS?

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;

public class Test extends JApplet implements ActionListener
{
      private JButton start = new JButton("Start");
      private JComboBox symbols = new JComboBox();
      
      public void init()
      {
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(BorderLayout.CENTER, symbols);
            getContentPane().add(BorderLayout.SOUTH, start);
            start.addActionListener(this);
      }
      
      public void start()
      {
            setVisible(true);
      }
      
      public void destroy()
      {
      }
      
      public void loadSymbols()
      {
            URL url = null;
            try
            {
                  url = new URL(getCodeBase(), "tcx_data/day/ABB.day");
            System.out.println(url);
                  InputStream is = url.openStream();
                  InputStreamReader isr = new InputStreamReader(is);
                  BufferedReader br = new BufferedReader(isr);

                  String line = "";
                  while ( (line = br.readLine()) != null)
                  {
                        System.out.println(line);
                        symbols.addItem(line);
                  }// end while

            }
            catch(MalformedURLException MURLe)
            {
                  System.err.println("URL nicht korrekt!");
                  System.err.println(MURLe);
            }
            catch(IOException IOe)
            {
                  System.err.println("Konnte Datei nicht lesen!");
                  System.err.println(IOe);
            }
      }//end loadSymbols
      
      public void actionPerformed(ActionEvent Ae)
      {
            System.out.println(Ae.toString());
            if( Ae.getSource().equals(start) )
            {
                  System.out.println("Start gedrückt...");
                  loadSymbols();
            }
      }
}//end class Test
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

dirkuAuthor Commented:
This happens when using Netscape Navigator 4.05, using MS IE 4.0 the program runs although there are numerous exceptions appearing in the Java console.

How can I make my programs run with both Netscape Navigator/Communicator and MS Internet Explorer considering Windows NT AND Windows 95 (of course, all other platforms, too)?
0
msmolyakCommented:
The applet looks reasonable. Could you turn the debugging on in the Java console and send me the output which gets produced when you run the applet. Make sure you clear browser's cache before running the applet and turn the debug mode on on the console.
0
dirkuAuthor Commented:
Hi, tought you have given it up to teach me :-))

Now I have installed the Personal Web Server and the test program runs well with it. However, I want to know what was wrong. I think if all the files are on my PC the program should have run, too, shouldn't it?

After starting the Navigator the program with the source above was the only I have run:

Netscape Communications Corporation -- Java 1.1.5
Type '?' for options.
Symantec Java! ByteCode Compiler Version 210.065
Copyright (C) 1996-97 Symantec Corporation
# Applet debug level set to 9
# initApplet: contextID=2 appletID=13737648 parentContext=12310688 frameContext=12310688
# New applet context: file:///C|/Java/IDE/Kawa30/Projects/Test/Default.html, contextID=2
# Initializing applet: Test.class, appletID=13737648, contextID=2
#   docURL=file:///C|/Java/IDE/Kawa30/Projects/Test/Default.html reloadClasses=false
#     total applets=1
#     New applet: 13737648 at file:/C|/Java/IDE/Kawa30/Projects/Test/ width=300 height=300 hspace=0 vspace=0 align=baseline codebase=file:///C|/Java/IDE/Kawa30/Projects/Test/ code=Test.class
# startApplet: contextID=2 appletID=13737648 newFrameMWContext=12310688
# Starting applet: Test, appletID=13737648, contextID=2
#   new class loader netscape.applet.AppletClassLoader@800e4c6
#      context = netscape.applet.MozillaAppletContext@800c659
#      codebase = file:/C|/Java/IDE/Kawa30/Projects/Test/
Swing: checked access to system event queue.
# Applet Test loaded
# Applet Test initialized
# Applet Test running
java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Start] on com.sun.java.swing.JButton[,0,275,300x25,layout=com.sun.java.swing.OverlayLayout]
Start gedrückt...
file:/C|/Java/IDE/Kawa30/Projects/Test/tcx_data/day/ABB.day
netscape.security.AppletSecurityException: security.class from local disk trying to access url: file:/C|/Java/IDE/Kawa30/Projects/Test/tcx_data/day/ABB.day
  at java.lang.Throwable.<init>(Compiled Code)
  at java.lang.Exception.<init>(Compiled Code)
  at java.lang.RuntimeException.<init>(Compiled Code)
  at java.lang.SecurityException.<init>(Compiled Code)
  at netscape.security.AppletSecurityException.<init>(Compiled Code)
  at netscape.security.AppletSecurityException.<init>(Compiled Code)
  at netscape.security.AppletSecurity.checkURLConnect(Compiled Code)
  at java.lang.SecurityManager.checkURLConnect(Compiled Code)
  at netscape.net.URLConnection.connect(Compiled Code)
  at netscape.net.URLConnection.getInputStream(Compiled Code)
  at java.net.URL.openStream(Compiled Code)
  at Test.loadSymbols(Compiled Code)
  at Test.actionPerformed(Compiled Code)
  at com.sun.java.swing.AbstractButton.fireActionPerformed(Compiled Code)
  at com.sun.java.swing.AbstractButton$ForwardActionEvents.actionPerformed(Compiled Code)
  at com.sun.java.swing.DefaultButtonModel.fireActionPerformed(Compiled Code)
  at com.sun.java.swing.DefaultButtonModel.setPressed(Compiled Code)
  at com.sun.java.swing.plaf.basic.BasicButtonListener.mouseReleased(Compiled Code)
  at java.awt.Component.processMouseEvent(Compiled Code)
  at java.awt.Component.processEvent(Compiled Code)
  at java.awt.Container.processEvent(Compiled Code)
  at java.awt.Component.dispatchEventImpl(Compiled Code)
  at java.awt.Container.dispatchEventImpl(Compiled Code)
  at java.awt.Component.dispatchEvent(Compiled Code)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Compiled Code)
  at java.awt.LightweightDispatcher.processMouseEvent(Compiled Code)
  at java.awt.LightweightDispatcher.dispatchEvent(Compiled Code)
  at java.awt.Container.dispatchEventImpl(Compiled Code)
* at java.awt.Component.dispatchEvent(Compiled Code)
  at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
  at java.awt.EventDispatchThread.run(Compiled Code)
  at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)

Besides: What's the exactly distinction between getDocumentBase() and getCodeBase()???
0
msmolyakCommented:
The message:
# New applet context: file:///C|/Java/IDE/Kawa30/Projects/Test/Default.html
Means that you are using file: protocol to load the applet. In this case the browser will not allow you to read files. You have to use http: protocol to load your applet (from your web server). Then the codebase will also have http: as its protocol an you should be  able to read the file.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.