简体   繁体   中英

Pass parameters to a Java Applet from Java Program

I want to change the os.name property before invoking an applet.

(Using appletviewer -J-Dos.name=Windows on Linux raises a lot of exceptions, understandably so)

So, I figured I'll use System.setProperty() to set the os name in a Java Program (ie the JVM on starting will have the correct OS name, but the applet won't) and then invoke the applet from there (by calling it's init() function)

The issue is I don't know how to pass the parameters to the applet (the ones I'd normally be using the param HTML tag for.)?

Any ideas?

I think it might be possible by implementing the AppletStub interface, but I'm not sure how to implement the other methods (apart from getParameter).

You can browse the source code of the appletviewer from the OpenJDK for ideas, or even reuse its code for your purposes. However, it is possible to display an applet in less code than that, if you don't need all the features of Oracle's appletviewer. I found this one from Ian F. Darwin , or even this post from Sandeep Sharma which seems to be a really stripped-down version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM