[Advanced-java] Applets: workaround for missing classes in MSIE?
Mark Gorokhov
mark.gorokhov at comtechmobile.com
Mon Apr 24 06:19:12 PDT 2006
The class Graphics2D is not supported by old MS JVM 1.1.4. This means
that your code cannot contain explicit use of Graphics2D. The workaround
is to hide Graphics2D class from JVM classloader. Remove any explicit
use of Graphics2D. Use reflection. This will work nicely on any machine
with any JVM. You don't need even to check for MS or Sun JVM. Just call
Graphics2D functionality using reflection and ignore exceptions.
Exception means that Graphics2D is not supported.
Mark Gorokhov
-----Original Message-----
From: advanced-java-bounces at lists.XCF.Berkeley.EDU
[mailto:advanced-java-bounces at lists.XCF.Berkeley.EDU] On Behalf Of
Alexander Farber
Sent: Friday, April 21, 2006 6:00 AM
To: advanced-java at lists.xcf.berkeley.edu
Subject: [Advanced-java] Applets: workaround for missing classes in
MSIE?
Hello,
I have a small multiplayer card game applet ( http://preferans.de )
which I try to keep runnable both by the Sun's JVM and by the old MSIE
VM (msjavax86.exe).
There is however one little thing which I'd like to add to it w/o
breaking it for MSIE users: the antialiased fonts.
So I've created this small test case - Anti.java:
import java.awt.*;
import java.applet.*;
public class Anti extends Applet {
public void init() {
setFont(new Font("Serif", Font.ITALIC, 36));
}
void enableAntiAlias(Graphics g) {
((Graphics2D) g).setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
((Graphics2D) g).setRenderingHint(
RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
}
public void paint(Graphics g) {
/*
if
(System.getProperty("java.vendor").startsWith("Microsoft"))
System.err.println("MSIE detected");
else
enableAntiAlias(g);
*/
g.drawString("Hello World!", 10, getSize().height / 2);
}
}
And here is the html-file for your convenience:
<HTML>
<BODY>
<APPLET CODE="Anti" HEIGHT="100" WIDTH="300"> </APPLET> </BODY> </HTML>
If I comment the 4 lines in the paint() as listed above, then MSIE loads
and displays the applet w/o problems.
However once I remove the comments, I get this error:
Microsoft (R) VM for Java, 5.0 Release 5.0.0.3810
==============================================
java.lang.ClassNotFoundException: java.awt.Graphics2D
at com/ms/vm/loader/URLClassLoader.loadClass
at java/lang/ClassLoader.loadClassInternal
at Anti.paint
at com/ms/awt/WComponentPeer.doClearAndPaint
at com/ms/awt/WComponentPeer.paintNode
at com/ms/ui/windowmanager/PaintRequest.run
at com/ms/ui/windowmanager/RunnableMessage.run
at com/ms/awt/WSystemQueue.getMessage
at com/ms/awt/WEventQueue.getNextEvent
at java/awt/EventDispatchThread.run
I wonder if anyone have found a nice workaround for this probably very
frequent problem.
Please note, that I don't want to use JS or "Anti.cab"
or teach my users how to install the Sun's VM.
I just want them to play my little game with any browser.
Regards
Alex
_______________________________________________
Advanced-java mailing list
Advanced-java at lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/advanced-java
More information about the Advanced-java
mailing list