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

Explain what is local variable, Explain what is Local Variable ? Declar...

Explain what is Local Variable ? Declaring variables (using the var keyword) inside a function forms them local. They are available only inside the function and hold no meaning

Benefits of spring framework, Benefits of Spring framework : Spring can...

Benefits of Spring framework : Spring can effectively organize your middle tier objects as given in the diagram above, whether or not you select to use EJB. Applications create

What is the major role of ejb 2.x in j2ee? , EJB 2.x is broadly adopted ser...

EJB 2.x is broadly adopted server side component architecture for J2EE. 1. EJB is a remote, distributed multi-tier system and allows protocols like IIOP, JRMP, and HTTP etc.

Help, Are you real? I dont want to get help from a computer

Are you real? I dont want to get help from a computer

I want prosport savings plans, I want ProSport Savings Plans Project Des...

I want ProSport Savings Plans Project Description: To prepare an application on iPhone, Mac, iPad and Android, which does the subsequent:- Provides a calculation of the am

Minimum spanning tree based heuristic, Problem description: A travelling s...

Problem description: A travelling salesman wants to make a tour of the cities and returns back to the starting point. What is the minimum length tour? Formal Definiti

Functions in javascript, The following set of short questions will focus on...

The following set of short questions will focus on getting you familiar with JavaScript functions. All functions and testing should appear in a single XHTML 1.0 Strict page. All

Explain term literals in java, Explain term Literals in java? Literals ...

Explain term Literals in java? Literals are pieces of Java source code which mean exactly what they say. For example "Hello World!" is a String literal and its meaning is the w

Explain different way of using thread, Explain different way of using threa...

Explain different way of using thread? The thread could be executed by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cau

Describe even higer dimensions in java, Describe even higer dimensions in j...

Describe even higer dimensions in java? You don't have to stop along with two dimensional arrays. Java allows arrays of three, four or more dimensions. Therefore chances are pr

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