Part II: Develop fat client report applications using JasperReport as a report control

xiaoxiao2021-03-06  70

Tip: In some sectors, the pictures in the article can not see, it is recommended to browse my blog: http://blog.9cbs.net/jemlee2002/ The article will involve 3 aspects:

Part 1: Use the IREPORT to make a detailed process (in the Windows environment)

Part II: Develop fat client report applications using JasperReport as a report control

Part III: Develop Web Report Applications using JasperReport as a report control

1,

Overview

We make a brief memory for the first part, the first part mainly introduces how to use iReport how to make a data report, I think the article is more detailed in detail "how to appear from zero to satisfaction". " However, there is no content involving JasperReport, the purpose is to make you purely understand how to do reports, because you can make a report and embed the report to application programming, which is easy to integrate.

We know that Ireport is a JasperReport's front-end development tool, Ireport is used to make and preview reports, providing adequate front-end support for application usage reports. Now how JasperReport works, so you can better understand how Ireport helps JasperReport to achieve the front-end work, in fact, these work is "dirty", why? Take a look at the information below.

You probably understand the working principle of JasperReport. The first is to have an XML file (usually in a JRXML suffix), then this XML file is there? What is it used? This XML file is the definition file of the report. Every detail of the entire report is defined in this XML file. There are hundreds of lines of XML files, you can manually edit this XML file (a line, a paragraph Edit - this is the so-called "dirty"). If it is hand-made this XML file, it is not allowed to consider efficiency, especially the development time of many application systems becomes more and more tense, and will always be issued in time. The best way to save time is to fully utilize automation tools, James Martin's software engineering thinking is also an automation of repeated emphasis, how to automate? It is a full use of automation tools to integrate into the development process, saying that a big pile is not to say to Ireport to do a report! This is our first part of the work that has been completed, but it is important to understand the working principle of JasperReport.

2, combined with JBuilder to develop fat client report applications

2.1 to establish an Application

Refer to JBuilder information. As long as it is an ordinary WINDOW window application.

2.2, introducing the library file required by JasperReports

Through JBuilder9 [Tool] - [Configure Libraries] - press the leftmost [New] - Enter a name, such as the Report- [Add] button, navigate to the lib directory of Ireport, introduced all files in the lib directory. Figure:

Press twice ok to return to the development interface of JBuilder.

2.3, add a Report Series Library file to the project

By right-clicking on the project, select [Properties] - [Paths] Label- [Required Libraries] Label- [Add] button - Select "Report" - Press OK to return to the JBuilder's development interface twice. This adds to the required library files. This is ideal, but all JAR files under LIB of Ireport may not be required when the report is run.

2.4, add the required components on the main interface

Add a Button and a Label and a Textbox in the main frame, of course, you can also connect by creating a menu, as shown: This form is used for testing, the actual interface may be complicated, where TextBox is reported The variable is prepared. The value fill in here is to pass the variable to the report, that is, the first part defined a variable with $ p {} symbol, the program will correspond to them. Button's click event code is as follows:

/ **

* The RPTDialog dialog is used to host the report.

* @Param E

* /

Void JButton1_ActionPerformed (ActionEvent E) {

/ / Please create a dialog box 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 a Dialog object that is made next, and creates a Dialog object through JBuilder and name RPTDialog. The code of 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;

/ **

*

Title: RPTDIALOG

*

Description: Report Carrier Dialog

*

Copyright: Copyright (C) 2004

*

company: *****

* @Author Li Kexi

* @version 1.0

* /

Public class rptdialog extends jdialog {

JPanel Reportpan = New jPanel ();

BorderLayout BorderLayout1 = New BorderLayout ();

// bug project name

String proname = "";

/ / Show the control required by the report

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); // loads a report, creates a Reports folder in the Directory of the JBuilder Engineering and puts the Jasper file of the report in this folder.

String reportPath = System.getProperty ("User.dir") "// Reports // Bugsrpt.jasper";

JasperReport JasperReport =

(JASPERREPORT) JRLOADER.LOADOBJECTFROMLOCATION (REPORTPATH);

// Create a connection to the database, refer to Java's JDBC programming data creation connection method

CommectionDB condb = new commectionDB ();

// Note: This connection requires the connection to the connection when making a report

Connection conn = connDb.getdbconnection ();

// Report configuration parameters, the WHERE condition parameters of the SQL statement mentioned above are corresponding to here. // The value of the condition may be obtained in a variety of ways, such as the last page passed.

Map parameters = new hashmap ();

// Projectname is the name of Ireport's variable $ p {projectname}, referring to the first part 5.6 Add parameters and use of the PRONAME is the value obtained from the interface.

Parameters.put ("ProjectName", Proname;

JasperPrint JasperPrint =

JasperfillManager.FillReport

JasperReport,

Parameters,

conn

);

// Loading process, pay attention to the red body part

JRVIEW = New Dori.jasper.view.jrviewer (JasperPrint);

Reportpan.setLayout (BorderLayout1);

Reportpan.SetPreferredSize (New Dimension (800, 600));

GetContentPane (). add (reportpan, borderlayout.center);

Reportpan.Add (JRVIEW, NULL);

}

}

Here, all work that requires settings and programming is basically completed.

3,

run

Determine the database has been launched and run the application in JBuilder. In the Textbox input, a meaningful group value, such as "Bugwin System", this is my test value, the actual situation is determined according to your needs. Click Button, the system will pop up the dialog, run the results, and the first part 6.2, and the preview report results are the same.

4,

to sum up

With the advancement of technology, the application environment is constantly changing, the application of fat clients may gradually exit mainstream, but its existence is necessary. So I want to write the application technology of the application of fat client. The text briefly introduced how to use the JasperReport programming report program. I hope to have a little help you.

转载请注明原文地址:https://www.9cbs.com/read-109586.html

New Post(0)