##### Example 1: TestDesignInvoice.java

TestDesignInvoice.java in `<insatll_root>\help\samples\APIDesign` is primarily designed for creating a report with the methods provided by the Design API. Here is an explanation of how TestDesignInvoice.java works.

- Creating an instance of Designer
  `desg = new Designer(path, cat);`

  The constructor of Designer has two parameters: path and name. They are respectively the path and name of the catalog with which the report will be created.

- Setting log if necessary
  `desg.setLog(new FileOutputStream(log), "8859_1");`

  The output stream log points to the path and file in which to write log messages. Parameter "8859_1" is the encoding for the messages.

- Getting handles
  `handles = desg.getHandles(report, Designer.PAGE);`

  This method gets all handles of PAGE type and returns a handle array. Parameter report is the parent handle, and Designer.PAGE is a class type value which is defined in the Designer class.

- Creating a report set
  // Create a report set. Use the name from the -name parameter.
  reportset = designer.createReportSet(name);

  This method creates a new report and returns its handle. Parameter name is the name of the report that is to be created.

- Adding a connection
  `// Register the existing query "WorldWideSales" to this report set.
  dataset = designer.addDataset(reportset, "Data Source 1", "WorldWideSales","dsWorldWideSales", "",Designer.DATASET_TYPE_QUERY);`

  This method adds a dataset to the report. The dataset must exist in the referenced catalog.

- Adding a report tab
  `// Add a report tab named "Invoice" to the report set.
  report = designer.addReport(reportset, "Invoice");`

  This method creates a new report and returns its handle. Parameter name is the name of the report that is to be created.

- Adding a banded object
  `// Insert the banded object for the invoice report
  banded = designer.insertBandedObject(reportbody, true, true, true);`

  This method adds a banded object into our report tab.

- Inserting a group panel
  `gGroupInfo ginfo =new GroupInfo( "Customers_Customer ID", GroupInfo.DESCENDING );
  groupCust = designer.insertSectionGroup( handles[0], ginfo );`

  This method inserts a new group panel and returns its handle. Parameter handles[0] is the parent node handle. The newly inserted object will be in this node. Customers_Customer ID is the mapping name to group by.

- Inserting a label
  `handle = desg.insert(header, Designer.LABEL, "Label1");`

  This method inserts a label named label1 into the group header. Parameter header is the parent handle, the newly inserted object will be in this node. desg.LABEL is the class type that you want to insert, and Label1 is the object name to be inserted.

- Inserting DBField
  `handle = desg.insert(header, Designer.DBFIELD, "DBField1", "Orders_Order ID");`

  This method inserts a DBField named DBField1 into the group header. Parameter header is handle of the parent node; Designer.DBFIELD is class type that is to be inserted, and Orders_Orders ID is the mapping name of the database field.

- Inserting a formula, parameter and summary
  To insert a formula, parameter or summary, use the same method as for inserting a DBField. Note that the formula, parameter or summary that is to be inserted should already exist in the catalog.

  For example, in the sample program, it is made sure that the parameter PToday, formula customeraddress12, and summary Sum_total9 already exist in the catalog by the following:

  `handle = desg.insert(header, Designer.PARAMETER, "Parameter1", "PToday");
  handle = desg.insert(header, Designer.FORMULA, "formula1", "customeraddress12");
  handle = desg.insert(footer, Designer.SUMMARY, "summary1", "Sum_total9");`

- Inserting an image, box and line
  To insert an image, box or line, use the same method as for inserting a label.

  For example, in the sample program, you can insert the image, box and line as follows:

  `handle = desg.insert(header, Designer.IMAGE, "Image1");
  handle = desg.insert(report, Designer.BOX, "Box1");
  handle = desg.insert(report, Designer.LINE, "Line1");`

- Setting the property value
  To set the property value, you should provide three parameters: object handle, property name and property value.

  In the sample program, you can set the property value as follows:

  `desg.set(handle, "Width", 1.74f);desg.set(handle, "Height", 0.35f);desg.set(handle, "Text", "Invoice");desg.set(handle, "Alignment", desg.LEFTCENTER);desg.set(handle, "Foreground", new Color(0x900000));desg.set(handle, "Bold", true);desg.set(handle, "FontSize", 0.31f);`

- Exiting and closing all reports
  `desg.exit();`

  This method ends the editing status, releases all resources and saves all of the reports and the catalog.

- Compiling and running the sample program
  To compile and run the sample program, you should add report.jar, sac.jar, log4j-1.2.8.jar and JREngine.jar with their path into the class path.

  For example, you can use the following command to compile the sample program:

  `C:\JReport\Designer\help\samples\APIDesign>javac -classpath "C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\sac.jar;C:\JReport\Designer\lib\JREngine.jar;C:\JReport\Designer\lib\log4j-1.2.8.jar" TestDesignInvoice.java`

  When you run the sample program, you should provide two or three parameters. If you want to use two parameters, they should be catalog path and catalog name, and the command line should be:

  `C:\JReport\Designer\help\samples\APIDesign>java -Dreporthome="C:\JReport\Designer" -classpath "C:\JReport\Designer\lib\jrengine.jar;C:\JReport\Designer\lib\sac.jar;C:\JReport\Designer\lib\resource_en_US.jar;C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\log4j-1.2.8.jar;C:\JReport\Designer\lib\hsqldb.jar" TestDesignInvoice -path=C:\JReport\Designer\Demo\Reports\TutorialReports -catalog=JinfonetGourmetJava.cat -report=TestInvoice.cls`

  If you want to use three parameters, they should be catalog path, catalog name and log file with a full path name, and the command line should be:

  `C:\JReport\Designer\help\samples\APIDesign>java -Dreporthome="C:\JReport\Designer" -classpath "C:\JReport\Designer\lib\JREngine.jar;C:\JReport\Designer\lib\sac.jar;C:\JReport\Designer\lib\resource_en_US.jar;C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\log4j-1.2.8.jar;C:\JReport\Designer\lib\hsqldb.jar" TestDesignInvoice -path=C:\JReport\Designer\Demo\Reports\TutorialReports -catalog=JinfonetGourmetJava.cat -report=TestInvoice.cls -log=C:\JReport\Designer\logs\designer.log`

  Here, it is assumed that JReport Designer has been installed to `C:\JReport\Designer`, and the current directory when you execute these commands is `C:\JReport\Designer\help\samples\APIDesign` (location of the sample programs). After running the program, you will find a newly created file TestInvoice.cls in `C:\JReport\Designer\Demo\Reports\TutorialReports`.