aspose file tools*
The moose likes Beginning Java and the fly likes Passing Parameters to Applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing Parameters to Applets" Watch "Passing Parameters to Applets" New topic
Author

Passing Parameters to Applets

Collete Williams
Greenhorn

Joined: May 03, 2011
Posts: 4
My code creates a traffic light which changes colors which took me over a week just to do that. When you run the html it automatically changes the color. There is an extra twist in which I am to write an HTML file to run the applet (done). But I am also to use param tags to pass the duration of each color. I know it has something to do with "PARAM NAME="SPEED" VALUE="1000">" tag. But I am not understanding exactly how this parm tag would supercede the sleep time I have in my code. I have googled the subject about parms and most of data I have read about a string, not time duration. Could someone please let me know what I am missing, I would greatly appreciate it..




Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
It's been a long time since I did applets, but I think I can help with this one.

Yes, any param you get is going to be a string; you can convert the string to whatever kind of value you need.

So you need a duration. A fairly simple way of doing it is to have the parameter specify a number of milliseconds. You get a string that has that value, convert it to an int or long, and then use it as the duration of a timer or whatever.

Just by-the-bye, in the examples I've seen, you close the APPLET tag, then have the PARAM tag, then have the APPLET closing tag:
<APPLET
CODE = "TrafficLight.class"
width = "300"
height = "300"
>
<PARAM NAME="speed" VALUE = "1000">
</APPLET>

And then in your applet class, you can call getParameter and then convert the returned value (getParameter being a method on Applet)

String speedString = getParameter("speed");

long speed = 0;

try { speed = Long.parseLong(speedString); }
catch (NumberFormatException nfe)
{ // code in here to handle a bad parameter
}

rc
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Parameters to Applets