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