Get Applet parameter Example

  1. /*
  2. Get Applet parameter Example
  3. This java example shows how get the parameter passed to an applet using
  4. getParameter() method of Java Applet class.
  5. */
  6.  
  7. import java.applet.Applet;
  8. import java.awt.Graphics;
  9.  
  10. /*
  11.  * To pass a parameter to an Applet use <param> HTML tag.
  12.  * Specify name and value attribute to pass a parameter to an applet like
  13.  * given below.
  14.  *
  15.  * <param name="paramName" value="paramValue"/>
  16.  *
  17.  * You can pass multiple parameters for an Applet using multiple
  18.  * <param> HTML tag.
  19.  */
  20.  
  21. /*
  22. <applet code="GetAppletParameterExample" width=200 height=200>
  23. <param name="msg" value="This is a parameter example program"/>
  24. <param name="xPosition" value="50"/>
  25. <param name="yPosition" value="50"/>
  26. </applet>
  27. */
  28.  
  29. public class GetAppletParameterExample extends Applet{
  30.  
  31. public void paint(Graphics g){
  32.  
  33. int x = 0;
  34. int y = 0;
  35. String msg = "";
  36.  
  37. try{
  38. x = Integer.parseInt(getParameter("xPosition"));
  39. }
  40. catch(NumberFormatException ne){
  41. msg = msg + "Invalid x Value";
  42. }
  43.  
  44. try{
  45. y = Integer.parseInt(getParameter("yPosition"));
  46. }
  47. catch(NumberFormatException ne){
  48. msg = msg + "Invalid y Value";
  49. }
  50.  
  51. msg = getParameter("msg");
  52.  
  53. g.drawString(msg, x, y);
  54. }
  55. }

Visit Java Example Forums to request Java examples or ask Java questions!
OR
Try out our new Java Search Engine




Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

Could not find what you are looking for? Search Java Examples




Feel Tired? Read Jokes & Inspirational Stories, Play Games!