devxlogo

Provide Default Values for Applet Parameters

Provide Default Values for Applet Parameters

You can customize your applets by providing parameters at runtime in. But it is a good practice to always provide default values, when specific values for parameters are not provided.

You can do this by checking for null values and/or proper type checking (if you expect numeric or date values). Here is the code:

 public class MyApplet extend Applet {         public void  init(){          // Get the Parameter	  String  frameTitle = getParameter("FRAME_TITLE");	  // Check for Null	   if (frameTitle  == null) {	       // Provide Default value	        frameTitle = "Frame to Test Parameters";	   }	  String frameWidthString = getParameter("FRAME_WIDTH");	  int   frameWidthInt = 0;	  try{	        frameWidthInt =  Integer.parseInt(frameWidthString);	  } catch(Exception ex){	       // Catch Exception if frameWidthString is null or invalid value               // Default value	       frameWidthInt = 100;	  }	  String frameHeightString = getParameter("FRAME_WIDTH");	  int   frameHeightInt = 0;	  try{	        frameHeightInt =  Integer.parseInt( frameHeightString );	  } catch(Exception ex){	       // Provide Default Value	       frameHeightString = 100;	  }	 Frame f = new Frame(frameTitle);	 f.setSize(frameWidthInt,frameHeightString);	 f.show();         }}
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist