How to passing parameters to applets, JAVA Programming

Assignment Help:

How to Passing Parameters to Applets ?

Parameters are passed to applets in NAME=VALUE pairs in tags among the opening and closing APPLET tags. Inside the applet, you read the values passed by the PARAM tags along with the getParameter() techniques of the java.applet.Applet class.
The program below demonstrates this along with a generic string drawing applet. The applet parameter "Message" is the string to be drawn.
import java.applet.*;
import java.awt.*;

public class DrawStringApplet extends Applet {

private String defaultMessage = "Hello!";

public void paint(Graphics g) {

String inputFromPage = this.getParameter("Message");
if (inputFromPage == null) inputFromPage = defaultMessage;
g.drawString(inputFromPage, 50, 25);

}

}
You also need an HTML file that references your applet. The subsequent simple HTML file will do:
< HTML>
< HEAD>
< TITLE> Draw String
< /HEAD>

< BODY>
This is the applet:


< APPLET code="DrawStringApplet" width="300" height="50">
< PARAM name="Message" value="Howdy, there!">
This page will be very boring if your
browser doesn't understand Java.
< /APPLET>
< /BODY>
< /HTML>
Of course you are free to change "Howdy, there!" to a "message" of your choice. You only required to change the HTML, not the Java source code. PARAMs let you customize applets without changing or recompiling the code.

This applet is very similar to the HelloWorldApplet. Therefore rather than hardcoding the message to be printed it's read within the variable inputFromPage from a PARAM element in the HTML.

You pass getParameter() a string that names the parameter you want. This string should match the name of a PARAM element in the HTML page. getParameter() returns the value of the parameter. All values are passed as strings. If you want to get another type like an integer, then you'll requires passing it as a string and converting it to the type you really need.

The PARAM element is also straightforward. It occurs among and . It has two attributes of its own, NAME and VALUE. NAME identifies that PARAM this is. VALUE is the string value of the PARAM. Both should be enclosed in double quote marks if they contain white space.

An applet is not limited to one PARAM. You can pass as several named PARAMs to an applet as you like. An applet does not necessarily need to use all the PARAMs that are in the HTML. Additional PARAMs can be safely ignored.


Related Discussions:- How to passing parameters to applets

What is a target , A target is the class that is being advised. The class ...

A target is the class that is being advised. The class can be a third party class or your own class to which you require to add your own custom behavior. By using the concepts of A

A talent agency program , class Writer extends Client {    // additional m...

class Writer extends Client {    // additional members    private boolean technical = false;    private boolean government = false;    private boolean international = false;    pri

I need android kiosk mode, I need Android Kiosk Mode Project Description...

I need Android Kiosk Mode Project Description: I need an Android platform developer to develop an app when device start it start into kiosk mode. Only browser window open a c

Draw hierarchy of the people involved in the project, Suppose we have a big...

Suppose we have a big project. Draw hierarchy of the people involved in the project? Executive Team CEO, COO, CMSO Quality Architecture Team Business Development Team Technolog

What is the purpose to use the enableevents method, What is the purpose to ...

What is the purpose to use the enableEvents() method?

What is arpanet and who developed it, What is ARPANET and who developed it?...

What is ARPANET and who developed it? ARPANET stands for Advanced Research Projects. The initial reasons were to communicate along with and share computer resources between mainl

Difference b/w deep cloning and shallow cloning of object, The default natu...

The default nature of an object's clone() function automatically provides a shallow copy. So to need a deep copy the classes have to be edited or adjusted.   Shallow co

Give a example of using tostring() methods, Give a example of Using toStrin...

Give a example of Using toString() Methods ? Below is a version of CarTest in which uses toString() and System.out.println() instead of printing the fields in a straight line

Writing a program with all the primitive, Problem 1 Explain and Define ...

Problem 1 Explain and Define the following concepts with appropriate examples a) Superclass b) Subclass c) Inheritance d) Exceptions e) Stream classes >>Defining and expl

How many ways are there to call a function in a program, How many ways are ...

How many ways are there to call a function in a program? Explain with example? Two Ways of Calling Functions: Functions do not run automatically. While the page loads, every

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd