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 bean lifecycle in spring framework, 1. The spring container searche...

1. The spring container searches the bean's definition from the XML file and instantiates the bean. 2. Using the dependency injection, spring populates all of the properties as

Gui-based event-driven application program, GUI-Based Application Object...

GUI-Based Application Objectives:   (1)   Learning how to write a GUI-based application in Java. (2) Learning how to write an event driven application program in Java.

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

Describe interfaces in java langauge, Describe Interfaces in java langauge?...

Describe Interfaces in java langauge? Interfaces are the further level of abstraction. An interface is like a class along with nothing but abstract methods and final, static fi

What is the importance of static variable, What is the importance of static...

What is the importance of static variable? Static variables are class level variables where all objects of the class refer to the similar variable. If one object alters the val

Describe exception handling in java, Question A What are the difference be...

Question A What are the difference between an interface and an abstract class? Question B Describe Exception Handling in JAVA Question C Describe the following with resp

Time date millis method, I neeed to create a basic code to do the following...

I neeed to create a basic code to do the following. the class is entry level and I would appreciate a brief explanation as to why you do each bit. Write a program that displays t

I want to develop a chat application for j2me, I want to develop a Chat app...

I want to develop a Chat application for j2me Project Description: We require a chat application for a community website. Skills required: Java, J2ME

Statements and operators, Operator Functionality E x...

Operator Functionality E x ample/Explanation = Sets one value equal to another counter=0  Sets the counter to equivale

Give an example of code using static and finalize, Give an example of code ...

Give an example of code using static and finalize Example Code: using static & finalize () We want to count exact number of objects in memory of a Student class the one de

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