This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
 
subject: Passing Parameters to Applets
 
Similar Threads
YoYo goes up and down on a string but the yoyo doll doesn't display it appears broken in Internet Ex
Moving an object such as an arc.
Calling an applet from another class of the same package
Moving Circles
Need help writing a code involving bar charts!