Click to See Complete Forum and Search --> : this.getParameter doesn't work


renevanh
10-04-2007, 07:35 AM
I'm working on a small Java program which works as an applet.
The program is working fine, but I want to give some parameters in the HTML file which should be used by the applet.
Unfortunaly, the parameters don't get into the applet and the default values are used.

HTML code:


<html><head><title></title></head>
<body>
<applet code="Myapplet.class" width="400" height="400">
<PARAM name="Xcoordinaat" value="1" />
<PARAM name="Ycoordinaat" value="1" />

</applet>
</body>
</html>


Corresponding part of the Java program:



double MY = 0;
double MX = 0;

public void init() {
if (this.getParameter("Xcoordinaat")!= "" ){
MX = Double.parseDouble(this.getParameter("Xcoordinaat"));
}
if (this.getParameter("Ycoordinaat") != "") {
MY = Double.parseDouble(this.getParameter("Ycoordinaat"));
}



MX and MY are global variables (they need to be), and need to be 0 when there's is no parameter. I think the if statement is ok, because when I leave it out and I don't initialize MX and MY with 0, it's still not working.

What am I doing wrong here?

René

Setomidor
10-18-2007, 09:01 AM
One thing you're doing wrong is comparing Strings with '=='. You should use 'equals()' or 'compareTo() == 0' instead. Comparing with '==' will compare the OBJECTS not the CONTENT. You can have several distinct String objects with the value "Setomidor", but they still will return false when compared with '=='.

Don't know if this solves your problem, but it is ONE error at least.

Good luck

renevanh
10-18-2007, 04:08 PM
The problem has been solved.

Using != "" isn't a problem, the browser cache is.
When you change the applet and reload the webpage (F5), the browser doesn't reload the applet but uses the one in his cache. Closing the browser and opening it again works.

My final Java code was something with try/catch, but I did use the code mentioned above and it's working fine because I only check if the string (or the object) is empty, and that's all I had to do.

René