Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Applet - Passing Parameter in Java Applet

                         

Introduction

Java applet has the feature of retrieving the parameter values passed from the html page. So, you can pass the parameters from your html page to the applet embedded in your page. The param tag(<parma name="" value=""></param>) is used to pass the parameters to an applet. For the illustration about the concept of applet and passing parameter in applet, a example is given below.

In this example, we will see what has to be done in the applet code to retrieve the value from parameters. Value of a parameter passed to an applet can be retrieved using getParameter() function. E.g. code:

String strParameter = this.getParameter("Message");

Printing the value:

Then in the function paint (Graphics g), we prints the parameter value to test the value passed from html page. Applet will display "Hello! Java Applet"  if no parameter is passed to the applet else it will display the value passed as parameter. In our case applet should display "Welcome in Passing parameter in java applet example." message.

Here is the code for the Java Program : 

import java.applet.*; 
import java.awt.*; 
             
public class appletParameter extends Applet {
  
private String strDefault = "Hello! Java Applet.";
  
public void paint(Graphics g) {
    String strParameter = 
this.getParameter("Message");
   
 if (strParameter == null)
    strParameter = strDefault;
    g.drawString(strParameter, 50, 25);
  } 
}

Here is the code for the html program : 

<HTML>
<HEAD>
<TITLE>
Passing Parameter in Java Applet</TITLE>
</HEAD>
<BODY>

This is the applet:<P>
<APPLET code="appletParameter.class" width="800" height="100">
<PARAM name="message" value="Welcome in Passing parameter in java applet example.">
</APPLET>
</BODY>
</HTML>

There is the advantage that if need to change the output then you will have to change only the value of the param tag in html file not in java code.

Compile the program : 
javac appletParameter.java

Output after running the program : 
To run the program using appletviewer, go to command prompt and type appletviewer appletParameter.html Appletviewer will run the applet for you and and it should show output like
Welcome in Passing parameter in java applet example. Alternatively you can also run this example from your favorite java enabled browser.

Try the example online

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
WebLogic Server Tools
Binary Tree JTree
h:inputtext tag in jsf
Photoshop Photo Retouc
Bubble sort with two n
calendar.set
passing values from js
optionsCollection
adding label and textb
options
compare two dates in j
i need simple date for
jbossconnectionpool
HQL
finding superscript in
Photoshop Web Layouts
dwr reverse ajax
ArrayList
reading file(java)
capture screen j2me
ะà???ะ ยà¸?ะà
Jtable
intranet applications
validations in js
how to traverse throug
drop down list box
session validation
Photoshop Photography
sum of digits
java mail api
Bean class tag
create menubar
onglet css
wait
jdk1.4
sample palindrome prog
type casting
VNCj (Java VNC S
Java com
datalist
jsp bean get property
/n java
menu gui
java inner class
java counter
t:datalist
how to save JDBC Conne
B Tree implementation
how to installmcat
Logger
java random numbers
panelGrid/
Javascript Menus Image
spring
clear grid dojo
fjhjf
JSP forward
struts custom tag
MULTIPLE SELECT COMBO
insert data to text fi
panelgrid colspan
game in java
String to array in jav
iBatis Stored Procedur
rules
Photoshop
Linux Caixa MаÐ??аÐ?
J2ME Recordstore
Java code for media pl
add row, delete row an
JPA Tutorials
Take user input using
java programmes
debugging java
JSP:File Input Paramet
is the jvm same for al
how to write hql in da
jms examples
Inserting data from gu
creating eclipse insta
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.