dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Feb 18, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Provide Default Values for Applet Parameters

You can customize your applets by providing parameters at runtime in <param>. 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();
         }
}
Nilesh Shah
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date