1 / 10

Passing Parameter to an Applet

Passing Parameter to an Applet. User-defined parameters can be passed to an applet using the <PARAM…> tags . < APPLET …..> < PARAM name=“age” value = “22”> < PARAM name=“class” value = “MCA ”> </PARAM> </APPLET>. Sample Program. <html > < head>

jean
Download Presentation

Passing Parameter to an Applet

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Passing Parameter to an Applet User-defined parameters can be passed to an applet using the <PARAM…> tags. <APPLET …..> <PARAM name=“age” value = “22”> <PARAM name=“class” value = “MCA”> </PARAM> </APPLET>

  2. Sample Program <html> <head> <title>Hello World</title> </head> <body> <applet code="ParamTest.class" height=200 width=200> <param name="String" value="Welcome to Applet Programming"> </param> </applet> </body> </html>

  3. Sample Program import java.awt.*; import java.applet.*; public class ParamTest extends Applet { String str; public void init() { str=getParameter("String"); setBackground(Color.yellow); setForeground(Color.red); } public void paint(Graphics g) { super.paint(g); g.drawString(str,20,20); } }

  4. getDocumentBase The signature of the method getDocumentBase() defined by Applet class is: public URL getDocumentBase() The method getDocumentBase() gets the URL of the document in which this applet is embedded. For example, suppose an applet is contained within the document: http://java.sun.com.products/jdk/1.5/index.html The document base is: http://java.sun.com.products/jdk/1.5/index.html

  5. getCodeBase • The signature of the getCodeBase method is • public URL getCodeBase() • The method gets the base URL. This is the URL of the directory which contains this applet

  6. Code for An applet program to give demo of getDocumentBase() and getCodeBase() methods /* <applet code="URLDemo" height=100 width=400> </applet> */ import java.awt.*; import java.applet.*; import java.net.*; Public class URLDemo extends Applet { publicvoid paint(Graphics g){ String msg; URL url=getCodeBase(); msg = "Code Base : "+url.toString(); g.drawString(msg,10,20); url=getDocumentBase(); msg="Document Base : "+url.toString(); g.drawString(msg,10,40); } }

  7. showDocument method • Defined in the Applet Context interface. • showDocument(URL) – Displays the document represented by the URL • showDocument(URL,where) • Displays the document represented by the URL at the location • specified by where

  8. Applet Context Interface • Applet Context is an interface that is defined in the java.applet package. • It is used by an applet to obtain information from the applet's environment through its methods. • Using methods of this interface, we can transfer control to another document.

  9. Working with Graphics • Rich class of graphics methods defined in the awtpackage. • Can be drawn relative to a window. • The origin of each window is at the top-left corner and is 0,0. • Coordinates are specified in pixels.

  10. Graphic Methods

More Related