Part two: Using Jasperreport as a report control to develop FAT client report application

Source: Internet
Author: User
Tags pack

Hint: in some plate, the picture in the article does not see, suggest to my blog browsing article: http://blog.csdn.net/jemlee2002/
The article will cover 3 elements:

Part I: The detailed process of using ireport to make reports (under Windows environment)

Part two: Using Jasperreport as a report control to develop FAT client report application

Part III: Using Jasperreport as a report control to develop web report applications

1. Overview

We have a brief recollection of the contents of the first part, the first part mainly introduces how to make a data report using ireport, and I think the article gives a more detailed introduction to "How to meet most of the requirements report from zero". But the article does not involve any content of jasperreport, the purpose is to let you pure understanding of how to do the report, because the report and the report embedded into the application programming can be divided, easy to integrate and easy to decompose.

We know that ireport is a Jasperreport front-end development tool that ireport used to make and preview reports, providing sufficient front-end support for application usage reports. Now a brief introduction of how jasperreport work, so that you can better understand how ireport help Jasperreport to achieve the front-end work, in fact, these work in our view is "dirty", why. Take a look at the information below to find out.


By the above figure you probably already understand how the Jasperreport works. The first is to have an XML file (usually with the jrxml suffix), and the XML file comes from there. What to do with it. This XML file is the definition file for the report, every detail of the report is defined in this XML file, and there are hundreds of lines of XML files for a simple report, which you can edit manually (one line at a time, a section of editing-this is called "dirty Work"). If you are making this XML file by hand, it is not allowed to consider efficiency alone, especially now the development time of many application systems becomes more and more tense, and it always goes wrong in time. The best way to save time is to make full use of automation tools, and James Martin's software engineering idea is to repeatedly emphasize process automation and how to automate it. Is the full use of automation tools integrated into the development process, said a lot of not to say to use ireport to do the report.  This is the first part of the work we've done, but it's important to understand how Jasperreport works.

2, combined with jbuilder development of Fat Client report Application 2.1, the establishment of application

Refer to JBuilder related information. As long as the Normal window window application can be.

2.2, the introduction of jasperreports needs of the library files

Through the Jbuilder9 "Tool"-"Configure Libraries"-Press the leftmost "New"-Enter a name, such as the report-"Add" button, navigate to the ireport Lib directory, the Lib directory to introduce all the files. As shown in figure:


Press two times OK to return to the JBuilder development interface.

2.3, add to the Project series library files

By right-clicking the project, select "Properties"-"Paths" label-"Required Libraries" label-"ADD" button-select "" "-press two times OK to return to the JBuilder development interface. This adds the library file that you want to complete. This is ideal, but the report runtime may not need all of the jar files under ireport lib.

2.4, add the required components on the main interface

Add a button and a label along with a textbox in the main frame, and of course you can also create a menu connection, as shown in the figure:


This form is used for testing purposes, the actual interface can be complex, where the textbox is prepared for the variables of the report. The value that is filled in here is the variable to pass to the report, that is, the variable with the $p{} symbol defined in the first section, the program will match them. The Click event code for the button is as follows:

/**

* The Rptdialog dialog box is used to host the display of the report.

* @param E

*/

void Jbutton1_actionperformed (ActionEvent e) {

Please create a dialog box class Rptdialog

Rptdialog dlg = new Rptdialog (This.jGroupID.getText ());

Dimension dlgsize = Dlg.getpreferredsize ();

Dimension frmsize = GetSize ();

Point loc = GetLocation ();

Dlg.setlocation ((frmsize.width-dlgsize.width)/2 + loc.x,

(frmsize.height-dlgsize.height)/2 + loc.y);

Dlg.setmodal (TRUE);

Dlg.pack ();

Dlg.show ();

}

Rptdialog is the next dialog object created by JBuilder to create a new dialog object and name Rptdialog. The code for Rptdialog is as follows:

Import java.awt.*;

Import javax.swing.*;

Import dori.jasper.engine.*;

Import dori.jasper.view.*;

Import Dori.jasper.engine.util.JRLoader;

Import java.sql.Connection;

Import Java.io.File;

Import Java.util.Map;

Import Java.util.HashMap;

Import Mytest.trac.CommectionDB;

/**

* <p>title:rptdialog </p>

* <p>description: report hosting dialog Box </p>

* <p>copyright:copyright (c) 2004</p>

* <p>company: *****</p>

* @author Rick Hi

* @version 1.0

*/

public class Rptdialog extends JDialog {

JPanel Reportpan = new JPanel ();

BorderLayout borderLayout1 = new BorderLayout ();

Bug Project Name

String proname = "";

Display the controls that the report needs

Jrviewer Jrview;

Public Rptdialog (String GroupID) {

Proname = GroupID;

try {

Jbinit ();

Pack ();

}

catch (Exception ex) {

Ex.printstacktrace ();

}

}

private void Jbinit () throws Exception {

Reportpan.setlayout (BORDERLAYOUT1);

Getcontentpane (). Add (Reportpan);

Load the report, create a Reports folder in the directory of the JBuilder project, and shelve the report's Jasper file in the folder.

String Reportpath = System.getproperty ("User.dir") + "//reports//bugsrpt.jasper";

Jasperreport Jasperreport =

(Jasperreport) Jrloader.loadobjectfromlocation (Reportpath);

Create a connection to the database, reference Java JDBC Programming material to create the connection method

Commectiondb conndb = new Commectiondb ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.