passing in parameters to an applet

58 views
Skip to first unread message

Charlie

unread,
Aug 9, 2010, 12:19:03 AM8/9/10
to gwtai
Is there any way to pass in data to an applet at startup? My applet
needs to connect to a host and port to do some video streaming, and I
want to pass in this data in the constructor of the applet.

thx!

kilkenny

unread,
Aug 9, 2010, 2:36:16 AM8/9/10
to gwtai
Hi Charlie

Yes, you can do so using Applet Parameters. The main principle is
explained in 'The Java Tutorials' by Oracle/Sun:
http://download.oracle.com/javase/tutorial/deployment/applet/param.html

GwtAI has the annotation com.google.gwt.gwtai.applet.client.Params to
construct such an Applet Parameters object. Have a look at the
JavaFXApplet demo, the @Params is used in this example:
http://code.google.com/p/gwtai/source/browse/trunk/gwtaifx/src/com/google/gwt/gwtai/demo/client/JavaFXApplet.java

Regards, Adrian
Message has been deleted

Charlie

unread,
Aug 10, 2010, 12:10:48 AM8/10/10
to gwtai
...not sure if my last response got posted

Is it possible to send parameters at runtime? Looks like you can only
configure these params using annotations at compile time. I want to
know at runtime what that host URL is, and this URL to the apple.

Maybe another angle on this question is: can I call
GWT.getHostPageBaseURL() from within an applet?

thanks

On Aug 8, 11:36 pm, kilkenny <a.bue...@gmail.com> wrote:
> Hi Charlie
>
> Yes, you can do so using Applet Parameters. The main principle is
> explained in 'The Java Tutorials' by Oracle/Sun:http://download.oracle.com/javase/tutorial/deployment/applet/param.html
>
> GwtAI has the annotation com.google.gwt.gwtai.applet.client.Params to
> construct such an Applet Parameters object. Have a look at the
> JavaFXApplet demo, the @Params is used in this example:http://code.google.com/p/gwtai/source/browse/trunk/gwtaifx/src/com/go...

kilkenny

unread,
Aug 10, 2010, 2:40:50 AM8/10/10
to gwtai
Hi Charlie

Okay, I see the problem. Actually the way Applet Parameters work, they
could be used dynamically. But with the annotation based solution in
GwtAI this does not work. In GwtAI the Applet tag with the parameters
is constructed at compile time, thus you have to know the parameter
values at compile time.

Now there are different solutions to the problem.

If you rely on dynamic Applet Parameters the straight forward
workaround is to construct your own Applet Proxy. Instead of creating
an interface for your Applet and adding annotations to this interface,
write an Applet Proxy class. The class has to extend
'com.google.gwt.gwtai.applet.client.AppletAccomplice' and implement
'com.google.gwt.gwtai.applet.client.Applet'. Of course you have to
implement all your dynamic parameter logic and all required methods in
this class, but that should be self explanatory. You can then pass
your new class to the 'createAppletWidget(..)' method of the
'com.google.gwt.gwtai.applet.client.AppletJSUtil' class...

Another way is to just add some kind of setter method to your Applet.
Something like 'myApplet.setHostPageBaseURL(String url)'. See how the
TrayIcon demo handles 'addTextItem(String caption)' for example.

The other option is, you could help to improve GwtAI and think of a
good way to handle dynamic Applet Parameters. I would probably add a
method 'createAppletWidget(Applet applet, HashMap parameter)' or
something like that to the
'com.google.gwt.gwtai.applet.client.AppletJSUtil' class...

Hope that helps!
Adrian

Charlie

unread,
Aug 10, 2010, 10:27:59 PM8/10/10
to gwtai
Thanks for the good response Adrian, I will ponder these options. But
one more question (for now ..). I see that all calls to the applet
from the gwt client are made on a user gesture (button press, etc). If
I try to call any applet method from the main thread (not from a user
event) I get an error basically saying the applet is not up and
running yet. How do I know when the applet is instantiated? Can I sit
in a loop polling some status until it indicates the applet is up?
Then I could call some initialization method and get the rest of the
applet to execute.

thx!

kilkenny

unread,
Aug 12, 2010, 7:07:07 AM8/12/10
to gwtai
Hi Charlie

Polling is an option, or you can try to call back from the applet once
it is initialized. I have not actually tried the code, but something
like this should work:

-- The applet interface --
public interface TheApplet extends Applet {

public void setHostPageBaseURL(String url);

}

-- In the GWT code --
final TheApplet applet = (TheApplet) GWT.create(TheApplet.class);

AppletJSUtil.registerAppletCallback(applet, new
AppletCallback<String>() {

public void callback(String state) {
String url = GWT.getHostPageBaseURL();
applet.setHostPageBaseURL(url);
}

});

-- In the Applet implementation --
public class TheAppletImpl extends JApplet implements TheApplet {
private String _url;

@Override
public void start() {
super.start();
AppletUtil.callback(TheAppletImpl.this, "STARTED");
}

@Override
public void setHostPageBaseURL(String url) {
_url = url;
}

}

Regards, Adrian
Reply all
Reply to author
Forward
0 new messages