admin管理员组文章数量:1122832
I know applets are no longer formally supported. I have some legacy code that can still run using IE 11/Edge in compatibility mode. I can also run applets in any browser using Webswing.
My applets use netscape.javascript.JSObject to perform live connect to the page's JavaScript.
I can compile with Java 11, but in Java 17, method netscape.javascript.JSObject.getWindow() has been removed. If I try to compile an applet that uses netscape.javascript.JSObject.getWindow() with Java 17, I get a compilation error. Here's a sample applet and the compilation error I get:
Sample applet:
package your.package.name;
import javax.swing.JApplet;
public class SimpleApplet extends JApplet {
private static final long serialVersionUID = 1L;
public void init() {
System.out.println("SimpleApplet.init()");
netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow(this);
}
public void start() {
System.out.println("SimpleApplet.start()");
}
public void destroy() {
System.out.println("SimpleApplet.destroy()");
}
}
Compiling with command: "C:\Program Files\Java\jdk-17\bin\javac.exe" "C:\Users\userId\your\package\name\SimpleApplet.java"
Yields this output:
SimpleApplet.java:5: warning: [removal] JApplet in javax.swing has been deprecated and marked for removal
public class SimpleApplet extends JApplet {
^
SimpleApplet.java:10: error: cannot find symbol
netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow(this);
^
symbol: method getWindow(SimpleApplet)
location: class JSObject
1 error
1 warning
I know the netscape.javascript.JSObject.getWindow() method has been removed, so I figured I'd add jaws.jar to the classpath (note that jaws.jar is basically the same as plugin.jar). Compiling with jaws.jar as follows: "C:\Program Files\Java\jdk-17\bin\javac.exe" -cp "C:\Users\userId\jaws.jar" "C:\Users\userId\your\package\name\SimpleApplet.java"
Yields this identical output:
SimpleApplet.java:5: warning: [removal] JApplet in javax.swing has been deprecated and marked for removal
public class SimpleApplet extends JApplet {
^
SimpleApplet.java:10: error: cannot find symbol
netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow(this);
^
symbol: method getWindow(SimpleApplet)
location: class JSObject
1 error
1 warning
It seems that the compiler is not looking at my jaws.jar. If he did, he'd find the netscape.javascript.JSObject.getWindow() method.
Can I compile with Java 17? Is there a way to force the compiler to use the jaws.jar implementation of netscape.javascript.JSObject?
A side note: The test applet above is not flagged with errors in eclipse as long as I have the jaws.jar listed before Java 17 (in Project Properties->Java Build Path: Order and Export tab). If I move Java 17 above jaws.jar, then the IDE flags getWindow() as an error. If eclipse can handle Java 17, then I assume javac should be able to, too.
本文标签:
版权声明:本文标题:Is it possible to use the Java 17 compiler to compile a Java Applet that calls netscape.javascript.JSObject.getWindow()? - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307180a1933221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论