Sunday, November 27, 2011

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. }

No comments:

Post a Comment

How to find the most appropriate Keywords?

  🔍 Step 1: Understand Your Business and Audience Define your products, services, or content . Identify your target audien...