A2: If there is an error in the Java language applet, it would be
displayed in the Java language area. The ALT message is to tell browsers
that are not Java language enabled that there is an applet on this page
and they can't read it. I would suggest putting all of your methods in
a try{ }...catch(Exception){ }...finally{ } setup. For instance:
public void init()
{
try{
//Do necessary stuff
}
catch(Exception e)
{
System.out.println("ERROR IN INIT()! " + e);//This is visible in
your browser's Java language
//console
//Do any other necessary stuff
}
finally
{
this.getGraphics().drawString(/*Your alt msg*/, x, y);
}
}
Do this for all of your methods, and if I am correct, it should work. I hope this helps you. Good luck!
Many thanks to JDC member tnazeinnoR for contributing to this answer.
Feedback from other JDC members
Mon Apr 19 15:53:14 PDT 1999
ionFreeman
Dave,
What does that finally block do? You seem to be suggesting writing the same text as lies in your ALT attribute to the java applet, even though it's running and even if it succeeds.
Is this right?
Tue Apr 20 02:08:30 PDT 1999
operdeck
Drawing in the init method? Will this have any effect? Shouldn't it be in a paint() method?
Tue Apr 20 04:26:35 PDT 1999
ajayiyer
will the finally statement not be executed each time you execute the init statement and hence an drawstring will be drawn each time inspite of error or not
Tue Apr 20 09:29:18 PDT 1999
kriff
I would use the applet's constructor to examine
the system properties "java.version", "java.vendor"
and "java.class.version". Together these properties
should be able to tell you if the browser's VM
is the correct version.
If your applet requires the Java 2 platform, check
that the "java.class.version" is 46.0 or higher.
If you require JDK 1.1 classes, you'll have to interpret
the "java.version" property. The format of this
property isn't very well defined so you'll have to
write code that is somewhat flexible. In general,
the format will be "a.b[.c]" where a, b and c are
integers (note that the maintenance release version
isn't always present, and it may be followed by
the letters "A" or "B"). If you know of any incompatibilities
with a given vendor's JVM then you should check the
"java.vendor" string.
If you detect an error, there are a couple of things
you can do. First print out a diagnostic message
to System.out that contains as much info as you
can get about the problem. Then either throw an
exception to stop loading the applet, or set some
internal flag to indicate that an error has occurred.
If the error flag is set, the applet should paint
an error message in its display area and ignore any
user input.
Wed Apr 21 01:00:42 PDT 1999
RaffiHerzog
I once had the same problem, additionally I had to display a message "Loading, please wait during initialized". I managed it using two flags: isInitialized and errorOccurred. The initialization happened in the start() method, because you cannot paint in init(), but only if isInitialized is set to false. The paint() rouztine now paints an error message if errorOccurred is true, the Applet content if isInitialized is true and a "please wait"-message if both are set to false. Like that you have a feedback for the user almost immediately after the applet has been (maybe just partially) loaded.
Wed Apr 21 02:22:40 PDT 1999
anandcp
The System.out.println is a good idea, but not many browsers have the Java console enabled by default. And most of the users don't know they need to look in the Java console for messages.
Better option is getGraphics.drawString(...) which would help. or better still a add(new Label("Some problem")) would enable more clearer response.
Wed Apr 21 05:48:01 PDT 1999
denisel
Is there any resource out there that can hook you up with other developers using the same development platform so that we can discuss how things are done in platform-specific ways? I am using VisualAge for Java 1.0.1.
Thu Apr 22 01:25:07 PDT 1999
nanite
This is great to know, especialy if you are using 1.2 to develop apps.
Thu Apr 22 08:31:48 PDT 1999
Anonymous
Thw solution doesn't work with the following example:
import java.applet.Applet;
import java.awt.event.*;
public class MyApplet extends Applet implements ActionListener
public void actionPerformed(ActionEvent e) { }
}
I've got the same problem, but I wasn't able to fix it. The browser always complains "ClassNotFoundException: ActionEvent" (Netscape) or SecurityException (Explorer).
(ActionEvent is a 1.1+ class). I think there's nothing you can do *with the source code*, because the browsers check the code before running it.
Thu Apr 22 20:25:53 PDT 1999
ctallam
if it is jdk1.2 security policies have to be declared using policy tool. Want to know how!! mail me on ctallam@hotmail.com
Fri Apr 23 06:24:18 PDT 1999
jsweyrich
The Java INetAddress class is non-instantiable. It assumes a host is referenced by name. I'm guessing something like a domain name? Can I use the socket class to establish a connection with a host via the Internet if I have the host's IP address and socket, but no host name? Can I treat the IP address as a name? This is rather urgent. TIA.
Fri Apr 23 15:46:49 PDT 1999
Anonymous
How Can I implement a Java Applet, that sends data to a CGI program with POST method and return a HTML page to the Browser?
THE INFORMATION PROVIDED IN THE JAVA DEVELOPER'S CONNECTION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR, AND NON-INFRINGEMENT.
THIS INFORMATION IS PROVIDED AT NO CHARGE. BY USE OF THE INFORMATION YOU AGREE THAT NEITHER SUN MICROSYSTEMS, INC. NOR ITS LICENSORS WILL BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF SUN OR ITS LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING
LIMITATION MAY NOT APPLY.
THIS INFORMATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN. SUN MICROSYSTEMS, INC.
MAY MAKE IMPROVEMENTS AND OTHER CHANGES IN THE PRODUCTS AND THE PROGRAMS DESCRIBED HEREIN AT ANY TIME WITHOUT NOTICE.