1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. 怎么用JFreeReport做報表實踐

        時間:2024-08-19 05:57:00 JAVA認證 我要投稿
        • 相關推薦

        怎么用JFreeReport做報表實踐

          準備工作:

          下載jfreeReport0.8.7 地址:http://www.jfree.org/jfreereport/index.php

          Java認證:用JFreeReport做報表實踐,使用JFreeReport生成報表通常需要以下三個基本步驟:

          A.生成可通過TableModel接口訪問的數據,如本例中的createData方法完成的功能。

          B.生成一個JFreeReport實例,他定義了我們如何格式化顯示數據,如本例中的createReportDefinition方法完成的功能。

          C.將數據和JFreeReport實例連接起來,并且將該JFreeReport實例傳給PreviewDialog的一個實例顯示給用戶。

          下面開始:

          1.新建一個WEB工程,在WebRoot\lib中import 如下jar文件:jcommon-1.0.1.jar jfreereport-0.8.7.jar jfreereport-demo-0.8.7.jar jfreereport-servlet-demo-0.8.7.jar

          (可在jfreereport包中解壓得到)

          2.寫一個Demo.java 加入到工程的src包中。 內容如下:

          import java.awt.Color;

          import java.awt.geom.Point2D;

          import javax.swing.table.DefaultTableModel;

          import javax.swing.table.TableModel;

          import org.jfree.report.ElementAlignment;

          import org.jfree.report.JFreeReport;

          import org.jfree.report.JFreeReportBoot;

          import org.jfree.report.ReportProcessingException;

          import org.jfree.report.demo.helper.DefaultCloseHandler;

          import org.jfree.report.demo.helper.DemoHandler;

          import org.jfree.report.demo.helper.PreviewHandler;

          import org.jfree.report.elementfactory.TextFieldElementFactory;

          import org.jfree.report.modules.gui.base.PreviewDialog;

          import org.jfree.ui.FloatDimension;

          import org.jfree.util.Log;

          public class Demo implements DemoHandler

          {

          private class HelloWorldPreviewHandler implements PreviewHandler

          {

          public HelloWorldPreviewHandler()

          {

          }

          public void attemptPreview()

          {

          executeReport();

          }

          }

          public Demo (){

          }

          protected void executeReport ()

          {

          final TableModel data = createData();

          final JFreeReport report = createReportDefinition();

          report.setData(data);

          try

          {

          final PreviewDialog preview = new PreviewDialog(report);

          preview.addWindowListener(new DefaultCloseHandler());

          preview.pack();

          preview.setVisible(true);

          }

          catch (ReportProcessingException e)

          {

          Log.error(“Failed to generate report ”, e);

          }

          }

          private TableModel createData ()

          {

          final Object[] columnNames = new String[]{“Column1”, “Column2”};

          final DefaultTableModel result = new DefaultTableModel(columnNames, 101);

          for (int i=1;i《101;i++){

          result.setValueAt(“用繁體字寫幾個看看\n”, i, 0);

          result.setValueAt(“簡體中文輸出第”+i+“次”, i, 1);

          }

          return result;

          }

          private JFreeReport createReportDefinition ()

          {

          final JFreeReport report = new JFreeReport();

          report.setName(getDescription());

          TextFieldElementFactory factory = new TextFieldElementFactory();

          factory.setName(“T1”);

          factory.setAbsolutePosition(new Point2D.Float(0, 0));

          factory.setMinimumSize(new FloatDimension(150, 12));

          factory.setColor(Color.black);

          factory.setHorizontalAlignment(ElementAlignment.RIGHT);

          factory.setVerticalAlignment(ElementAlignment.MIDDLE);

          factory.setNullString(“-”);

          factory.setFieldname(“Column1”);

          report.getItemBand()。addElement(factory.createElement());

          factory = new TextFieldElementFactory();

          factory.setName(“T2”);

          factory.setAbsolutePosition(new Point2D.Float(200, 0));

          factory.setMinimumSize(new FloatDimension(150, 12));

          factory.setColor(Color.black);

          factory.setHorizontalAlignment(ElementAlignment.LEFT);

          factory.setVerticalAlignment(ElementAlignment.MIDDLE);

          factory.setNullString(“-”);

          factory.setFieldname(“Column2”);

          report.getItemBand()。addElement(factory.createElement());

          return report;

          }

          protected String getDescription ()

          {

          return “A Very Simple Report”;

          }

          public String getDemoName()

          {

          return “Hello World Demo (External)”;

          }

          public PreviewHandler getPreviewHandler()

          {

          return new HelloWorldPreviewHandler();

          }

          public static void main (final String[] args)

          {

          JFreeReportBoot.getInstance()。start();

          new Demo()。executeReport();

          }

          }

          3.在eclipse 中運行(Shift+Alt+X J)運行出來了。 仍有錯誤或警告。下面來消除它們。

          4.Exception in thread “export-worker——1” java.lang.NoClassDefFoundError: org/jfree/fonts/registry/FontRecord === 解決辦法是 import libfonts-0.1.4.jar

          5.WARN: Unable to initialize the module misc-bsf

          org.jfree.base.modules.ModuleInitializeException: Unable to load the bean scripting framework manager class. This class is required to execute the BSFExpressions. === 解決辦法是 import bsf-2.3.0.jar

          6.WARN: Unable to initialize the module misc-beanshellorg.jfree.base.modules.ModuleInitializeException: Unable to load the bean shell interpreter class. This class is required to execute the BeanShellExpressions. === 解決辦法是 import bsh-1.3.0.jar

          7.WARN: Unable to load module classes for parser-simple:org/jfree/xml/parser/AbstractXmlReadHandler

          WARN:Unable to load module classes for parser-ext:org/jfree/xml/parser/AbstractXmlReadHandler

          === 解決辦法是 import jcommon-xml-1.0.1.jar

          8.最終出現:

          INFO:Registering fonts for the iText library; using a cached font registry.

          INFO:Completed font registration.

          INFO:setReport(……): started pagination .……

          OK,一切順利完成。

          9.總之最后的WebRoot\lib中一共引入了

          bsf-2.3.0.jar bsh-1.3.0.jar itext-1.3.6.jar jcommon-1.0.1.jar jfreereport-0.8.7.jar jfreereport-demo-0.8.7.jar jfreereport-servlet-demo-0.8.7.jar

          libfonts-0.1.4.jar poi-3.0-alpha1-20050704.jar

          這些JAR文件。

        【怎么用JFreeReport做報表實踐】相關文章:

        hr工作報表怎么做03-08

        怎么做冰淇淋03-12

        眉筆怎么用03-29

        面膜怎么用02-27

        丹麥面包怎么做02-14

        香蕉奶昔怎么做03-13

        意大利面怎么做03-14

        酸奶蛋糕怎么做03-12

        夏日冷飲怎么做03-11

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>