As with any Java™ application, you must begin by importing
the necessary classes and defining the program's classes.
- Create a new Java source
file called calculateAge.java.
- Any program that calls methods from the API must
import the following classes:
import com.ibm.form.api.DTK;
import com.ibm.form.api.xfdl.FormNodeP;
import com.ibm.form.api.xfdl.XFDL;
import com.ibm.form.api.error.UWIException;
import com.ibm.form.api.IFSSingleton;
- You must place these lines before any class or
interface definitions.
- Set up the rest of your application. This generally
includes defining any classes and methods for your application as
well as declaring and initializing any variables you may need. The
following code sets up the Calculate Age application:
- Create the public class CalculateAge and
the main method for the class.
public class CalculateAge
{
- Declare a FormNodeP object called theForm to
represent the form.
private static FormNodeP theForm;
- Create the program's main method.
public static void main(String argv[])
{
- Declare the program's variables.
int birthYear;
int birthMonth;
int birthDay;
- The program's main method essentially
consists of a series of calls to other methods. The Form Library methods
are called from the definition of these methods.
try
{
initialize();
loadForm();
birthYear = getBirthYear();
birthMonth = getBirthMonth();
birthDay = getBirthDay();
setBirthYear(birthYear);
setBirthMonth(birthMonth);
setBirthDay(birthDay);
saveForm();
- Free the memory in which the form was stored. For
more information see Closing a Form .
theForm.destroy();
}
- Finally, perform exception handling.
catch (Exception ex)
{
ex.printStackTrace();
}
/* Additional code removed */
}
}