Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Running Swing applets in IE or Navigator

Posted on 1998-07-06
7
Medium Priority
?
239 Views
Last Modified: 2013-12-29
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
0
Comment
Question by:dirku
[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
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 80 total points
ID: 1224756
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
 

Author Comment

by:dirku
ID: 1224757
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
 

Author Comment

by:dirku
ID: 1224758
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:dirku
ID: 1224759
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
 
LVL 5

Expert Comment

by:msmolyak
ID: 1224760
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
 

Author Comment

by:dirku
ID: 1224761
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
 
LVL 5

Expert Comment

by:msmolyak
ID: 1224762
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

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