Problem with getParameter from HTMl file using param tag
Hi I need help plese, could any one tell me how to Pass in avirable from the HTML file using the PARAM tag. Also, pass in parameters to specify the font and colour of the text that is drawn to the screen. I did creat an Applet to demostrate it but doesn't displeay the the name said Hello null insteat of hello Ali.
Code:
public class DrawName extends java.applet.Applet {
String name;
Color color;
Font font;
/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
name = getParameter("name");
//color= getParameter("color");
//font= getParameter("font");
}
// TODO overwrite start(), stop() and destroy() methods
public void paint(Graphics g) {
//g.setColor(color);
g.drawString("Hello" + name ,50,30);
}
}
HTML Code:
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="DrawName.class" width=350 height=200>
<param name="name" value="Ali">
</APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>
Re: Problem with getParameter from HTMl file using param tag
Code:
public class DrawName extends java.applet.Applet {
private String name;
private Color color;
Font font;
/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init( String name ) {
name = getParameter("name");
//color= getParameter("color");
//font= getParameter("font");
}
Try this, i don't now if its work because i don't work with applets but normally this will work..
Re: Problem with getParameter from HTMl file using param tag
Just like markb1986 said, you can use the getParameter method to read param values. and here's an example:
HTML Code:
<html>
<body>
<applet code="MyApplet.class" style="width: 800px; height: 600px;">
<param name="name" value="My name">
</applet>
</body>
</html>
Code:
public class MyApplet extends JApplet {
@Override
public void init() {
String name = getParameter("name");
if (name != null && !name.isEmpty()) {
JOptionPane.showMessageDialog(null, name, "Name", JOptionPane.PLAIN_MESSAGE);
}
}
}