This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing Parameters to Applets

 
Collete Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic