![]() ![]() |
This tutorial provides instructions for writing a set of event handlers. The tutorial assumes that you have a basic report design based on the Classic Models, Inc. Sample Database. The only requirement of the starting report design is that it contains a table of customers with a column for the customer name. In this tutorial you count the customers whose names contain the string "Mini" and display the result in a pop-up window.
In this tutorial, you perform the following tasks:
Open a report design that uses the Classic Car sample database and displays a table of customer names.
In order to count the number of customers whose names contain the string Mini, you must first declare a global counter and set its value to zero. The Table.onCreate( ) method is the most appropriate place to do this task because Table.onCreate( ) executes before any rows are retrieved. You conditionally increment this counter in the Row.onCreate( ) method.
To count the number of customers with the string Mini in their names, you must examine each customer's name and add one to the counter for every occurrence. A logical place to do this task is in the Row.onCreate( ) method, which is executed upon every retrieval of a row of data from the data source.
To display the count of customers with the string Mini in their names, you insert code in a method that runs after the processing of all the rows in the table. One logical place for this code is in the ReportDesign.afterFactory( ) method.
importPackage( Packages.javax.swing ); frame = new JFrame( "Count of Minis = " + countOfMinis ); frame.setBounds( 310, 220, 300, 20 ); frame.show( );
If you do not see the Count of Minis window, look for it behind the Eclipse window. If the Count of Minis window does not appear, the most likely reason is a scripting error caused by an error in one of your code entries.
If you suspect that a scripting error has occurred, scroll to the bottom of the report, where all scripting error messages appear. In most situations, there is a brief error message next to a plus sign ( + ). The plus sign indicates that there is a more detailed error message that is only visible after you expand the brief error message. To expand the brief error message, choose the plus sign. Scroll down to see the more detailed error message.
![]() ![]() |