How can we pass parameters to applet from HTML files? Explain with proper example.

 We can pass parameters into an applet via the <param name="paramName" value="param Value"/> tag nested within the <applet> tag. Inside the applet source code, we can use getParameter(StringparamName) to get the paramValue in the form og String; or null if the parameter does not exist. For example,

Example //.java File

import java.awt.*;

import javax.swing.*;

public class ParamTest extends JApplet

{

String msg;

public void init ()

{

msg= getParameter("message");

if (msg=null) msg = "Hi";

createGUI();

}

private void createGUI()

{

Container cp = getContentPane();

cp.setBackground (new Color (204, 238, 241)); 

cp.add(new JLabel(msg, JLabel.CENTER));

}

}

//.html File

<html>

<head>

<title>A Swing Applet with Parameter</title>

</head>

<body>

<h3>A Swing Applet with Parameter</h3>

<applet code="ParamTest.class" width="300" height="60" alt="Error Loading Applet!">

<param name="message" value="Hello, world!" />

</applet>

</body>

</html>



Comments

Popular posts from this blog

Suppose that a data warehouse consists of the four dimensions; date, spectator, location, and game, and the two measures, count and charge, where charge is the fee that a spectator pays when watching a game on a given date. Spectators may be students, adults, or seniors, with each category having its own charge rate. a) Draw a star schema diagram for the data b) Starting with the base cuboid [date; spectator; location; game], what specific OLAP operations should perform in order to list the total charge paid by student spectators at GM Place in 2004?

Explain Parallel Efficiency of MapReduce.

Short Note on Security Architecture of E-governance