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 Applets and the fly likes passing parameter to applet 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 » Applets
Bookmark "passing parameter to applet" Watch "passing parameter to applet" New topic
Author

passing parameter to applet

karthik muthuveeramani
Greenhorn

Joined: Apr 12, 2001
Posts: 5
when i run the following code i invariably get a null pointer exception please help me out.
import java.awt.*;
import java.applet.*;
/*<applet code="MyApplet.class" width=200 height=300>
<param name="message" value="hello world">
</applet>
*/
public class MyApplet extends Applet
{
String uuu;
public void init()
{
uuu=getParameter("message");
}
public void start()
{
repaint();
}
public void paint(Graphics g)
{
/*if(getParameter("message")==null)
{
g.drawString( "",20,20);
}
else*/
g.drawString(uuu ,20,20);
}
}//end applet
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Hi Karthik,
Don't use start method. Just use Init and Paint method.
Thanks,
Angela
karthik muthuveeramani
Greenhorn

Joined: Apr 12, 2001
Posts: 5
hi angela
thanks for your reply. i tried it but strangely its not working.
pl help me.
thanks once again
karthik
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428

Hi Karthik,
Here is code:
import java.applet.Applet;
import java.awt.*;

public class MyApplet extends Applet
{
String uuu;
public void init()
{
uuu=getParameter("message");
}
public void paint(Graphics g)
{
g.drawString(uuu ,20,20);
}
Here is HTML file:
<html>
<head>
<title>Card Test (1.1)</title>
</head>
<body>
<applet code=MyApplet.class width=500 height=900>
<param name="message" value="hello world">
</applet>
</applet>
</body>
</html>
It is working!
Let me know further help,
Thanks
angela
venkataraman bagavathisub
Greenhorn

Joined: Dec 19, 2000
Posts: 2
i am karthik's friend.
thank you angela the code is working .i actually had a ie-jvm problem.got alright after reinstalling it(windows jvm).
this is actually for a ticker tape.its moving very slowly even if i adjust the Thread.sleep to 10(Thread.sleep(10)).i will be looking for answers , meanwhile you also pass suggestions.
thanking you
karthik
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

To make the scrolling move faster, increase the x ( or y ) amount that you are moving the text each time. This will make a much bigger difference than increasing the Thread speed...

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67
Hi
I am using JDK1.3,
I have to pass arguments to Applet.
I am using html converted file from JDK1.3 HTML converter.
I am getting parameter in IE. but Netscape returning null
I tryed use getParameter in init(), start() also.
both the cases Netscape is failing to get the parameter
any help?
thanks in advance
Mohana
ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
Do you guys know how to pass an array of values to an Applet ?
I mean one parameter name, the value of the parameter is an array (e.g. 10000 elements).
Please comments if you have ideas on how to do it.
Thanks
Ruilin
 
Don't get me started about those stupid light bulbs.
 
subject: passing parameter to applet
 
Similar Threads
NUllPointerException
Start: applet not initialized
applet not working..... and I can't figure out why
Start: applet not initialized
Running applets