/    Sign up×
Community /Pin to ProfileBookmark

this.getParameter doesn’t work

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:

[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>
[/code]

Corresponding part of the Java program:

[code]

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”));
}

[/code]

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é

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@SetomidorOct 18.2007 — 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
Copy linkTweet thisAlerts:
@renevanhauthorOct 18.2007 — 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é
×

Success!

Help @renevanh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...