发展部件技术分享 http://blog.sciencenet.cn/u/求新 研究方向:数据库、MIS,教育部教指委计算机分委会专家工作组成员

博文

管理信息系统软件生产线源码98-100

已有 1938 次阅读 2018-7-9 21:20 |个人分类:生活点滴|系统分类:科研笔记| 软件生产线, 软部件, 数据库, 管理信息系统, JAVA

 版本1

98.源码98,部件程序,生成带统计图表格的数据报表格式文件。该报表针对数据表的每条记录所指定的若干数字数据类型字段数据生成直方图,形象地比较一条记录中各字段数据大小关系及相关记录中这些字段数据关系。

/*

 * 程序文件名:statisticalChart1.java

 * 作者:程学先

 * 功能:生成带统计图表格的数据报表格式文件。

 * 该报表针对数据表的每条记录所指定的若干数字数据类型字段数据生成直方图,

 * 形象地比较一条记录中各字段数据大小关系。

 * 每条记录的数据组成一组,总组数等于记录条数,

 * 必须输入的参数:表名。

 * 格式文件格式:

 * 第一行数据为:标题[]:(表格标题,字体,字号,统计图标题,字体字号,记录条数、记录列数),

 * 第二行数据为:表格字段名[],限数字数据类型字段的字段名。

 * 第三行以后为:每列宽度,将自动根据字段宽度与字号填入文本框,可手工修改宽度。

 * 第四行数据为:图的记录分组字段名、标识字段名和数据字段名

 * 第五行数据为:统计图宽度、高度、统计函数类型。

 * 在输入数据时请顺次输入,在存盘后可以预览报表摸样。

  */

import java.awt.*;

import java.awt.event.*;

 

import javax.swing.*;

 

import java.io.*;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

public class printFormat3 extends JFrame {

    private static printFormat3 frame1 = new printFormat3();      //定义窗口

    private static JPanel panel1 = new JPanel();      //定义面板

    private static List list1 = new List();

    private static JLabel fl0,fl1,fl2,fl3,fl4,fl10;

    private static JTextField fa0,fa1,fa2,fa3,fa4,fa10;

    private static JLabel fla0,fla1,fla2;

    private static JTextField faa0,faa1,faa2;

   private static JLabel flb0,flb1,flb2;

    private static JTextField fab0,fab1,fab2;

    private static JLabel flc2,flc3,flc4,flc5,flc6;

    private static JTextField fac2,fac3,fac4,fac5,fac6;

    private static String 当前值;

    private static int 选中行号=-1,当前行号=0,表格行数=0,当前列号=0,列数=0;

    private static int 字段序号=0,记录条数=0;

    private static String[][] 表格数据=null;

    private static String[][] 表格数据1=null;

    private static ArrayList<String> 读入数据 = new ArrayList();

    private static String[] 列名1;

    private static String[] 图表;

    private static String[] 列数据类型;

    private static int[] 列数据宽度;

    private static String[] 一行数据=new String[12];

    private static int[] 一行数据1=new int[12];

    private static File file1;

    private static FileReader fr;

   static Connection con; 

   private static Statement sta;     //连接数据库

   static String s1="",s2="";   

   private static ResultSet rs; 

   private static ResultSetMetaData rsmd;

   private static ArrayList 表名1=new ArrayList();

   private static String [] 字号={"5","6","7","8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"};

   private static String [] 字体={"宋体","楷体","黑体","仿宋_GB2312"};

   private static String [] 类型={"柱形图","饼形图","折线图"};

   private static int 窗口宽=main1.窗口宽;

   private static String 数据表名;

   private static String 连接条件 = "";

   private static String 字段名表 = "";

 

    static void means(String [] parameter){

      frame1 = new printFormat3();      //定义窗口

      panel1 = new JPanel();      //定义面板

      list1 = new List();

      选中行号=-1;当前行号=0;表格行数=0;当前列号=0;列数=0;

      字段序号=0;记录条数=0;

      读入数据 = new ArrayList();

      一行数据=new String[12];

      一行数据1=new int[12];

      s1="";s2="";   

      表名1=new ArrayList();

      字号=new String[19];

      字体= new String[4];

      字号[0]="5";字号[1]="6";字号[2]="7";字号[3]="8";

      字号[4]="9";字号[5]="10";字号[6]="11";字号[7]="12";

      字号[8]="14";字号[9]="16";字号[10]="18";字号[11]="20";

      字号[12]="22";字号[13]="24";字号[14]="26";字号[15]="28";

      字号[16]="36";字号[17]="48";字号[18]="72";

      字体[0]="宋体";字体[1]="楷体";字体[2]="黑体";

      字体[3]="仿宋_GB2312";

     frame1.setTitle("图表类报表打印格式设计与打印程序。                       作者:程学先");

        frame1.setBounds(10, 10, 900, 580);    //窗口位置大小

        frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 设置窗体的默认关闭模式

        panel1.setBounds(10, 10, 880, 570);      //定义面板大小与位置

        panel1.setLayout(null);        //关闭面板布局管理器

        String[] 列名01  = { "标签名", "字段名", "宽度", "字体", "字号"};

        main1.driver1();

        数据表名=parameter[4] ;

        数据表查询结构(数据表名);

        fl10=new JLabel("文件名");

        fl10.setBounds(30,30,50, 20);

        panel1.add(fl10); 

        fa10 = new JTextField("",20); 

        fa10.setBounds(80,30, 620, 20);

        panel1.add(fa10);      

        fa10.addMouseListener(new MouseAdapter() {

     public void mouseClicked(MouseEvent e) {

         图表=new String[37];

         if (fa10.getText().length()<1){      

            final JFileChooser fc = new JFileChooser(".\\"); 

          fc.showOpenDialog(null);    //读取文件名

           if (fc.getSelectedFile()!=null) { 

             fa10.setText(fc.getSelectedFile().toString());

                file1 = new File(fa10.getText());

               try{   

                  if ((fa10.getText().length()>0)&&(file1.exists())) {   //如果文件存在

                      fr = new FileReader(file1);

                   BufferedReader br = new BufferedReader(fr);

                   String tempStr = null;

                   int y=0,b=0;

                  for (int i = 0; (tempStr = br.readLine()) != null; i++){//读文件

                    图表[i]=tempStr;

                    y=i;

                  }

                  if (y>=16) {

                   if (y>=0) faa0.setText(图表[0]);

                  if (y>=1) faa1.setText(图表[1]);

                  if (y>=2) faa2.setText(图表[2]);

                  if (y>=3) fa0.setText(图表[3]);

                  if (y>=4) fa1.setText(图表[4]);

                  if (y>=5) fa2.setText(图表[5]);

                  if (y>=6) fa3.setText(图表[6]);

                  if (y>=7) fab0.setText(图表[7]);

                  if (y>=8) fab1.setText(图表[8]);

                  if (y>=9) fab2.setText(图表[9]);

                  if (y>=10) fa4.setText(图表[10]);

                  if (y>=12) fac2.setText(图表[12]);

                  if (y>=13) fac3.setText(图表[13]);

                  if (y>=14) fac4.setText(图表[14]);

                  if (y>=15) fac5.setText(图表[15]);

                  if (y>=16) fac6.setText(图表[16]);

                  }

                 }

                 else {

                     if (fa10.getText().length()>0)

                          file1.createNewFile();// 创建文件

                       }

                    }catch(IOException e2) {   

                   JOptionPane.showMessageDialog( null, "打开文件错!");

               }

             }

         }

         }

        });

 

        fla0=new JLabel("表格标题");

        fla0.setBounds(30,70,80, 20);

         panel1.add(fla0); 

         faa0 = new JTextField("",20); 

         faa0.setBounds(110,70, 310, 20);

         panel1.add(faa0);      

         faa0.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=0;    

                    list1.removeAll();

             }

        });

         fla1=new JLabel("表题字体");

         fla1.setBounds(430,70,60, 20);

          panel1.add(fla1); 

          faa1 = new JTextField("",20); 

          faa1.setBounds(490,70, 60, 20);

          panel1.add(faa1);      

          faa1.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=1;    

                    list1.removeAll();

                    for (int i=0;i<字体.length;i++){

                       list1.add(字体[i]);

                    }

             }

         });

          fla2=new JLabel("表题字号");

          fla2.setBounds(560,70,70, 20);

           panel1.add(fla2); 

           faa2 = new JTextField("",20); 

           faa2.setBounds(630,70, 70, 20);

           panel1.add(faa2);      

           faa2.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=2;    

                    list1.removeAll();

                    for (int i=0;i<字号.length;i++){

                       list1.add(字号[i]);

                    }

              }

          });

 

           fl2=new JLabel("数据字体");

           panel1.add(fl2); 

           fa2 = new JTextField("",20); 

           panel1.add(fa2);      

           fl2.setBounds(30,110,70, 20);

           fa2.setBounds(100,110, 120, 20);

           fa2.addFocusListener(new FocusAdapter() {   

                public void focusGained(final FocusEvent arg0) {

                       当前列号=5;    

                       list1.removeAll();

                       for (int i=0;i<字体.length;i++){

                          list1.add(字体[i]);

                       }

                }

           });

 

           fl3=new JLabel("数据字号");

           panel1.add(fl3); 

           fa3 = new JTextField("",20); 

           panel1.add(fa3);      

           fl3.setBounds(230,110,70, 20);

           fa3.setBounds(300,110,110, 20);

           fa3.addFocusListener(new FocusAdapter() {   

                public void focusGained(final FocusEvent arg0) {

                       当前列号=6;    

                       list1.removeAll();

                          for (int i=0;i<字号.length;i++){

                             list1.add(字号[i]);

                          }

                       }

           });

        fl0=new JLabel("报表字段名(逗号分隔)");

        fl0.setBounds(30,140,400, 20);

         panel1.add(fl0); 

         fa0 = new JTextField("",20); 

         fa0.setBounds(30,160,470, 20);

         panel1.add(fa0);      

         fa0.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=3;    

                    list1.removeAll();

                           for (int i=0;i<列数;i++) {

                               list1.add(列名1[i]);

                           }

             }

        });

 

         fl4=new JLabel("非数字数据类型字段名(关键字)");

         fl4.setBounds(500,140,200, 20);

          panel1.add(fl4); 

          fa4 = new JTextField("",20); 

          fa4.setBounds(500,160,200, 20);

          panel1.add(fa4);      

          fa4.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=11;    

                    list1.removeAll();

                           for (int i=0;i<列数;i++) {

                               list1.add(列名1[i]);

                           }

             }

         });

 

          fl1=new JLabel("宽度(逗号分隔)");

        fl1.setBounds(30,190,140, 20);

         panel1.add(fl1); 

         fa1 = new JTextField("",20); 

         fa1.setBounds(30,210, 670, 20);

         panel1.add(fa1);      

         fa1.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=4;    

                    list1.removeAll();

             }

        });

        

       flb0=new JLabel("统计图标题");

       flb0.setBounds(30,260,80, 20);

        panel1.add(flb0); 

        fab0 = new JTextField("",20); 

        fab0.setBounds(110,260, 300, 20);

        panel1.add(fab0);      

        fab0.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=7;    

                    list1.removeAll();

             }

       });

        flb1=new JLabel("图题字体");

        flb1.setBounds(420,260,70, 20);

         panel1.add(flb1); 

         fab1 = new JTextField("",20); 

         fab1.setBounds(490,260, 60, 20);

         panel1.add(fab1);      

         fab1.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=8;    

                    list1.removeAll();

                    for (int i=0;i<字体.length;i++){

                       list1.add(字体[i]);

                    }

             }

        });

         flb2=new JLabel("图题字号");

         flb2.setBounds(560,260,70, 20);

          panel1.add(flb2); 

          fab2 = new JTextField("",20); 

          fab2.setBounds(630,260, 70, 20);

          panel1.add(fab2);      

          fab2.addFocusListener(new FocusAdapter() {   

             public void focusGained(final FocusEvent arg0) {

                    当前列号=9;    

                    list1.removeAll();

                    for (int i=0;i<字号.length;i++){

                       list1.add(字号[i]);

                    }

             }

         });

           flc2=new JLabel("图形数据字段名(Y轴数据名)");

            flc2.setBounds(450,300,200, 20);

             panel1.add(flc2); 

             fac2 = new JTextField("",20); 

             fac2.setBounds(450,330,200, 20);

             panel1.add(fac2);      

             fac2.addFocusListener(new FocusAdapter() {   

                public void focusGained(final FocusEvent arg0) {

                       当前列号=12;    

                       list1.removeAll();

                              for (int i=0;i<列数;i++) {

                                  list1.add(列名1[i]);

                              }

                }

            });

             flc3=new JLabel("图形类型");

             flc3.setBounds(30,370,70, 20);

              panel1.add(flc3); 

              fac3 = new JTextField("",20); 

              fac3.setBounds(100,370,70, 20);

              panel1.add(fac3);      

              fac3.addFocusListener(new FocusAdapter() {   

                public void focusGained(final FocusEvent arg0) {

                       当前列号=13;    

                       list1.removeAll();

                              for (int i=0;i<类型.length;i++) {

                                  list1.add(类型[i]);

                              }

                }

             });

              flc4=new JLabel("图形宽度");

              flc4.setBounds(180,370,60, 20);

               panel1.add(flc4); 

               fac4 = new JTextField("",20); 

               fac4.setBounds(240,370,70, 20);

               panel1.add(fac4);      

               fac4.addFocusListener(new FocusAdapter() {   

                 public void focusGained(final FocusEvent arg0) {

                   当前列号=14;    

                   list1.removeAll();

                   String sk[]=fa1.getText().split(",");

                    int wh4=0;

                   for (int i=0;i<sk.length;i++)

                     wh4=wh4+Integer.parseInt(sk[i]);

                   fac4.setText(wh4+"");

                   }

              });

               flc5=new JLabel("图形高度");

               flc5.setBounds(320,370,60, 20);

                panel1.add(flc5); 

                fac5 = new JTextField("",20); 

                fac5.setBounds(380,370,70, 20);

                panel1.add(fac5);      

                fac5.addFocusListener(new FocusAdapter() {   

                   public void focusGained(final FocusEvent arg0) {

                     当前列号=15;    

                     list1.removeAll();

                      int wh4=0;

                      if ((faa2.getText().length()>0)&&(faa2.getText().compareTo("0")>0))

                        wh4=Integer.parseInt(faa2.getText());//表标题字号

                      if ((fa3.getText().length()>0)&&(fa3.getText().compareTo("0")>0))

                      wh4=wh4+记录条数*Integer.parseInt(fa3.getText());  //表格高度

                      else wh4=wh4+记录条数*20;

                      if ((fab2.getText().length()>0)&&(fab2.getText().compareTo("0")>0))

                        wh4=wh4+Integer.parseInt(fab2.getText());  //图标题字号

                      wh4=800-wh4;  //估计A4打印每页高度为800象素点

                  fac5.setText(wh4+"");

                 }

               });

                flc6=new JLabel("统计函数序号");

                flc6.setBounds(460,370,100, 20);

                 panel1.add(flc6); 

                 fac6 = new JTextField("",20); 

                 fac6.setBounds(560,370, 120, 20);

                 panel1.add(fac6);      

                 fac6.addFocusListener(new FocusAdapter() {   

                   public void focusGained(final FocusEvent arg0) {

                     当前列号=16;    

                     list1.removeAll();

                     list1.add("按记录");

                     list1.add("分组求和");

                     list1.add("分组平均");

                   }

                });

        list1.setBounds(730, 30,120,410); 

        panel1.add(list1);

        list1.addMouseListener(new MouseAdapter() {

           public void mouseClicked(MouseEvent e) {

            int w1=0,w2=0;

            if (list1.getSelectedIndex()>=0){

               int wh1,wh2,h1,h2;

             String s0="",s6="";

             switch (当前列号) {

             case 0: // 表名

                if (fa0.getText().length()==0)

                    s0=list1.getSelectedItem();

                else s0=fa0.getText()+","+list1.getSelectedItem();

                fa0.setText(s0);

                数据表查询结构(s0);

                break;

                  case 1:   

                     faa1.setText(list1.getSelectedItem());

                    break;

                  case 2:   

                    faa2.setText(list1.getSelectedItem());

                    break;

                  case 3:

                    wh1=list1.getSelectedIndex();

                    wh2=列数据宽度[wh1];

                    s6=list1.getSelectedItem();

                    if (列名1[wh1].length()>wh2)

                       wh2=列名1[wh1].length();

                    if (fa3.getText().length()>0)

                       wh2=wh2*Integer.parseInt(fa3.getText());

                    else wh2=wh2*12;

                    if (fa0.getText().length()==0){

                    fa0.setText(s6);

                    fa1.setText(wh2+"");

                    }

                    else{

                    fa0.setText(fa0.getText()+","+s6);

                    fa1.setText(fa1.getText()+","+wh2);

                    }

                    if (main1.数字数据类型.indexOf(","+列数据类型[wh1]+",")<0)

                       if ((fa4.getText().length()==0))

                          fa4.setText(s6);

                       else

                          fa4.setText(fa4.getText()+","+s6);

                    break;

                  case 5:   

                    fa2.setText(list1.getSelectedItem());

                    break;

                  case 6:   

                    fa3.setText(list1.getSelectedItem());

                    break;

                  case 8:   

                    fab1.setText(list1.getSelectedItem());

                    break;

                  case 9:   

                    fab2.setText(list1.getSelectedItem());

                    break;

                  case 11:

                    wh1=list1.getSelectedIndex();

                    s6=list1.getSelectedItem();

                    wh2=列数据宽度[wh1];

                    if (列名1[wh1].length()>wh2)

                       wh2=列名1[wh1].length();

                    if (fa3.getText().length()>0)   //乘字号

                       wh2=wh2*Integer.parseInt(fa3.getText());

                    else wh2=wh2*12;

                    if ((fa4.getText().length()==0))

                          fa4.setText(s6);

                    else

                          fa4.setText(fa4.getText()+","+s6);

                    if ((","+fa0.getText()+",").indexOf(","+s6+",")<0){

                       if (fa0.getText().length()==0){

                          fa0.setText(s6);

                          fa1.setText(wh2+"");

                       }

                       else {

                          fa0.setText(s6+","+fa0.getText());

                          fa1.setText(wh2+","+fa1.getText());

                       }

                    }

                    break;

                  case 12:   

                    fac2.setText(list1.getSelectedItem());

                    break;

                  case 13:   

                    fac3.setText(list1.getSelectedIndex()+"");

                    break;

                  case 16:   

                    fac6.setText(list1.getSelectedIndex()+"");

                    break;

                }

            }

             }

        });

         final JButton creButton = new JButton("格式内容存盘"); 

        creButton.setBounds(30,440,170, 20);

        creButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) { 

            char x1=10,x2=13,x3='"',x4=','; 

                file1 = new File(fa10.getText());

             FileOutputStream fs;

             try{

             fs = new  FileOutputStream(file1);

               fs.write((faa0.getText()+x1).getBytes());

               fs.write((faa1.getText()+x1).getBytes());

               fs.write((faa2.getText()+x1).getBytes());

               fs.write((fa0.getText()+x1).getBytes());

               fs.write((fa1.getText()+x1).getBytes());

               fs.write((fa2.getText()+x1).getBytes());

               fs.write((fa3.getText()+x1).getBytes());

               fs.write((fab0.getText()+x1).getBytes());

               fs.write((fab1.getText()+x1).getBytes());

               fs.write((fab2.getText()+x1).getBytes());

               fs.write((fa4.getText()+x1).getBytes());   //关键字

               fs.write(("0"+x1).getBytes());

               fs.write((fac2.getText()+x1).getBytes());

               fs.write((fac3.getText()+x1).getBytes());

               fs.write((fac4.getText()+x1).getBytes());

               fs.write((fac5.getText()+x1).getBytes());

               fs.write((fac6.getText()+x1).getBytes());

             }catch(IOException e2) {

                   JOptionPane.showMessageDialog( null,"写文件错。");

             }

            }

        });

        panel1.add(creButton);    

 

        final JButton clearButton = new JButton("清参数文本框"); 

        clearButton.setBounds(200,440,170, 20);

        clearButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                fa1.setText("");fa2.setText("0");

               fa4.setText("0");

             }

        });

        panel1.add(clearButton);   

 

        final JButton printButton = new JButton("打印预览"); 

        printButton.setBounds(370,440,170, 20);

        printButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

            int c=0,b=0;

            try {

               con = main1.getConn();

               sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

                    ResultSet.CONCUR_UPDATABLE);

               s1 = "select " + fa0.getText() + "  from " + 数据表名 + 连接条件;

               rs = sta.executeQuery(s1);

               rsmd = rs.getMetaData();

               列数 = rsmd.getColumnCount();

               列名1 = new String[列数];

               列数据类型 = new String[列数];

               列数据宽度 = new int[列数];

               for (int i = 0; i < 列数; i++) {

                 列名1[i] = rsmd.getColumnName(i+1);

                 列数据类型[i] = rsmd.getColumnTypeName(i + 1);

                 列数据宽度[i] = rsmd.getColumnDisplaySize(i + 1);

               }

               rs.last();

               记录条数 = rs.getRow();

               表格数据 = new String[记录条数][列数];

               while (c < 记录条数) {

                 rs.absolute(c + 1);

                 while (b < 列数) {

                    表格数据[c][b] = rs.getString(b + 1);

                    b++;

                 }

                 c++;

                 b = 0;

               }

               rs.close();

               sta.close();

               con.close();

            } catch (SQLException e1) {

               JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

            }

           main1.n = 0; // 打印预览标志

           statisticalChart1.means(fa10.getText(), 表格数据);

            }

        });

        panel1.add(printButton);   

 

        final JButton exitButton = new JButton("退出"); 

        exitButton.setBounds(540,440,170, 20);

        exitButton.addActionListener(new ActionListener() { 

            public void actionPerformed(ActionEvent e) {

             panel1.setVisible(false);

             frame1.setVisible(false);

                 frame1.dispose();

          }

        });

        panel1.add(exitButton); 

        frame1.add(panel1); // 把面板添加到窗体

        frame1.setVisible(true);

 }

   static void 数据表查询结构(String 数据表名) {

     String[] s10 = null;

     String[] sk = new String[300];

     int n1 = 0, n2 = 0;

     字段名表 = "";

     连接条件 = "";

     if (数据表名.indexOf(",") < 0) { // 单表

        try {

           con = main1.getConn();

           sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

                ResultSet.CONCUR_UPDATABLE);

           String s1 = "select * from " + 数据表名;

           rs = sta.executeQuery(s1);

           rsmd = rs.getMetaData();

           列数 = rsmd.getColumnCount();

           列名1 = new String[列数];

           字段名表 = "";

           for (int i = 0; i < 列数; i++) {

             列名1[i] = rsmd.getColumnName(i + 1);

             sk[i] = 列名1[i];

             n1++;

             if (字段名表.length() == 0)

                字段名表 = 列名1[i];

             else

                字段名表 = 字段名表 + "," + 列名1[i];

           }

           rs.close();

           sta.close();

           con.close();

        } catch (SQLException e1) {

           JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

        }

     } else { // 多表

        s10 = 数据表名.split(",");

        String s0 = "", s1 = "", s2 = "";

        int k = 0;

        for (int i = 0; i < s10.length; i++) {

           try {

             con = main1.getConn();

             sta = con.createStatement(

                   ResultSet.TYPE_SCROLL_INSENSITIVE,

                   ResultSet.CONCUR_UPDATABLE);

             s1 = "select * from " + s10[i];

             rs = sta.executeQuery(s1);

             rsmd = rs.getMetaData();

             列数 = rsmd.getColumnCount();

             for (int j = 0; j < 列数; j++) { // 读取所有表的列名,同名的加表名

                s2 = rsmd.getColumnName(j + 1).toLowerCase(); // 列名

                n2 = n1;

                if (i > 0) { // 加入第2个表之后字段出现同名字段

                   k = 0;

                   for (int j1 = 0; j1 < n2; j1++) {

                      if (sk[j1].equals(s2)) {

                        sk[j1] = s10[i - 1] + "." + sk[j1];

                        if (连接条件.length() == 0) // 连接条件

                           连接条件 = " where " + s10[i - 1] + "."

                                + s2 + " = " + s10[i] + "."

                                + s2;

                        else

                           连接条件 = 连接条件 + " and " + s10[i - 1]

                                + "." + s2 + " = " + s10[i]

                                + "." + s2;

                        sk[n1] = s10[i] + "." + s2 + " as "

                              + (s2 + i);

                        n1++;

                        k = 1;

                        break;

                      }

                   }

                   if (k == 0) {

                      sk[n1] = s2;

                      n1++;

                   }

                } else {

                   sk[n1] = s2;

                   n1++;

                }

             }

             rs.close();

             sta.close();

             con.close();

           } catch (SQLException e1) {

             JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

           }

        }

        字段名表 = "";

        for (int j1 = 0; j1 < n1; j1++)

           if (字段名表.length() == 0)

             字段名表 = sk[j1];

           else

             字段名表 = 字段名表 + "," + sk[j1];

     }

     int c=0,b=0;

     try {

        con = main1.getConn();

        sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

             ResultSet.CONCUR_UPDATABLE);

        s1 = "select " + 字段名表 + "  from " + 数据表名 + 连接条件;

        rs = sta.executeQuery(s1);

        rsmd = rs.getMetaData();

        列数 = rsmd.getColumnCount();

        列名1 = new String[列数];

        列数据类型 = new String[列数];

        列数据宽度 = new int[列数];

        for (int i = 0; i < 列数; i++) {

           列名1[i] = sk[i];

           列数据类型[i] = rsmd.getColumnTypeName(i + 1);

           列数据宽度[i] = rsmd.getColumnDisplaySize(i + 1);

        }

        rs.last();

        记录条数 = rs.getRow();

        表格数据 = new String[记录条数][列数];

        while (c < 记录条数) {

           rs.absolute(c + 1);

           while (b < 列数) {

             表格数据[c][b] = rs.getString(b + 1);

             b++;

           }

           c++;

           b = 0;

        }

        rs.close();

        sta.close();

        con.close();

     } catch (SQLException e1) {

        JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

     }

   }

   }

99.源码99,部件程序,根据printFormat3.java生成的格式文件打印或打印预览带统计图表格的数据报表。首先打印数据表格,其中生成直方图统计图的为其中数字数据类型字段,可以为一个到多个。针对数据表的每条记录各字段数据生成直方图,形象地比较一条记录中各字段数据大小关系及相关记录中这些字段数据关系。

/**

 * 程序文件名:dataPreview6.java

 * 作者:程学先

 * 功能:根据printFormat3.java生成的格式文件打印或打印预览带统计图表格的数据报表。

 * 首先打印数据表格,其中生成直方图统计图的为其中数字数据类型字段,可以为一个到多个。

 * 将针对数据表的每条记录各字段数据生成直方图,形象地比较一条记录中各字段数据大小关系。

 * 每条记录的数据组成一组,总组数等于记录条数,

 * 记录条数如果超过20,显示的图形将过于密集,建议选择起始记录号,与打印记录条数,

 * 建议每次打印不超过20条记录(20组柱形图形)。

 * 数字类型数据之外建议字段数尽量少,所有非数字数据类型字段共同称为关键字,

 * 必须输入的参数:表名、关键字、打印格式文件名。

 * 完成时间:20131127

 * 调用语句:dataPreview6.means(parameter);

 * 本程序需要调用公共程序:statisticalChart1.java完成报表打印或预览。

 */

import java.awt.BasicStroke;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import javax.swing.JButton;

import javax.swing.JComponent;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

 

public class dataPreview6 extends JComponent {

   private static JFrame frame1;

   static Connection con;

   private static ResultSetMetaData rsmd;

   private static Statement sta; // 连接数据库

   private static Connection cont4;

   private static Statement stat4;

   private static ResultSetMetaData rsmdt4;

   private static ResultSet rs;

   private static String 表名;

   private static String s1 = "";

   static int 最大值 = 0, 最小值 = 0, 纵向分段数 = 20;

   private static int 记录条数 = 0, 列数 = 0, 记录号 = 0;

   private static String[] 列名;

   private static String[] 数据列名;

   private static String[] 列数据类型;

   private static int[] 列数据宽度;

   private static String[][] 表格数据;

   private static String[] 标签数据;

   static String[] 关键字;

   static int[] 关键字序号;

   static int[][] 交叉数据2;

   static int[] 交叉数据1;

   static int 窗口宽度 = 1000, 窗口高度 = 600;

   static int 标签左边 = 100, 标签到顶 = 窗口高度;

   private static ArrayList<struct1> title = new ArrayList<struct1>();

   private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();

   private static ArrayList<struct3> table1 = new ArrayList<struct3>();

   private static ArrayList<struct4> table2 = new ArrayList<struct4>();

   private static int 页高 = 600;

   private static int x1 = 0, y1 = 0, w1 = 0, h1 = 0, 左边 = 0, 到顶 = 0;

   private static int 图顶点 = 0;

   private static Graphics2D g2;

   private static Graphics g;

   private static String faa0, faa1, faa2;

   private static String fab0, fab1, fab2;

   private static String fac0, fac1, fac2, fac3, fac4, fac5, fac6;

   private static String fa0, fa1,fa2,fa3,fa10;

   private static String[][] 表格数据1 = null;

   private static String 数据表名;

   private static String 连接条件;

   private static String 字段名表 = "";

   private static String 打印格式文件名;

   private static String[] 图表;

   private static int 记录条数1;

   private static int 列数1; // 获取列数

   static void title() {

     struct2[] 标签 = new struct2[tableTitle.size()];

     左边 = Integer.valueOf(tableTitle.get(0).tableTitle[3]);

     左边 = 左边 / 2;

     for (int i = 0; i < tableTitle.size(); i++)

        标签[i] = tableTitle.get(i);

    g2.setFont(new Font(标签[0].tableTitle[6], Font.PLAIN, Integer

           .valueOf(标签[0].tableTitle[7])));// 设置字体

     for (int i = 0; i < tableTitle.size(); i++) {

        x1 = 左边;

        y1 = 到顶;

        w1 = Integer.valueOf(标签[i].tableTitle[3]);

        h1 = Integer.valueOf(标签[i].tableTitle[4]);

        g2.drawLine(x1, y1, x1 + w1, y1);

        g2.drawLine(x1, y1, x1, y1 + h1);

        g2.drawString(标签[i].tableTitle[0], 左边 + 2, 到顶 + h1);

        if (标签[i].tableTitle[8].equals(""))

           g2.drawLine(x1, y1 + h1, x1 + w1, y1 + h1);

        if (标签[i].tableTitle[9].equals(""))

           g2.drawLine(x1 + w1, y1, x1 + w1, y1 + h1);

        左边 = 左边 + w1;

        if ((i < tableTitle.size() - 1)

             && (Integer.valueOf(标签[i].tableTitle[1]) < Integer

                   .valueOf(标签[i + 1].tableTitle[1])))

           到顶 = 到顶 + h1;

     }

     到顶 = 到顶 + h1;

   }

 

   protected void paintComponent(Graphics g1) {

     g = g1;

     g2 = (Graphics2D) g;

     struct1[] 标题 = new struct1[title.size()];

     到顶 = 0;

     左边 = 0;

     for (int i = 0; i < title.size(); i++) {

        标题[i] = title.get(i);

        g2.setFont(new Font(标题[i].title[8], Font.PLAIN, Integer

             .valueOf(标题[i].title[9])));// 设置字体

        x1 = Integer.valueOf(标题[i].title[6]);

        y1 = Integer.valueOf(标题[i].title[7]);

        g2.drawString(标题[i].title[0], x1, y1);

        到顶 = y1 + Integer.valueOf(标题[i].title[5]);

     }

     title();

     struct3[] 表体 = new struct3[table1.size()];

     int[] w10 = new int[table1.size()];

     int[] h10 = new int[table1.size()];

     int[] h20 = new int[table1.size()];

     for (int i = 0; i < table1.size(); i++) {

        表体[i] = table1.get(i);

        w10[i] = Integer.valueOf(表体[i].table1[2]);

        h10[i] = Integer.valueOf(表体[i].table1[3]);

        h20[i] = Integer.valueOf(表体[i].table1[5]);

     }

     y1 = 到顶;

     g2.setFont(new Font(表体[0].table1[4], Font.PLAIN, Integer

           .valueOf(表体[0].table1[5])));// 设置字体

     for (int j = 0; j < 记录条数; j++) {

        x1 = Integer.valueOf(tableTitle.get(0).tableTitle[3]) / 2;

        g2.drawLine(x1, y1, x1, y1 + h1);

        for (int i = 0; i < table1.size(); i++) {

           if (表格数据[j][i] == null)

             表格数据[j][i] = " ";

           g2.drawString(表格数据[j][i], x1 + 2, y1 + h20[i]);

           g2.drawLine(x1, y1 + h10[i], x1 + w10[i], y1 + h10[i]);

           g2.drawLine(x1 + w10[i], y1, x1 + w10[i], y1 + h10[i]);

           x1 = x1 + w10[i];

        }

        y1 = y1 + h10[table1.size() - 1];

 

        if (y1 >= 页高) {

 

           struct4[] 页尾 = new struct4[table2.size()];

           for (int i1 = 0; i1 < table2.size(); i1++) {

             页尾[i1] = table2.get(i1);

             g2.setFont(new Font(页尾[i1].table2[8], Font.PLAIN, Integer

                   .valueOf(页尾[i1].table2[9])));// 设置字体

             x1 = Integer.valueOf(页尾[i1].table2[6]);

             y1 = Integer.valueOf(页尾[i1].table2[7]);

             g2.drawString(页尾[i1].table2[0], x1, y1);

             到顶 = y1 + Integer.valueOf(页尾[i1].table2[5]);

           }

           y1 = 640;

           break;

        }

     }

     y1 = y1 + h10[table1.size() - 1];

   }

   static void means(String[] parameter) {

     frame1 = new JFrame(); // 定义窗口

     frame1.setLayout(null);

     frame1.setTitle("图表式报表打印与打印预览程序                                                                                                                                                                                              作者:程学先");

     frame1.setBounds(10, 10, 1000, 660);

     frame1.getContentPane().setLayout(null);

     final JPanel panel1 = new JPanel(); // 定义面板

     panel1.setBounds(10, 10, 1000, 660);

     panel1.setLayout(null);

     frame1.getContentPane().add(panel1);

     表名 = parameter[4];

     连接条件 = parameter[20];

     打印格式文件名 = parameter[15];

     图表 = new String[37];

     if (打印格式文件名.length() < 1) {

        final JFileChooser fc = new JFileChooser(".\\");

        fc.showOpenDialog(null); // 读取文件名

        if (fc.getSelectedFile() != null) {

           打印格式文件名 = fc.getSelectedFile().toString();

        }

     }

     File file1 = new File(打印格式文件名);

     fa10 = 打印格式文件名;

     try {

        if ((打印格式文件名.length() > 0) && (file1.exists())) { // 如果文件存在

           FileReader fr = new FileReader(file1);

           BufferedReader br = new BufferedReader(fr);

           String tempStr = null;

           int y = 0, b = 0;

           for (int i = 0; (tempStr = br.readLine()) != null; i++) {// 读文件

             图表[i] = tempStr;

             y = i;

           }

           if (y >= 16) {

             if (y >= 0)

                faa0 = 图表[0];

             if (y >= 1)

                faa1 = 图表[1];

             if (y >= 2)

                faa2 = 图表[2];

             if (y >= 3)

                fa0 = 图表[3];

             if (y >= 4)

                fa1 = 图表[4];

             if (y >= 5)

                fa2 = 图表[5];

             if (y >= 6)

                fa3 = 图表[6];

             if (y >= 7)

                fab0 = 图表[7];

             if (y >= 8)

                fab1 = 图表[8];

             if (y >= 9)

                fab2 = 图表[9];

             if (y >= 10){

                关键字=图表[10].split(",");

                关键字序号=new int[关键字.length];

             }

             if (y >= 11)

                fac1 = 图表[11];

             if (y >= 12)

                fac2 = 图表[12];

             if (y >= 13)

                fac3 = 图表[13];

             if (y >= 14)

                fac4 = 图表[14];

             if (y >= 15)

                fac5 = 图表[15];

             if (y >= 16)

                fac6 = 图表[16];

           }

        }

     } catch (IOException e2) {

        JOptionPane.showMessageDialog(null, "打开文件错!");

     }

     字段名表 = fa0;

     数据表名 = 表名;

     数据表查询结构(表名);

     数据表查询数据(表名);

 

     final JButton inButton = new JButton("预览图表");

     inButton.setBounds(340, 520, 170, 20);

     inButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           String [] s7=new String[记录条数];

           String [] s6=new String[关键字序号.length];

           int [] n6=new int[关键字序号.length];

           for (int j=0;j<关键字序号.length;j++){

                  s6[j]=关键字[j];

                  n6[j]=列数据宽度[关键字序号[j]];

           }

           for (int i = 0; i < 记录条数; i++) {

             for (int j=0;j<关键字序号.length;j++){

                if ((s7[i]==null)||(s7[i].length()==0))

                   s7[i]=表格数据[i][关键字序号[j]];

                else s7[i]=s7[i]+","+表格数据[i][关键字序号[j]];

             }

           }

           main1.n = 0; // 打印预览标志

           statisticalChart1.means(fa10, 表格数据);

        }

     });

     panel1.add(inButton);

     final JButton inButton1 = new JButton("打印图表");

     inButton1.setBounds(530, 520, 170, 20);

     inButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           String [] s7=new String[记录条数];

           String [] s6=new String[关键字序号.length];

           int [] n6=new int[关键字序号.length];

           for (int j=0;j<关键字序号.length;j++){

                  s6[j]=关键字[j];

                  n6[j]=列数据宽度[关键字序号[j]];

           }

           for (int i = 0; i < 记录条数; i++) {

             for (int j=0;j<关键字序号.length;j++){

                if ((s7[i]==null)||(s7[i].length()==0))

                   s7[i]=表格数据[i][关键字序号[j]];

                else s7[i]=s7[i]+","+表格数据[i][关键字序号[j]];

             }

           }

           main1.n = 1; // 打印标志

           statisticalChart1.means(fa10, 表格数据);

        }

     });

     panel1.add(inButton1);

 

     final JButton exitButton = new JButton("退出");

     exitButton.setBounds(720, 520, 170, 20);

     exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           panel1.setVisible(false);

           frame1.setVisible(false);

           frame1.dispose();

        }

     });

     panel1.add(exitButton);

     frame1.setVisible(true);

   }

 

   static void rectangular() {

     g.setColor(Color.BLACK);

     int 可用宽度 = 窗口宽度;

     int 可用高度 = 窗口高度 - 100;

     int 纵向单位 = 可用高度 / (纵向分段数 + 1);

     int 单位数据 = 最大值 / (纵向分段数);

     int Y线左边距 = 60;

     int Y线到顶距 = 图顶点;

     g2.setStroke(new BasicStroke(2f));

     g.drawLine(Y线左边距, Y线到顶距, Y线左边距, Y线到顶距 + 可用高度);

     int x = 0;

     int h0;

     for (int i = 0; i <= 纵向分段数; i++) {

        if (i < 纵向分段数) {

           h0 = (纵向分段数 - i) * 纵向单位;

           g.drawString(最大值 - (纵向分段数 - i - 1) * 单位数据 + "", Y线左边距 - 40,

                Y线到顶距 + h0);

           g.drawLine(Y线左边距 - 3, Y线到顶距 + h0, Y线左边距 + 3, Y线到顶距 + h0);

        }

     }

     g.setColor(Color.BLACK);

     g.drawLine(Y线左边距 - 10, Y线到顶距 + 可用高度 - 10, Y线左边距 + 窗口宽度 - 100, Y线到顶距

           + 可用高度 - 10);

     int X坐标单位 = (窗口宽度 - 140) / (列数1 * 2);

     int X坐标单位1 = X坐标单位 / 4;

     for (int i = 0; i < 列数1; i++) {

        g.setColor(Color.RED);

        g.drawString(数据列名[i], Y线左边距 + (i * 2 + 1) * X坐标单位 + X坐标单位1, Y线到顶距

             + 可用高度 + 6);

        g.fillRect(Y线左边距 + i * 2 * X坐标单位 + X坐标单位, Y线到顶距

             + (可用高度 - (可用高度 * 交叉数据1[i] / 最大值)) + 10, X坐标单位, 可用高度

             * 交叉数据1[i] / 最大值 - 20);

        if (i == 列数1 - 1) {

           g.fillRect(标签左边, Y线到顶距 + 可用高度 + 20, 8, 8);

           g.drawString(关键字[0] + "" + 标签数据[记录号], 标签左边 + 10, Y线到顶距 + 可用高度

                + 30);

        }

        g.setColor(Color.BLACK);

        g.drawString("" + 交叉数据1[i], Y线左边距 + (i * 2 + 1) * X坐标单位, Y线到顶距

             + (可用高度 - (可用高度 * 交叉数据1[i] / 最大值)) + 6);

     }

   }

 

   static void rectangulars() {

     最大值 = 0;

     for (int i = 0; i < 记录条数; i++)

        for (int j = 0; j < 列数1; j++) {

           if (交叉数据2[i][j] > 最大值)

             最大值 = 交叉数据2[i][j];

        }

 

     int 字号 = 12;

     g.setFont(new Font("宋体", Font.PLAIN, 字号));

     g.setColor(Color.BLACK);

     int 可用宽度 = 窗口宽度;

     int 可用高度 = 窗口高度 - 100;

     int 纵向单位 = 可用高度 / (纵向分段数 + 1);

     int 单位数据 = (最大值 - 最小值) / 纵向分段数;

     int Y线左边距 = 60;

     int Y线到顶距 = 图顶点;

     g.drawLine(Y线左边距, Y线到顶距, Y线左边距, 可用高度 + Y线到顶距);

     int h0;

     g.setColor(Color.BLACK);

     for (int i = 0; i <= 纵向分段数; i++) {

        if (i < 纵向分段数) {

           h0 = (纵向分段数 - i) * 纵向单位;

          g.drawString(最大值 - (纵向分段数 - i - 1) * 单位数据 + "", Y线左边距 - 25,

                Y线到顶距 + h0);

           g.drawLine(Y线左边距 - 3, Y线到顶距 + h0, Y线左边距 + 3, Y线到顶距 + h0);

        }

     }

     g.setColor(Color.BLACK);

     g.drawLine(Y线左边距 - 10, Y线到顶距 + 可用高度 - 10, Y线左边距 + 窗口宽度 - 100, Y线到顶距

           + 可用高度 - 10);

     int X坐标单位 = (窗口宽度 - 140) / (列数1 * 2);

     int X坐标单位1 = X坐标单位 / 4;

     int 宽度1 = X坐标单位 / 记录条数;

     标签左边 = 30;

     for (int i = 0; i < 列数1; i++) {

        g.setColor(Color.BLACK);

        g.drawString(数据列名[i], Y线左边距 + (i * 2 + 1) * X坐标单位 + X坐标单位1, Y线到顶距

             + 可用高度 + 6);

        for (int j = 0; j < 记录条数; j++) {

           color1(j + 1, g);

           g.fillRect(Y线左边距 + i * 2 * X坐标单位 + X坐标单位 + 宽度1 * j, Y线到顶距

                + (可用高度 - (可用高度 * 交叉数据2[j][i] / 最大值)) + 15, 宽度1, 可用高度

                * 交叉数据2[j][i] / 最大值 - 20);

           if (i == 列数1 - 1) {

            g.fillRect(标签左边, Y线到顶距 + 可用高度 + 20, 8, 8);

             g.drawString((关键字[关键字.length - 1] + "" + 标签数据[j]).trim(),

                   标签左边 + 10, Y线到顶距 + 可用高度 + 30);

             标签左边 = 标签左边

                   + (关键字[关键字.length - 1] + "" + 标签数据[j]).trim()

                        .length() * 字号 + 10;

           }

           g.setColor(Color.BLACK);

           g.drawString("" + 交叉数据2[j][i], Y线左边距 + (i * 2 + 1) * X坐标单位

                + 宽度1 * j, Y线到顶距 + (可用高度 - (可用高度 * 交叉数据2[j][i] / 最大值))

                + 6);

        }

     }

   }

 

   static void roundCake() {

     color1(5, g);

     int 总计 = 0;

     int[] 百分数 = new int[交叉数据1.length];

     for (int i = 0; i < 交叉数据1.length; i++)

        总计 = 总计 + 交叉数据1[i];

     for (int i = 0; i < 交叉数据1.length; i++) {

        百分数[i] = 360 * 交叉数据1[i] / (总计);

     }

     int x = 0, 起始角度 = 0, 终了角度 = 0, y2 = 0, y3 = 0;

     double y1 = 0;

     int k = 0;

     for (int i = 0; i < 列数1; i++) {

        终了角度 = 起始角度 + 百分数[i];

        y1 = ((终了角度 - 起始角度) / 2 + 起始角度);

        y3 = 250 + (int) (200 * Math.cos(y1 * 3.14 / 180));

        y2 = 250 - (int) (200 * Math.sin(y1 * 3.14 / 180));

        if (y2 < 100)

           y2 = y2 + 30;

        if (y2 > 400)

           y2 = y2 - 20;

        if (y3 > 250)

           y3 = y3 - 30;

        else

           y3 = y3 - 10;

        if (y3 < 100)

           y3 = y3 - 10;

        g.drawString(列名[i], y3, y2);

        起始角度 = 终了角度;

     }

     标签左边 = 500;

     标签到顶 = 图顶点 + 100;

     for (int i = 0; i < 列数1; i++) {

        color1(i + 1, g);

        g.fillRect(标签左边, 标签到顶 - 10, 8, 8);

        g.drawString(关键字[0] + "" + 标签数据[记录号] + " " + 交叉数据1[i], 标签左边 + 10,

             标签到顶);

        标签到顶 = 标签到顶 + 30;

     }

 

     起始角度 = 0;

     终了角度 = 0;

     y2 = 0;

     y3 = 0;

     for (int i = 0; i < 列数1; i++) {

        终了角度 = 起始角度 + 百分数[i];

        if (i == 列数1 - 1)

           终了角度 = 360;

        color1(i + 1, g);

        if (i == 列数1 - 1)

           终了角度 = 360;

        if (起始角度 < 90) {

           if (终了角度 <= 90)

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 终了角度 - 起始角度);

           else if (终了角度 <= 180) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 90);

             g.fillArc(100, 图顶点 + 30, 300, 300, 90, 终了角度 - 90);

           } else if (终了角度 <= 270) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 90);

             g.fillArc(100, 图顶点 + 30, 300, 300, 90, 90);

             g.fillArc(100, 图顶点 + 30, 300, 300, 180, 终了角度 - 180);

           } else if (终了角度 <= 360) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 90);

             g.fillArc(100, 图顶点 + 30, 300, 300, 90, 90);

             g.fillArc(100, 图顶点 + 30, 300, 300, 180, 90);

             g.fillArc(100, 图顶点 + 30, 300, 300, 270, 终了角度 - 270);

           }

        } else if (起始角度 < 180) {

           if (终了角度 <= 180) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 终了角度 - 起始角度);

           } else if (终了角度 <= 270) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 180 - 起始角度);

             g.fillArc(100, 图顶点 + 30, 300, 300, 180, 终了角度 - 180);

           } else if (终了角度 <= 360) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 180 - 起始角度);

             g.fillArc(100, 图顶点 + 30, 300, 300, 180, 90);

             g.fillArc(100, 图顶点 + 30, 300, 300, 270, 终了角度 - 270);

           }

        } else if (起始角度 < 270) {

           if (终了角度 <= 270) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 终了角度 - 起始角度);

           } else if (终了角度 <= 360) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 270 - 起始角度);

             g.fillArc(100, 图顶点 + 30, 300, 300, 270, 终了角度 - 270);

           }

        } else if (起始角度 < 360) {

           if (终了角度 <= 360) {

             g.fillArc(100, 图顶点 + 30, 300, 300, 起始角度, 终了角度 - 起始角度);

           }

        }

        起始角度 = 终了角度;

     }

   }

 

   static void brokenLine() {

     g.setColor(Color.BLACK);

     int 可用宽度 = 窗口宽度;

     int 可用高度 = 窗口高度 - 100;

     int 纵向单位 = 可用高度 / (纵向分段数 + 1);

     int 单位数据 = (最大值 - 最小值) / (纵向分段数);

     int Y线左边距 = 60;

     int Y线到顶距 = 图顶点 + 10;

     g.drawLine(Y线左边距, Y线到顶距, Y线左边距, 图顶点 + 可用高度 + 10);

     int x = 0;

     int h0;

     for (int i = 0; i <= 纵向分段数; i++) {

        if (i < 纵向分段数) {

           h0 = (纵向分段数 - i) * 纵向单位;

           g.drawString(最大值 - (纵向分段数 - i - 1) * 单位数据 + "", Y线左边距 - 40,

                Y线到顶距 + h0);

           g.drawLine(Y线左边距 - 3, Y线到顶距 + h0, Y线左边距 + 3, Y线到顶距 + h0);

        }

     }

     g.setColor(Color.BLACK);

     g.drawLine(Y线左边距 - 10, Y线到顶距 + 可用高度 - 10, Y线左边距 + 窗口宽度 - 100, Y线到顶距

           + 可用高度 - 10);

     int X坐标单位 = (窗口宽度 - 140) / (列数1 * 2);

     int X坐标单位1 = X坐标单位 / 4;

     int[] l0 = new int[列数1];

     int[] l1 = new int[列数1];

     int 点数 = 0;

     标签左边 = 50;

     for (int i = 0; i < 列数1; i++) {

        g.setColor(Color.RED);

        g.drawString(数据列名[i], Y线左边距 + (i * 2 + 1) * X坐标单位 + X坐标单位1 + 10,

             Y线到顶距 + 可用高度 + 6);

        l0[i] = Y线左边距 + i * 2 * X坐标单位 + X坐标单位;

        l1[i] = Y线到顶距 + (可用高度 - (可用高度 * 交叉数据1[i] / 最大值)) + 15;

        点数++;

        g.fillRect(标签左边 + 20, Y线到顶距 + 可用高度 + 20, 8, 8);

        g.drawString(关键字[0] + "" + 标签数据[记录号], 标签左边 + 30, Y线到顶距 + 可用高度 + 30);

 

        g.setColor(Color.BLACK);

        g.drawString("" + 交叉数据1[i], Y线左边距 + (i * 2 + 1) * X坐标单位, Y线到顶距

             + (可用高度 - (可用高度 * 交叉数据1[i] / 最大值)) + 6);

     }

     g2 = (Graphics2D) g;

     g2.setStroke(new BasicStroke(5f));

     g.drawPolyline(l0, l1, 点数);

   }

 

   static void color1(int c, Graphics g1) {

     switch (c) {

     case 1:

        g1.setColor(Color.red);

        break;

     case 2:

        g1.setColor(Color.blue);

        break;

     case 3:

        g1.setColor(Color.orange);

        break;

     case 4:

        g1.setColor(Color.green);

        break;

     case 5:

        g1.setColor(Color.black);

        break;

     case 6:

        g1.setColor(Color.cyan);

        break;

     case 7:

        g1.setColor(Color.yellow);

        break;

     case 8:

        g1.setColor(Color.lightGray);

        break;

     case 9:

        g1.setColor(Color.red);

        break;

     case 10:

        g1.setColor(Color.blue);

        break;

     case 11:

        g1.setColor(Color.orange);

        break;

     case 12:

        g1.setColor(Color.green);

        break;

     case 13:

        g1.setColor(Color.black);

        break;

     case 14:

        g1.setColor(Color.cyan);

        break;

     case 15:

        g1.setColor(Color.yellow);

        break;

     case 16:

        g1.setColor(Color.lightGray);

        break;

     case 17:

        g1.setColor(Color.white);

        break;

     }

   }

 

   static void 数据表查询结构(String 数据表名) {

     String[] s10 = null;

     String[] sk = new String[300];

     int n1 = 0, n2 = 0;

     连接条件 = "";

     main1.driver1();

     if (数据表名.indexOf(",") < 0) { // 单表

        try {

           cont4 = main1.getConn();

           stat4 = cont4.createStatement(

                ResultSet.TYPE_SCROLL_INSENSITIVE,

                ResultSet.CONCUR_UPDATABLE);

           String s1 = "select * from " + 数据表名;

           rs = stat4.executeQuery(s1);

           rsmdt4 = rs.getMetaData();

           列数 = rsmdt4.getColumnCount();

           列名 = new String[列数];

           列数据类型 = new String[列数];

           列数据宽度 = new int[列数];

           for (int i = 0; i < 列数; i++) {

             列名[i] = rsmdt4.getColumnName(i + 1);

           }

           rs.close();

           stat4.close();

           cont4.close();

        } catch (SQLException e1) {

           JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

        }

     } else { // 多表

        s10 = 数据表名.split(",");

        String s0 = "", s1 = "", s2 = "";

        int k = 0;

        for (int i = 0; i < s10.length; i++) {

           try {

             cont4 = main1.getConn();

             stat4 = cont4.createStatement(

                   ResultSet.TYPE_SCROLL_INSENSITIVE,

                   ResultSet.CONCUR_UPDATABLE);

             s1 = "select * from " + s10[i];

             rs = stat4.executeQuery(s1);

             rsmdt4 = rs.getMetaData();

             列数 = rsmdt4.getColumnCount();

             for (int j = 0; j < 列数; j++) { // 读取所有表的列名,同名的加表名

                s2 = rsmdt4.getColumnName(j + 1).toLowerCase(); // 列名

                n2 = n1;

                if (i > 0) { // 加入第2个表之后字段出现同名字段

                   k = 0;

                   for (int j1 = 0; j1 < n2; j1++) {

                      if (sk[j1].equals(s2)) {

                        sk[j1] = s10[i - 1] + "." + sk[j1];

                        if (连接条件.length() == 0) // 连接条件

                           连接条件 = " where " + s10[i - 1] + "."

                                + s2 + " = " + s10[i] + "."

                                + s2;

                        else

                           连接条件 = 连接条件 + " and " + s10[i - 1]

                                + "." + s2 + " = " + s10[i]

                                + "." + s2;

                        sk[n1] = s10[i] + "." + s2 + " as "

                              + (s2 + i);

                        n1++;

                        k = 1;

                        break;

                      }

                   }

                   if (k == 0) {

                      sk[n1] = s2;

                      n1++;

                   }

                } else {

                   sk[n1] = s2;

                   n1++;

                }

             }

             rs.close();

             stat4.close();

             cont4.close();

           } catch (SQLException e1) {

             JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

           }

        }

     }

   }

 

   static void 数据表查询数据(String 数据表名) {

     int c = 0;

     int b = 0;

     for (int i=关键字.length-1;i>=0;i--)

        if ((","+字段名表+",").indexOf(关键字[i])<0)

           字段名表=关键字[i]+","+字段名表;

     try {

        cont4 = main1.getConn();

        stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

             ResultSet.CONCUR_UPDATABLE);

        s1 = "select " + 字段名表 + "  from " + 数据表名 + 连接条件;

        rs = stat4.executeQuery(s1);

        rsmdt4 = rs.getMetaData();

        列数 = rsmdt4.getColumnCount();

        列名 = new String[列数];

        列数据类型 = new String[列数];

        列数据宽度 = new int[列数];

        int k1=0;

        for (int i1 = 0; i1 < 列数; i1++) {

           列名[i1] = rsmdt4.getColumnName(i1 + 1);

           for (int j1=0;j1<关键字.length;j1++)

           if (关键字[j1].equals(列名[i1]))

             关键字序号[j1]=i1;

           列数据类型[i1] = rsmdt4.getColumnTypeName(i1 + 1);

           列数据宽度[i1] = rsmdt4.getColumnDisplaySize(i1 + 1);

        }

        rs.last();

        记录条数 = rs.getRow();

        表格数据 = new String[记录条数][列数];

        while (c < 记录条数) {

           rs.absolute(c + 1);

           while (b < 列数) {

             表格数据[c][b] = rs.getString(b + 1);

              if ((main1.数字数据类型.lastIndexOf("," + 列数据类型[b] + ",")) > 0)

                if ((表格数据[c][b] == null)

                      || (表格数据[c][b].trim().length() == 0))

                   表格数据[c][b] = "0";

                else if (表格数据[c][b] == null)

                   表格数据[c][b] = "";

             b++;

           }

           c++;

           b = 0;

        }

        rs.close();

        stat4.close();

        cont4.close();

     } catch (SQLException e1) {

        JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

     }

   }

}

100.源码100,公共程序,支持dataPrint5程序打印带统计图的报表表格。

/**

 * 程序文件名:statisticalChart1.java

 * 作者:程学先

 * 用途:公共程序,支持dataPrint5程序打印带统计图的报表表格。

 * 本程序使用到了jcommon-1.0.16.jarjfreechart-1.0.13.jar包,

 * 需要到官方网站自行下载,并放到P1文件夹下COM文件夹中。

 * 调用语句:statisticalChart1(打印格式文件名,打印表格之数据,打印统计图之数据,

 * 关键字字段名,关键字字段宽度,统计图图形X轴分组字段名,统计图图形X轴数据标志字段名)

 * 本程序对数据要求较高,请保证表格中数据无空值。

 * 本程序在学习李钟尉、陈丹丹等老师所著“java开发实战1200例(第2卷)”之后设计,特此感谢。

 * 相关饼图、折线图程序请参考该书用例自行设计。

 */

import java.awt.BasicStroke;

import java.awt.BorderLayout;

import java.awt.Canvas;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.GradientPaint;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.awt.print.PageFormat;

import java.awt.print.Printable;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.sql.ResultSet;

import javax.imageio.ImageIO;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JFrame;

 

import org.jfree.chart.ChartUtilities;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.axis.CategoryAxis;

import org.jfree.chart.axis.CategoryLabelPositions;

import org.jfree.chart.axis.NumberAxis;

import org.jfree.chart.plot.CategoryPlot;

import org.jfree.chart.plot.PlotOrientation;

import org.jfree.chart.renderer.category.BarRenderer;

import org.jfree.chart.title.TextTitle;

import org.jfree.data.category.DefaultCategoryDataset;

import org.jfree.ui.HorizontalAlignment;

 

public class statisticalChart1 extends JFrame implements Printable {

   private static statisticalChart1 frame;

   private PageFormat pf;

   private static PreviewCanvas1 canvas;

   private boolean isPreview = false; //是否可以打印

   private boolean previewFlag = false;

   static String 表名;

   private static String s1 = "";

   private static int 记录条数, 记录条数1;

   private static int 表格列数, 表格列数1;

   private static String[][] 表格数据;

   private static String[][] 表格数据1;

   private static String path;

   private static int 窗口宽 = 0;

   private static String 文件名;

   private static FileReader fr;

   private static String[] 图表;

   private static Graphics2D g2;

   private static Graphics g;

   private static String 数据字段名;

   private static String 分组字段名,关键字;

   private static String[] 字段名1=null;

   private static int[] 关键字1=null,关键字序号=null;

   private static String[] 字段宽度=null,字段宽度1=null;

   private static int 小组起始号=0,终了序号=0;

   private static String[] 字段名=null;

   private static String[] 关键字值=null;

   public static void gainReport() {

     图表 = new String[17];

     if (文件名.length() < 1) {

        JOptionPane.showMessageDialog(null, "缺文件名!");

        return;

     }

     File file1 = new File(文件名);

     try {

        if (file1.exists())

           fr = new FileReader(file1);

        BufferedReader br = new BufferedReader(fr);

        String tempStr = null;

        for (int i = 0; (tempStr = br.readLine()) != null; i++) {//读文件

           图表[i] = tempStr;

        }

     } catch (IOException e2) {

        JOptionPane.showMessageDialog(null, "打开文件错!");

     }

   }

 

   static void means(String 文件名0, String[][] 表格数据2){

     图表 = new String[17];

     文件名 = 文件名0;

     gainReport();   //读打印格式文件内容

     记录条数=表格数据2.length;

     关键字=图表[10];

     String [] 关键字2=关键字.split(",");

     字段名=图表[3].split(",");

        字段宽度=图表[4].split(",");

     表格数据=new String[记录条数][字段名.length];

     for (int i=0;i<表格数据2.length;i++){

        for (int j=0;j<表格数据2[0].length;j++){

                表格数据[i][j]=表格数据2[i][j];

        }

        }

     s1 = "";

     int n1=字段名.length-关键字2.length;   //非关键字字段个数

     数据字段名="";

     关键字1=new int[关键字2.length];

     表格数据1=new String[记录条数][n1];

     关键字序号=new int[关键字2.length];

     字段宽度1=new String[关键字2.length];

     关键字值=new String[记录条数];

     字段名1=new String[关键字2.length];

     int c1=0;

     for (int i=0;i<字段名.length;i++){

        if ((","+图表[10]+",").indexOf(","+字段名[i]+",")<0){   //非关键字字段

           if (数据字段名.length()==0) 数据字段名=字段名[i];

           else 数据字段名=数据字段名+","+字段名[i];

             for (int j=0;j<记录条数;j++){

              表格数据1[j][c1]=表格数据2[j][i];   //数字数据类型数据

             }

            c1++;

        }

        for (int j1=0;j1<关键字2.length;j1++){

           if (字段名[i].equals(关键字2[j1])){

             关键字序号[j1]=i;

             字段宽度1[j1]=字段宽度[i];

             关键字1[j1]=Integer.parseInt(字段宽度[i]);

             字段名1[j1]=关键字2[j1];

           }

        }

     }

        for (int j=0;j<记录条数;j++){

         关键字值[j]="";

        for (int j1=0;j1<关键字2.length;j1++){

           if (j1==0) 关键字值[j]=表格数据2[j][关键字序号[j1]];

           else  关键字值[j]=关键字值[j]+","+表格数据2[j][关键字序号[j1]];

        }

        }

        String ss0="";

     小组起始号=0;

     String [] l0=null;

     if (记录条数>20) {    //一个图如果显示20条以上数据将显示不够清楚

        boolean bol1=true;

        while (bol1) {

        ss0=JOptionPane.showInputDialog("请输入图表显示的起始记录号与欲显示记录数,之间用逗号分隔。");

        l0=ss0.split(",");

        小组起始号=Integer.parseInt(l0[0]);

        终了序号=Integer.parseInt(l0[1]);

        if (小组起始号+终了序号>记录条数){

           JOptionPane.showMessageDialog( null,"所选记录范围超过记录总数:"+记录条数);

        }

        else bol1=false;

        }

        记录条数=Integer.parseInt(l0[1]);

       }

     窗口宽 = main1.窗口宽;

     表格列数 = 表格数据1[0].length;

     frame = new statisticalChart1(); //建立表单,执行构造方法

     frame.setVisible(true);

   }

 

   public statisticalChart1() {

     super();

     JFreeChart chart = createChart();//图表对象

     path = "a1.jpg";//图表存储位置

     int we1 = 窗口宽;

     int we2 = Integer.parseInt(图表[15]);

     try {

        ChartUtilities.writeChartAsJPEG(new FileOutputStream(path), chart,

             we1, we2);//将图表存储为图片,调节数字,可调节所生成图片大小

     } catch (FileNotFoundException e1) {

        e1.printStackTrace();

     } catch (IOException e1) {

        e1.printStackTrace();

     }

     setTitle(图表[0]);

     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     pf = new PageFormat(); //打印页面

     canvas = new PreviewCanvas1();

     int we3 = Integer.parseInt(图表[6]) + 2; //数据表字号

     int 窗口宽 = we1;

     int 窗口高 = we2 + 记录条数 * we3 + Integer.parseInt(图表[2])

           + Integer.parseInt(图表[9]);

     this.setSize(new Dimension(窗口宽, 窗口高));

     BorderLayout borderLayout = new BorderLayout();

     borderLayout.setHgap(10);

     setLayout(borderLayout);

     canvas.setSize(new Dimension(窗口宽, 窗口高)); //画布大小

     add(canvas, BorderLayout.CENTER);

     final JPanel panel = new JPanel();

     panel.setOpaque(false);

     getContentPane().add(panel, BorderLayout.SOUTH);

     if (main1.n == 1) {

        PrinterJob job = PrinterJob.getPrinterJob();

        if (!job.printDialog()) {//打开打印对话框

           return;

        }

        job.setPrintable(new Printable() {

           public int print(Graphics graphics, PageFormat pageFormat,

                int pageIndex) throws PrinterException {

             isPreview = true; //可以打印

             if (pageIndex < 1) {

                statisticalChart1.g = graphics;

                g2 = (Graphics2D) g;

                g2.setStroke(new BasicStroke(1f));

                printPicture(graphics, pageFormat, pageIndex);

                return Printable.PAGE_EXISTS;

             } else {

                return Printable.NO_SUCH_PAGE;

             }

           }

 

        });

        job.setJobName("打印报表");

        try {

           job.print();//实现打印

        } catch (PrinterException e1) {

           e1.printStackTrace();

        }

     }

   }

   private static JFreeChart createChart() {

     DefaultCategoryDataset dataset = new DefaultCategoryDataset();

     String [] 字段名2=数据字段名.split(",");

     for (int i = 0; i < 表格数据1.length; i++) {

        for (int j=0;j<表格数据1[0].length;j++){

        if ((表格数据1[i][j] == null) || (表格数据1[i][j].length() == 0))

           表格数据1[i][j] = 0 + "";

        int value = (int) Double.parseDouble(表格数据1[i][j]);

        String sf1 = 字段名2[j];

        String sf0 = 关键字值[i];

        dataset.addValue(value, sf1, sf0);//添加图形数据信息

        }

     }

     JFreeChart chart=null;

     chart = ChartFactory.createBarChart("\n\n" + 图表[7],分组字段名, 数据字段名,

           dataset,PlotOrientation.VERTICAL, true,true,false);

     chart.setBackgroundPaint(Color.white);

     CategoryPlot plot = (CategoryPlot) chart.getPlot();

     NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

     rangeAxis.setTickLabelFont(new Font("Sans-serif", Font.PLAIN, 12));

     rangeAxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));

      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

     BarRenderer renderer = (BarRenderer) plot.getRenderer();

     GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f,

           0.0f, new Color(0, 0, 64));

     GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f,

           0.0f, new Color(0, 64, 0));

     renderer.setSeriesPaint(0, gp0);

     renderer.setSeriesPaint(1, gp1);

     CategoryAxis domainAxis = plot.getDomainAxis();

     domainAxis.setTickLabelFont(new Font("Sans-serif", Font.PLAIN, 20));

     domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 20));

      domainAxis.setCategoryLabelPositions(CategoryLabelPositions

           .createUpRotationLabelPositions(Math.PI / 6.0));

     TextTitle textTitle = chart.getTitle();

     textTitle.setFont(new Font(图表[8], Font.PLAIN, Integer.parseInt(图表[9])));

      chart.getLegend().setItemFont(

           new Font(图表[8], Font.PLAIN, Integer.parseInt(图表[9])));

      chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);

     return chart;

   }

 

  public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)

        throws PrinterException {

     printPicture(graphics, pageFormat, pageIndex);//绘图

     return Printable.PAGE_EXISTS;

   }

 

   class PreviewCanvas1 extends Canvas {

     public void paint(Graphics g) {

        try {

           super.paint(g);

           g2 = (Graphics2D) g;

           g2.translate(10, 10);

           int x = (int) (pf.getImageableX() - 1);

           int y = (int) (pf.getImageableY() - 1);

           int width = (int) (pf.getImageableWidth() + 1);

           int height = (int) (pf.getImageableHeight() + 1);

           int mw = (int) pf.getWidth();

           int mh = (int) pf.getHeight();

           g2.drawRect(0, 0, mw, mh);

           g2.setColor(new Color(255, 253, 234));

           g2.fillRect(1, 1, mw - 1 + 300, mh - 1);

           g2.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND,

               BasicStroke.JOIN_ROUND, 10f, new float[] { 5, 5 }, 0f));

           g2.setColor(Color.BLACK);

           g2.setColor(Color.WHITE);

           g2.fillRect(x + 1, y + 1, width - 1 + 300, height - 1);

           statisticalChart1.this.print(g, pf, 0);

        } catch (PrinterException e) {

           e.printStackTrace();

        }

     }

   }

   public void printPicture(Graphics graphics, PageFormat pageFormat,

        int pageIndex) {

     int x = (int) pageFormat.getImageableX() - 20;

     int y = (int) pageFormat.getImageableY();

     int w = (int) pageFormat.getImageableWidth();

     int w1=0;

     int w2=(int) (Integer.parseInt(图表[6]) * 1.5);

     g2 = (Graphics2D) graphics;

     g2.setColor(Color.BLUE);

     g2.setFont(new Font(图表[1], Font.BOLD, Integer.parseInt(图表[2])));

     g2.drawString(图表[0], x + 60, y + 30);

     g2.setColor(Color.BLACK);

     g2.setFont(new Font(图表[5], Font.PLAIN, Integer.parseInt(图表[6])));

     g2.setStroke(new BasicStroke(1f));

     String[] we5 = 图表[3].split(",");

     String[] we6 = 图表[4].split(",");

     int[] we7 = new int[we6.length];

     int we8 = Integer.parseInt(图表[6]);

     for (int i = 0; i < we6.length; i++){

        we7[i] = Integer.parseInt(we6[i]);

     }

     try {

        y = y + 30 + Integer.parseInt(图表[2]);

        int y1 = y;

        int xe1 = x;

        g2.drawLine(xe1, y1 - 20, xe1, y + (记录条数-1)*w2);//左边线

        for (int i = 0; i < we6.length; i++) {

           g2.drawLine(xe1, y - 20, xe1 + we7[i], y - 20);//水平线

           g2.drawString(we5[i], xe1 + 5, y - 5);//标签

           g2.drawLine(xe1 + we7[i], y1 - 20, xe1 + we7[i], y + 10);//右边线

           xe1 = xe1 + we7[i];

        }

        for (int i = 0; i < 记录条数; i++) {

           y1 = y;

           y = y + (int) (Integer.parseInt(图表[6]) * 1.5);

          xe1 = x;

           g2.drawLine(xe1, y1, xe1, y);

           for (int j = 0; j < we6.length; j++) {

                    w1=we7[j];

             g2.drawLine(xe1, y1, xe1 + w1, y1);

             g2.drawString(表格数据[i][j], xe1 + 5, y - 5);

             g2.drawLine(xe1 + w1, y1, xe1 + w1, y);

             if (i == 记录条数 - 1)

                g2.drawLine(xe1, y, xe1 + w1, y);

             xe1 = xe1 + w1;

           }

        }

        File file = new File("a1.jpg");

        BufferedImage image1 = ImageIO.read(file);

        g2.drawImage(image1, 10, y + 20, 820, 300, this);

     } catch (Exception ex) {

        ex.printStackTrace();

     }

     isPreview = true;

     previewFlag = true;

   }

}

版本2

98.源码98,部件程序,生成带统计图表格的数据报表格式文件。该报表针对数据表的每条记录所指定的若干数字数据类型字段数据生成直方图,形象地比较一条记录中各字段数据大小关系及相关记录中这些字段数据关系。

/*

 * 程序文件名:statisticalChart1.java

 * 作者:程学先

 * 功能:生成打印或打印预览带统计图表格的数据报表格式文件。

 * 该报表将针对数据表的每条记录各字段数据生成直方图,比较一条记录中各字段数据大小关系。

 * 每条记录的数据组成一组,总组数等于记录条数,

 * 必须输入的参数:表名。

 * 格式文件格式:

 * 第一行数据为:标题[]:(表格标题,字体,字号,统计图标题,字体字号,记录条数、记录列数),

 * 第二行数据为:表格字段名[],限数字数据类型字段的字段名。

 * 第三行以后为:每列宽度,将自动根据字段宽度与字号填入文本框,可手工修改宽度。

 * 第四行数据为:图的记录分组字段名、标识字段名和数据字段名

 * 第五行数据为:统计图宽度、高度、统计函数类型。

 * 在输入数据时请顺次输入,在存盘后可以预览报表摸样。

 */

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

 

public class printFormat3 extends JFrame {

   private static printFormat3 frame1 = new printFormat3();

   private static JPanel panel1 = new JPanel();

   private static List list1 = new List();

   private static JLabel fl0, fl1, fl2, fl3, fl4, fl10;

   private static JTextField fa0, fa1, fa2, fa3, fa4, fa10;

   private static JLabel fla0, fla1, fla2;

   private static JTextField faa0, faa1, faa2;

   private static JLabel flb0, flb1, flb2;

   private static JTextField fab0, fab1, fab2;

   private static JLabel flc2, flc3, flc4, flc5, flc6;

   private static JTextField fac2, fac3, fac4, fac5, fac6;

   private static String variabl2327;

   private static int variabl1823 = -1, variabl1947 = 0, variabl2193 = 0,

        variabl1739 = 0, variabl2651 = 0;

   private static int variabl2127 = 0, variabl1853 = 0;

   private static String[][] variabl2197 = null;

   private static String[][] variabl21971 = null;

   private static ArrayList<String> variabl1665 = new ArrayList();

   private static String[] variabl25171;

   private static String[] variabl2663;

   private static String[] variabl1501;

   private static int[] variabl1489;

   private static String[] variabl2157 = new String[12];

   private static int[] variabl21571 = new int[12];

   private static File file1;

   private static FileReader fr;

   static Connection con;

   private static Statement sta;

   static String s1 = "", s2 = "";

   private static ResultSet rs;

   private static ResultSetMetaData rsmd;

   private static ArrayList variabl26031 = new ArrayList();

   private static String[] variabl2607 = { "5", "6", "7", "8", "9", "10",

        "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36",

        "48", "72" };

   private static String[] variabl2629 = { "宋体", "楷体", "黑体", "仿宋_GB2312" };

   private static String[] variabl2511 = { "柱形图", "饼形图", "折线图" };

   private static int variabl2483 = main1.variabl2483;

   private static String variabl2217;

   private static String variabl2049 = "";

   private static String variabl1633 = "";

 

   static void means(String[] parameter) {

     frame1 = new printFormat3();

     panel1 = new JPanel();

     list1 = new List();

     variabl1823 = -1;

     variabl1947 = 0;

     variabl2193 = 0;

     variabl1739 = 0;

     variabl2651 = 0;

     variabl2127 = 0;

     variabl1853 = 0;

     variabl1665 = new ArrayList();

     variabl2157 = new String[12];

     variabl21571 = new int[12];

     s1 = "";

     s2 = "";

     variabl26031 = new ArrayList();

     variabl2607 = new String[19];

     variabl2629 = new String[4];

     variabl2607[0] = "5";

     variabl2607[1] = "6";

     variabl2607[2] = "7";

     variabl2607[3] = "8";

     variabl2607[4] = "9";

     variabl2607[5] = "10";

     variabl2607[6] = "11";

     variabl2607[7] = "12";

     variabl2607[8] = "14";

     variabl2607[9] = "16";

     variabl2607[10] = "18";

     variabl2607[11] = "20";

     variabl2607[12] = "22";

     variabl2607[13] = "24";

     variabl2607[14] = "26";

     variabl2607[15] = "28";

     variabl2607[16] = "36";

     variabl2607[17] = "48";

     variabl2607[18] = "72";

     variabl2629[0] = "宋体";

     variabl2629[1] = "楷体";

     variabl2629[2] = "黑体";

     variabl2629[3] = "仿宋_GB2312";

     frame1.setTitle("图表类报表打印格式设计与打印程序。                       作者程学先");

     frame1.setBounds(10, 10, 900, 580);

      frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

     panel1.setBounds(10, 10, 880, 570);

     panel1.setLayout(null);

     String[] variabl251701 = { "标签名", "字段名", "宽度", "字体", "字号" };

     main1.driver1();

     variabl2217 = parameter[4];

     数据表查询结构(variabl2217);

     fl10 = new JLabel("文件名");

     fl10.setBounds(30, 30, 50, 20);

     panel1.add(fl10);

     fa10 = new JTextField("", 20);

     fa10.setBounds(80, 30, 620, 20);

     panel1.add(fa10);

     fa10.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

           variabl2663 = new String[37];

           if (fa10.getText().length() < 1) {

             final JFileChooser fc = new JFileChooser(".\\");

             fc.showOpenDialog(null);

             if (fc.getSelectedFile() != null) {

                fa10.setText(fc.getSelectedFile().toString());

                file1 = new File(fa10.getText());

                try {

                   if ((fa10.getText().length() > 0)

                        && (file1.exists())) {

                      fr = new FileReader(file1);

                      BufferedReader br = new BufferedReader(fr);

                      String tempStr = null;

                      int y = 0, b = 0;

                      for (int i = 0; (tempStr = br.readLine()) != null; i++) {

                        variabl2663[i] = tempStr;

                        y = i;

                      }

                      if (y >= 16) {

                        if (y >= 0)

                           faa0.setText(variabl2663[0]);

                        if (y >= 1)

                           faa1.setText(variabl2663[1]);

                        if (y >= 2)

                           faa2.setText(variabl2663[2]);

                        if (y >= 3)

                           fa0.setText(variabl2663[3]);

                        if (y >= 4)

                           fa1.setText(variabl2663[4]);

                        if (y >= 5)

                           fa2.setText(variabl2663[5]);

                        if (y >= 6)

                           fa3.setText(variabl2663[6]);

                        if (y >= 7)

                           fab0.setText(variabl2663[7]);

                        if (y >= 8)

                           fab1.setText(variabl2663[8]);

                        if (y >= 9)

                           fab2.setText(variabl2663[9]);

                        if (y >= 10)

                           fa4.setText(variabl2663[10]);

                        if (y >= 12)

                           fac2.setText(variabl2663[12]);

                        if (y >= 13)

                           fac3.setText(variabl2663[13]);

                        if (y >= 14)

                           fac4.setText(variabl2663[14]);

                        if (y >= 15)

                           fac5.setText(variabl2663[15]);

                        if (y >= 16)

                           fac6.setText(variabl2663[16]);

                      }

                   } else {

                      if (fa10.getText().length() > 0)

                        file1.createNewFile();

                   }

                } catch (IOException e2) {

                   JOptionPane.showMessageDialog(null, "打开文件错!");

                }

             }

           }

        }

     });

 

     fla0 = new JLabel("表格标题");

     fla0.setBounds(30, 70, 80, 20);

     panel1.add(fla0);

     faa0 = new JTextField("", 20);

     faa0.setBounds(110, 70, 310, 20);

     panel1.add(faa0);

     faa0.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 0;

           list1.removeAll();

        }

     });

     fla1 = new JLabel("表题字体");

     fla1.setBounds(430, 70, 60, 20);

     panel1.add(fla1);

     faa1 = new JTextField("", 20);

     faa1.setBounds(490, 70, 60, 20);

     panel1.add(faa1);

     faa1.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 1;

           list1.removeAll();

           for (int i = 0; i < variabl2629.length; i++) {

             list1.add(variabl2629[i]);

           }

        }

     });

     fla2 = new JLabel("表题字号");

     fla2.setBounds(560, 70, 70, 20);

     panel1.add(fla2);

     faa2 = new JTextField("", 20);

     faa2.setBounds(630, 70, 70, 20);

     panel1.add(faa2);

     faa2.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 2;

           list1.removeAll();

           for (int i = 0; i < variabl2607.length; i++) {

             list1.add(variabl2607[i]);

           }

        }

     });

 

     fl2 = new JLabel("数据字体");

     panel1.add(fl2);

     fa2 = new JTextField("", 20);

     panel1.add(fa2);

     fl2.setBounds(30, 110, 70, 20);

     fa2.setBounds(100, 110, 120, 20);

     fa2.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 5;

           list1.removeAll();

           for (int i = 0; i < variabl2629.length; i++) {

             list1.add(variabl2629[i]);

           }

        }

     });

 

     fl3 = new JLabel("数据字号");

     panel1.add(fl3);

     fa3 = new JTextField("", 20);

     panel1.add(fa3);

     fl3.setBounds(230, 110, 70, 20);

     fa3.setBounds(300, 110, 110, 20);

     fa3.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 6;

           list1.removeAll();

           for (int i = 0; i < variabl2607.length; i++) {

             list1.add(variabl2607[i]);

           }

        }

     });

     fl0 = new JLabel("报表字段名逗号分隔");

     fl0.setBounds(30, 140, 400, 20);

     panel1.add(fl0);

     fa0 = new JTextField("", 20);

     fa0.setBounds(30, 160, 470, 20);

     panel1.add(fa0);

     fa0.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 3;

           list1.removeAll();

           for (int i = 0; i < variabl2651; i++) {

             list1.add(variabl25171[i]);

           }

        }

     });

 

     fl4 = new JLabel("非数字数据类型字段名关键字");

     fl4.setBounds(500, 140, 200, 20);

     panel1.add(fl4);

     fa4 = new JTextField("", 20);

     fa4.setBounds(500, 160, 200, 20);

     panel1.add(fa4);

     fa4.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 11;

           list1.removeAll();

           for (int i = 0; i < variabl2651; i++) {

             list1.add(variabl25171[i]);

           }

        }

     });

 

     fl1 = new JLabel("宽度(逗号分隔)");

     fl1.setBounds(30, 190, 140, 20);

     panel1.add(fl1);

     fa1 = new JTextField("", 20);

     fa1.setBounds(30, 210, 670, 20);

     panel1.add(fa1);

     fa1.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 4;

           list1.removeAll();

        }

     });

 

     flb0 = new JLabel("统计图标题");

     flb0.setBounds(30, 260, 80, 20);

     panel1.add(flb0);

     fab0 = new JTextField("", 20);

     fab0.setBounds(110, 260, 300, 20);

     panel1.add(fab0);

     fab0.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 7;

           list1.removeAll();

        }

     });

     flb1 = new JLabel("图题字体");

     flb1.setBounds(420, 260, 70, 20);

     panel1.add(flb1);

     fab1 = new JTextField("", 20);

     fab1.setBounds(490, 260, 60, 20);

     panel1.add(fab1);

     fab1.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 8;

           list1.removeAll();

           for (int i = 0; i < variabl2629.length; i++) {

             list1.add(variabl2629[i]);

           }

        }

     });

     flb2 = new JLabel("图题字号");

     flb2.setBounds(560, 260, 70, 20);

     panel1.add(flb2);

     fab2 = new JTextField("", 20);

     fab2.setBounds(630, 260, 70, 20);

     panel1.add(fab2);

     fab2.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 9;

           list1.removeAll();

           for (int i = 0; i < variabl2607.length; i++) {

             list1.add(variabl2607[i]);

           }

        }

     });

     flc2 = new JLabel("图形数据字段名(Y轴数据名)");

     flc2.setBounds(450, 300, 200, 20);

     panel1.add(flc2);

     fac2 = new JTextField("", 20);

     fac2.setBounds(450, 330, 200, 20);

     panel1.add(fac2);

     fac2.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 12;

           list1.removeAll();

           for (int i = 0; i < variabl2651; i++) {

             list1.add(variabl25171[i]);

           }

        }

     });

     flc3 = new JLabel("图形类型");

     flc3.setBounds(30, 370, 70, 20);

     panel1.add(flc3);

     fac3 = new JTextField("", 20);

     fac3.setBounds(100, 370, 70, 20);

     panel1.add(fac3);

     fac3.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 13;

           list1.removeAll();

           for (int i = 0; i < variabl2511.length; i++) {

             list1.add(variabl2511[i]);

           }

        }

     });

     flc4 = new JLabel("图形宽度");

     flc4.setBounds(180, 370, 60, 20);

     panel1.add(flc4);

     fac4 = new JTextField("", 20);

     fac4.setBounds(240, 370, 70, 20);

     panel1.add(fac4);

     fac4.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 14;

           list1.removeAll();

           String sk[] = fa1.getText().split(",");

           int wh4 = 0;

           for (int i = 0; i < sk.length; i++)

             wh4 = wh4 + Integer.parseInt(sk[i]);

           fac4.setText(wh4 + "");

        }

     });

     flc5 = new JLabel("图形高度");

     flc5.setBounds(320, 370, 60, 20);

     panel1.add(flc5);

     fac5 = new JTextField("", 20);

     fac5.setBounds(380, 370, 70, 20);

     panel1.add(fac5);

     fac5.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 15;

           list1.removeAll();

           int wh4 = 0;

           if ((faa2.getText().length() > 0)

                && (faa2.getText().compareTo("0") > 0))

             wh4 = Integer.parseInt(faa2.getText());

           if ((fa3.getText().length() > 0)

                && (fa3.getText().compareTo("0") > 0))

             wh4 = wh4 + variabl1853 * Integer.parseInt(fa3.getText());

           else

             wh4 = wh4 + variabl1853 * 20;

           if ((fab2.getText().length() > 0)

                && (fab2.getText().compareTo("0") > 0))

             wh4 = wh4 + Integer.parseInt(fab2.getText());

           wh4 = 800 - wh4;

           fac5.setText(wh4 + "");

        }

     });

     flc6 = new JLabel("统计函数序号");

     flc6.setBounds(460, 370, 100, 20);

     panel1.add(flc6);

     fac6 = new JTextField("", 20);

     fac6.setBounds(560, 370, 120, 20);

     panel1.add(fac6);

     fac6.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 16;

           list1.removeAll();

           list1.add("按记录");

           list1.add("分组求和");

           list1.add("分组平均");

        }

     });

     list1.setBounds(730, 30, 120, 410);

     panel1.add(list1);

     list1.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

           int w1 = 0, w2 = 0;

           if (list1.getSelectedIndex() >= 0) {

             int wh1, wh2, h1, h2;

             String s0 = "", s6 = "";

             switch (variabl1739) {

              case 0:

                if (fa0.getText().length() == 0)

                   s0 = list1.getSelectedItem();

                else

                   s0 = fa0.getText() + "," + list1.getSelectedItem();

                fa0.setText(s0);

                数据表查询结构(s0);

                break;

             case 1:

                faa1.setText(list1.getSelectedItem());

                break;

             case 2:

                faa2.setText(list1.getSelectedItem());

                break;

             case 3:

                wh1 = list1.getSelectedIndex();

                wh2 = variabl1489[wh1];

                s6 = list1.getSelectedItem();

                if (variabl25171[wh1].length() > wh2)

                   wh2 = variabl25171[wh1].length();

                if (fa3.getText().length() > 0)

                   wh2 = wh2 * Integer.parseInt(fa3.getText());

                else

                   wh2 = wh2 * 12;

                if (fa0.getText().length() == 0) {

                   fa0.setText(s6);

                   fa1.setText(wh2 + "");

                } else {

                   fa0.setText(fa0.getText() + "," + s6);

                   fa1.setText(fa1.getText() + "," + wh2);

                }

                if (main1.variabl1545.indexOf("," + variabl1501[wh1]

                      + ",") < 0)

                   if ((fa4.getText().length() == 0))

                      fa4.setText(s6);

                   else

                      fa4.setText(fa4.getText() + "," + s6);

                break;

             case 5:

                fa2.setText(list1.getSelectedItem());

                break;

             case 6:

                fa3.setText(list1.getSelectedItem());

                break;

             case 8:

                fab1.setText(list1.getSelectedItem());

                break;

             case 9:

                fab2.setText(list1.getSelectedItem());

                break;

             case 11:

                wh1 = list1.getSelectedIndex();

                s6 = list1.getSelectedItem();

                wh2 = variabl1489[wh1];

                if (variabl25171[wh1].length() > wh2)

                   wh2 = variabl25171[wh1].length();

                if (fa3.getText().length() > 0)

                   wh2 = wh2 * Integer.parseInt(fa3.getText());

                else

                   wh2 = wh2 * 12;

                if ((fa4.getText().length() == 0))

                   fa4.setText(s6);

                else

                   fa4.setText(fa4.getText() + "," + s6);

                if (("," + fa0.getText() + ",").indexOf("," + s6 + ",") < 0) {

                   if (fa0.getText().length() == 0) {

                      fa0.setText(s6);

                      fa1.setText(wh2 + "");

                   } else {

                      fa0.setText(s6 + "," + fa0.getText());

                      fa1.setText(wh2 + "," + fa1.getText());

                   }

                }

                break;

             case 12:

                fac2.setText(list1.getSelectedItem());

                break;

             case 13:

                fac3.setText(list1.getSelectedIndex() + "");

                break;

             case 16:

                fac6.setText(list1.getSelectedIndex() + "");

                break;

             }

           }

        }

     });

     final JButton creButton = new JButton("格式内容存盘");

     creButton.setBounds(30, 440, 170, 20);

     creButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           char x1 = 10, x2 = 13, x3 = '"', x4 = ',';

           file1 = new File(fa10.getText());

           FileOutputStream fs;

           try {

             fs = new FileOutputStream(file1);

             fs.write((faa0.getText() + x1).getBytes());

             fs.write((faa1.getText() + x1).getBytes());

             fs.write((faa2.getText() + x1).getBytes());

             fs.write((fa0.getText() + x1).getBytes());

             fs.write((fa1.getText() + x1).getBytes());

             fs.write((fa2.getText() + x1).getBytes());

             fs.write((fa3.getText() + x1).getBytes());

             fs.write((fab0.getText() + x1).getBytes());

             fs.write((fab1.getText() + x1).getBytes());

             fs.write((fab2.getText() + x1).getBytes());

             fs.write((fa4.getText() + x1).getBytes());

             fs.write(("0" + x1).getBytes());

             fs.write((fac2.getText() + x1).getBytes());

             fs.write((fac3.getText() + x1).getBytes());

             fs.write((fac4.getText() + x1).getBytes());

             fs.write((fac5.getText() + x1).getBytes());

             fs.write((fac6.getText() + x1).getBytes());

           } catch (IOException e2) {

             JOptionPane.showMessageDialog(null, "写文件错。");

           }

        }

     });

     panel1.add(creButton);

 

     final JButton clearButton = new JButton("清参数文本框");

     clearButton.setBounds(200, 440, 170, 20);

     clearButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           fa1.setText("");

           fa2.setText("0");

           fa4.setText("0");

        }

     });

     panel1.add(clearButton);

 

     final JButton printButton = new JButton("打印预览");

     printButton.setBounds(370, 440, 170, 20);

     printButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           int c = 0, b = 0;

           try {

             con = main1.getConn();

             sta = con.createStatement(

                   ResultSet.TYPE_SCROLL_INSENSITIVE,

                   ResultSet.CONCUR_UPDATABLE);

             s1 = "select " + fa0.getText() + "  from " + variabl2217

                   + variabl2049;

             rs = sta.executeQuery(s1);

             rsmd = rs.getMetaData();

             variabl2651 = rsmd.getColumnCount();

             variabl25171 = new String[variabl2651];

             variabl1501 = new String[variabl2651];

             variabl1489 = new int[variabl2651];

             for (int i = 0; i < variabl2651; i++) {

                variabl25171[i] = rsmd.getColumnName(i + 1);

                variabl1501[i] = rsmd.getColumnTypeName(i + 1);

                variabl1489[i] = rsmd.getColumnDisplaySize(i + 1);

             }

             rs.last();

             variabl1853 = rs.getRow();

             variabl2197 = new String[variabl1853][variabl2651];

             while (c < variabl1853) {

                rs.absolute(c + 1);

                while (b < variabl2651) {

                   variabl2197[c][b] = rs.getString(b + 1);

                   b++;

                }

                c++;

                b = 0;

             }

             rs.close();

             sta.close();

             con.close();

           } catch (SQLException e1) {

             JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

           }

           main1.n = 0;

           statisticalChart1.means(fa10.getText(), variabl2197);

        }

     });

     panel1.add(printButton);

 

     final JButton exitButton = new JButton("退出");

     exitButton.setBounds(540, 440, 170, 20);

     exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           panel1.setVisible(false);

           frame1.setVisible(false);

           frame1.dispose();

        }

     });

     panel1.add(exitButton);

     frame1.add(panel1);

     frame1.setVisible(true);

   }

 

   static void 数据表查询结构(String variabl2217) {

     String[] s10 = null;

     String[] sk = new String[300];

     int n1 = 0, n2 = 0;

     variabl1633 = "";

     variabl2049 = "";

     if (variabl2217.indexOf(",") < 0) {

        try {

           con = main1.getConn();

           sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

                ResultSet.CONCUR_UPDATABLE);

           String s1 = "select * from " + variabl2217;

           rs = sta.executeQuery(s1);

           rsmd = rs.getMetaData();

           variabl2651 = rsmd.getColumnCount();

           variabl25171 = new String[variabl2651];

           variabl1633 = "";

           for (int i = 0; i < variabl2651; i++) {

             variabl25171[i] = rsmd.getColumnName(i + 1);

             sk[i] = variabl25171[i];

             n1++;

             if (variabl1633.length() == 0)

                variabl1633 = variabl25171[i];

             else

                variabl1633 = variabl1633 + "," + variabl25171[i];

           }

           rs.close();

           sta.close();

           con.close();

        } catch (SQLException e1) {

           JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

        }

     } else {

        s10 = variabl2217.split(",");

        String s0 = "", s1 = "", s2 = "";

        int k = 0;

        for (int i = 0; i < s10.length; i++) {

           try {

             con = main1.getConn();

             sta = con.createStatement(

                   ResultSet.TYPE_SCROLL_INSENSITIVE,

                   ResultSet.CONCUR_UPDATABLE);

             s1 = "select * from " + s10[i];

             rs = sta.executeQuery(s1);

             rsmd = rs.getMetaData();

             variabl2651 = rsmd.getColumnCount();

             for (int j = 0; j < variabl2651; j++) {

                s2 = rsmd.getColumnName(j + 1).toLowerCase();

                n2 = n1;

                if (i > 0) {

                   k = 0;

                   for (int j1 = 0; j1 < n2; j1++) {

                      if (sk[j1].equals(s2)) {

                        sk[j1] = s10[i - 1] + "." + sk[j1];

                        if (variabl2049.length() == 0)

                           variabl2049 = " where " + s10[i - 1]

                                + "." + s2 + " = " + s10[i]

                                + "." + s2;

                        else

                           variabl2049 = variabl2049 + " and "

                                + s10[i - 1] + "." + s2 + " = "

                                + s10[i] + "." + s2;

                        sk[n1] = s10[i] + "." + s2 + " as "

                              + (s2 + i);

                        n1++;

                        k = 1;

                        break;

                      }

                   }

                   if (k == 0) {

                      sk[n1] = s2;

                      n1++;

                   }

                } else {

                   sk[n1] = s2;

                   n1++;

                }

             }

             rs.close();

             sta.close();

             con.close();

           } catch (SQLException e1) {

             JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

           }

        }

        variabl1633 = "";

        for (int j1 = 0; j1 < n1; j1++)

           if (variabl1633.length() == 0)

             variabl1633 = sk[j1];

           else

             variabl1633 = variabl1633 + "," + sk[j1];

     }

     int c = 0, b = 0;

     try {

        con = main1.getConn();

        sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

             ResultSet.CONCUR_UPDATABLE);

        s1 = "select " + variabl1633 + "  from " + variabl2217

             + variabl2049;

        rs = sta.executeQuery(s1);

        rsmd = rs.getMetaData();

        variabl2651 = rsmd.getColumnCount();

        variabl25171 = new String[variabl2651];

        variabl1501 = new String[variabl2651];

        variabl1489 = new int[variabl2651];

        for (int i = 0; i < variabl2651; i++) {

           variabl25171[i] = sk[i];

           variabl1501[i] = rsmd.getColumnTypeName(i + 1);

           variabl1489[i] = rsmd.getColumnDisplaySize(i + 1);

        }

        rs.last();

        variabl1853 = rs.getRow();

        variabl2197 = new String[variabl1853][variabl2651];

        while (c < variabl1853) {

           rs.absolute(c + 1);

           while (b < variabl2651) {

             variabl2197[c][b] = rs.getString(b + 1);

             b++;

           }

           c++;

           b = 0;

        }

        rs.close();

        sta.close();

        con.close();

     } catch (SQLException e1) {

        JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

     }

   }

}

99.源码99,部件程序,根据printFormat3.java生成的格式文件打印或打印预览带统计图表格的数据报表。首先打印数据表格,其中生成直方图统计图的为其中数字数据类型字段,可以为一个到多个。针对数据表的每条记录各字段数据生成直方图,形象地比较一条记录中各字段数据大小关系及相关记录中这些字段数据关系。

/**

 * 程序文件名:dataPreview6.java

 * 作者:程学先 

 * 功能:根据printFormat3.java生成的格式文件打印或打印预览带统计图表格的数据报表。

 * 首先打印数据表格,其中生成直方图统计图的为其中数字数据类型字段,可以为一个到多个。

 * 将针对数据表的每条记录各字段数据生成直方图,比较一条记录中各字段数据大小关系。

 * 每条记录的数据组成一组,总组数等于记录条数,

 * 记录条数如果超过20,显示的图形将过于密集,建议选择起始记录号,与打印记录条数,

 * 建议每次打印不超过20条记录(20组柱形图形)。

 * 数字类型数据之外建议字段数尽量少,所有非数字数据类型字段共同称为关键字,

 * 必须输入的参数:表名、关键字、打印格式文件名。

 * 完成时间:20131127

 * 调用语句:dataPreview6.means(parameter);

 * 本程序需要调用公共程序:statisticalChart1.java完成报表打印或预览。

 */

import java.awt.BasicStroke;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import javax.swing.JButton;

import javax.swing.JComponent;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

 

public class dataPreview6 extends JComponent {

   private static JFrame frame1;

   static Connection con;

   private static ResultSetMetaData rsmd;

   private static Statement sta;

   private static Connection cont4;

   private static Statement stat4;

   private static ResultSetMetaData rsmdt4;

   private static ResultSet rs;

   private static String variabl2603;

   private static String s1 = "";

   static int variabl2281 = 0, variabl2371 = 0, variabl1415 = 20;

   private static int variabl1853 = 0, variabl2651 = 0, variabl2305 = 0;

   private static String[] variabl2517;

   private static String[] variabl1997;

   private static String[] variabl1501;

   private static int[] variabl1489;

   private static String[][] variabl2197;

   private static String[] variabl2231;

   static String[] variabl2253;

   static int[] variabl1287;

   static int[][] variabl20232;

   static int[] variabl20231;

   static int variabl1727 = 1000, variabl1783 = 600;

   static int variabl1757 = 100, variabl2055 = variabl1783;

   private static ArrayList<struct1> title = new ArrayList<struct1>();

   private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();

   private static ArrayList<struct3> table1 = new ArrayList<struct3>();

   private static ArrayList<struct4> table2 = new ArrayList<struct4>();

   private static int variabl2681 = 600;

   private static int x1 = 0, y1 = 0, w1 = 0, h1 = 0, variabl2661 = 0,

        variabl2657 = 0;

   private static int variabl2347 = 0;

   private static Graphics2D g2;

   private static Graphics g;

   private static String faa0, faa1, faa2;

   private static String fab0, fab1, fab2;

   private static String fac0, fac1, fac2, fac3, fac4, fac5, fac6;

   private static String fa0, fa1, fa2, fa3, fa10;

   private static String[][] variabl21971 = null;

   private static String variabl2217;

   private static String variabl2049;

   private static String variabl1633 = "";

   private static String variabl1079;

   private static String[] variabl2663;

   private static int variabl18531;

   private static int variabl26511;

 

   static void title() {

     struct2[] variabl2533 = new struct2[tableTitle.size()];

     variabl2661 = Integer.valueOf(tableTitle.get(0).tableTitle[3]);

     variabl2661 = variabl2661 / 2;

     for (int i = 0; i < tableTitle.size(); i++)

        variabl2533[i] = tableTitle.get(i);

     g2.setFont(new Font(variabl2533[0].tableTitle[6], Font.PLAIN, Integer

           .valueOf(variabl2533[0].tableTitle[7])));

     for (int i = 0; i < tableTitle.size(); i++) {

        x1 = variabl2661;

        y1 = variabl2657;

        w1 = Integer.valueOf(variabl2533[i].tableTitle[3]);

        h1 = Integer.valueOf(variabl2533[i].tableTitle[4]);

        g2.drawLine(x1, y1, x1 + w1, y1);

        g2.drawLine(x1, y1, x1, y1 + h1);

        g2.drawString(variabl2533[i].tableTitle[0], variabl2661 + 2,

             variabl2657 + h1);

        if (variabl2533[i].tableTitle[8].equals(""))

           g2.drawLine(x1, y1 + h1, x1 + w1, y1 + h1);

        if (variabl2533[i].tableTitle[9].equals(""))

           g2.drawLine(x1 + w1, y1, x1 + w1, y1 + h1);

        variabl2661 = variabl2661 + w1;

        if ((i < tableTitle.size() - 1)

             && (Integer.valueOf(variabl2533[i].tableTitle[1]) < Integer

                   .valueOf(variabl2533[i + 1].tableTitle[1])))

           variabl2657 = variabl2657 + h1;

     }

     variabl2657 = variabl2657 + h1;

   }

 

   protected void paintComponent(Graphics g1) {

     g = g1;

     g2 = (Graphics2D) g;

     struct1[] variabl2535 = new struct1[title.size()];

     variabl2657 = 0;

     variabl2661 = 0;

     for (int i = 0; i < title.size(); i++) {

        variabl2535[i] = title.get(i);

        g2.setFont(new Font(variabl2535[i].title[8], Font.PLAIN, Integer

             .valueOf(variabl2535[i].title[9])));

        x1 = Integer.valueOf(variabl2535[i].title[6]);

        y1 = Integer.valueOf(variabl2535[i].title[7]);

        g2.drawString(variabl2535[i].title[0], x1, y1);

        variabl2657 = y1 + Integer.valueOf(variabl2535[i].title[5]);

     }

     title();

     struct3[] variabl2685 = new struct3[table1.size()];

     int[] w10 = new int[table1.size()];

     int[] h10 = new int[table1.size()];

     int[] h20 = new int[table1.size()];

     for (int i = 0; i < table1.size(); i++) {

        variabl2685[i] = table1.get(i);

        w10[i] = Integer.valueOf(variabl2685[i].table1[2]);

        h10[i] = Integer.valueOf(variabl2685[i].table1[3]);

        h20[i] = Integer.valueOf(variabl2685[i].table1[5]);

     }

     y1 = variabl2657;

     g2.setFont(new Font(variabl2685[0].table1[4], Font.PLAIN, Integer

           .valueOf(variabl2685[0].table1[5])));

     for (int j = 0; j < variabl1853; j++) {

        x1 = Integer.valueOf(tableTitle.get(0).tableTitle[3]) / 2;

        g2.drawLine(x1, y1, x1, y1 + h1);

        for (int i = 0; i < table1.size(); i++) {

           if (variabl2197[j][i] == null)

             variabl2197[j][i] = " ";

           g2.drawString(variabl2197[j][i], x1 + 2, y1 + h20[i]);

           g2.drawLine(x1, y1 + h10[i], x1 + w10[i], y1 + h10[i]);

           g2.drawLine(x1 + w10[i], y1, x1 + w10[i], y1 + h10[i]);

           x1 = x1 + w10[i];

        }

        y1 = y1 + h10[table1.size() - 1];

        if (y1 >= variabl2681) {

           struct4[] variabl2653 = new struct4[table2.size()];

           for (int i1 = 0; i1 < table2.size(); i1++) {

             variabl2653[i1] = table2.get(i1);

             g2.setFont(new Font(variabl2653[i1].table2[8], Font.PLAIN,

                   Integer.valueOf(variabl2653[i1].table2[9])));

             x1 = Integer.valueOf(variabl2653[i1].table2[6]);

             y1 = Integer.valueOf(variabl2653[i1].table2[7]);

             g2.drawString(variabl2653[i1].table2[0], x1, y1);

             variabl2657 = y1

                   + Integer.valueOf(variabl2653[i1].table2[5]);

           }

           y1 = 640;

           break;

        }

     }

     y1 = y1 + h10[table1.size() - 1];

   }

 

   static void means(String[] parameter) {

     frame1 = new JFrame();

     frame1.setLayout(null);

     frame1.setTitle("图表式报表打印与打印预览程序                                                                                                                                                                                              作者:程学先");

     frame1.setBounds(10, 10, 1000, 660);

     frame1.getContentPane().setLayout(null);

     final JPanel panel1 = new JPanel();

     panel1.setBounds(10, 10, 1000, 660);

     panel1.setLayout(null);

     frame1.getContentPane().add(panel1);

     variabl2603 = parameter[4];

     variabl2049 = parameter[20];

     variabl1079 = parameter[15];

     variabl2663 = new String[37];

     if (variabl1079.length() < 1) {

        final JFileChooser fc = new JFileChooser(".\\");

        fc.showOpenDialog(null);

        if (fc.getSelectedFile() != null) {

           variabl1079 = fc.getSelectedFile().toString();

        }

     }

     File file1 = new File(variabl1079);

     fa10 = variabl1079;

     try {

        if ((variabl1079.length() > 0) && (file1.exists())) {

           FileReader fr = new FileReader(file1);

           BufferedReader br = new BufferedReader(fr);

           String tempStr = null;

           int y = 0, b = 0;

           for (int i = 0; (tempStr = br.readLine()) != null; i++) {

             variabl2663[i] = tempStr;

             y = i;

           }

           if (y >= 16) {

             if (y >= 0)

                faa0 = variabl2663[0];

             if (y >= 1)

                faa1 = variabl2663[1];

             if (y >= 2)

                faa2 = variabl2663[2];

             if (y >= 3)

                fa0 = variabl2663[3];

             if (y >= 4)

                fa1 = variabl2663[4];

             if (y >= 5)

                fa2 = variabl2663[5];

             if (y >= 6)

                fa3 = variabl2663[6];

             if (y >= 7)

                fab0 = variabl2663[7];

             if (y >= 8)

                fab1 = variabl2663[8];

             if (y >= 9)

                fab2 = variabl2663[9];

             if (y >= 10) {

                variabl2253 = variabl2663[10].split(",");

                variabl1287 = new int[variabl2253.length];

             }

             if (y >= 11)

                fac1 = variabl2663[11];

             if (y >= 12)

                fac2 = variabl2663[12];

             if (y >= 13)

                fac3 = variabl2663[13];

             if (y >= 14)

                fac4 = variabl2663[14];

             if (y >= 15)

                fac5 = variabl2663[15];

             if (y >= 16)

                fac6 = variabl2663[16];

           }

        }

     } catch (IOException e2) {

        JOptionPane.showMessageDialog(null, "打开文件错!");

     }

     variabl1633 = fa0;

     variabl2217 = variabl2603;

     数据表查询结构(variabl2603);

     数据表查询数据(variabl2603);

 

     final JButton inButton = new JButton("预览图表");

     inButton.setBounds(340, 520, 170, 20);

     inButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           String[] s7 = new String[variabl1853];

           String[] s6 = new String[variabl1287.length];

           int[] n6 = new int[variabl1287.length];

           for (int j = 0; j < variabl1287.length; j++) {

             s6[j] = variabl2253[j];

             n6[j] = variabl1489[variabl1287[j]];

           }

           for (int i = 0; i < variabl1853; i++) {

             for (int j = 0; j < variabl1287.length; j++) {

                if ((s7[i] == null) || (s7[i].length() == 0))

                   s7[i] = variabl2197[i][variabl1287[j]];

                else

                   s7[i] = s7[i] + ","

                        + variabl2197[i][variabl1287[j]];

             }

           }

           main1.n = 0;

           statisticalChart1.means(fa10, variabl2197);

        }

     });

     panel1.add(inButton);

     final JButton inButton1 = new JButton("打印图表");

     inButton1.setBounds(530, 520, 170, 20);

     inButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           String[] s7 = new String[variabl1853];

           String[] s6 = new String[variabl1287.length];

           int[] n6 = new int[variabl1287.length];

           for (int j = 0; j < variabl1287.length; j++) {

             s6[j] = variabl2253[j];

             n6[j] = variabl1489[variabl1287[j]];

           }

           for (int i = 0; i < variabl1853; i++) {

             for (int j = 0; j < variabl1287.length; j++) {

                if ((s7[i] == null) || (s7[i].length() == 0))

                   s7[i] = variabl2197[i][variabl1287[j]];

                else

                   s7[i] = s7[i] + ","

                        + variabl2197[i][variabl1287[j]];

             }

           }

           main1.n = 1;

           statisticalChart1.means(fa10, variabl2197);

        }

     });

     panel1.add(inButton1);

 

     final JButton exitButton = new JButton("退出");

     exitButton.setBounds(720, 520, 170, 20);

     exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           panel1.setVisible(false);

           frame1.setVisible(false);

           frame1.dispose();

        }

     });

     panel1.add(exitButton);

     frame1.setVisible(true);

   }

 

   static void rectangular() {

     g.setColor(Color.BLACK);

     int variabl1939 = variabl1727;

     int variabl1617 = variabl1783 - 100;

     int variabl1839 = variabl1617 / (variabl1415 + 1);

     int variabl1991 = variabl2281 / (variabl1415);

     int variabl1529 = 60;

      int variabl1437 = variabl2347;

     g2.setStroke(new BasicStroke(2f));

     g.drawLine(variabl1529, variabl1437, variabl1529, variabl1437

           + variabl1617);

     int x = 0;

     int h0;

     for (int i = 0; i <= variabl1415; i++) {

        if (i < variabl1415) {

           h0 = (variabl1415 - i) * variabl1839;

           g.drawString(variabl2281 - (variabl1415 - i - 1) * variabl1991

                + "", variabl1529 - 40, variabl1437 + h0);

           g.drawLine(variabl1529 - 3, variabl1437 + h0, variabl1529 + 3,

                variabl1437 + h0);

        }

     }

     g.setColor(Color.BLACK);

     g.drawLine(variabl1529 - 10, variabl1437 + variabl1617 - 10,

           variabl1529 + variabl1727 - 100, variabl1437 + variabl1617 - 10);

     int variabl1487 = (variabl1727 - 140) / (variabl26511 * 2);

     int variabl14871 = variabl1487 / 4;

     for (int i = 0; i < variabl26511; i++) {

        g.setColor(Color.RED);

        g.drawString(variabl1997[i], variabl1529 + (i * 2 + 1)

             * variabl1487 + variabl14871, variabl1437 + variabl1617 + 6);

        g.fillRect(

             variabl1529 + i * 2 * variabl1487 + variabl1487,

             variabl1437

                   + (variabl1617 - (variabl1617 * variabl20231[i] / variabl2281))

                   + 10, variabl1487, variabl1617 * variabl20231[i]

                   / variabl2281 - 20);

        if (i == variabl26511 - 1) {

           g.fillRect(variabl1757, variabl1437 + variabl1617 + 20, 8, 8);

           g.drawString(variabl2253[0] + "" + variabl2231[variabl2305],

                variabl1757 + 10, variabl1437 + variabl1617 + 30);

        }

        g.setColor(Color.BLACK);

        g.drawString(

             "" + variabl20231[i],

             variabl1529 + (i * 2 + 1) * variabl1487,

             variabl1437

                   + (variabl1617 - (variabl1617 * variabl20231[i] / variabl2281))

                   + 6);

     }

   }

 

   static void rectangulars() {

     variabl2281 = 0;

     for (int i = 0; i < variabl1853; i++)

        for (int j = 0; j < variabl26511; j++) {

           if (variabl20232[i][j] > variabl2281)

             variabl2281 = variabl20232[i][j];

        }

     int variabl2607 = 12;

     g.setFont(new Font("宋体", Font.PLAIN, variabl2607));

     g.setColor(Color.BLACK);

     int variabl1939 = variabl1727;

     int variabl1617 = variabl1783 - 100;

     int variabl1839 = variabl1617 / (variabl1415 + 1);

     int variabl1991 = (variabl2281 - variabl2371) / variabl1415;

     int variabl1529 = 60;

     int variabl1437 = variabl2347;

     g.drawLine(variabl1529, variabl1437, variabl1529, variabl1617

           + variabl1437);

     int h0;

     g.setColor(Color.BLACK);

     for (int i = 0; i <= variabl1415; i++) {

        if (i < variabl1415) {

           h0 = (variabl1415 - i) * variabl1839;

           g.drawString(variabl2281 - (variabl1415 - i - 1) * variabl1991

                + "", variabl1529 - 25, variabl1437 + h0);

           g.drawLine(variabl1529 - 3, variabl1437 + h0, variabl1529 + 3,

                variabl1437 + h0);

        }

     }

     g.setColor(Color.BLACK);

     g.drawLine(variabl1529 - 10, variabl1437 + variabl1617 - 10,

           variabl1529 + variabl1727 - 100, variabl1437 + variabl1617 - 10);

     int variabl1487 = (variabl1727 - 140) / (variabl26511 * 2);

     int variabl14871 = variabl1487 / 4;

     int variabl25611 = variabl1487 / variabl1853;

     variabl1757 = 30;

     for (int i = 0; i < variabl26511; i++) {

        g.setColor(Color.BLACK);

        g.drawString(variabl1997[i], variabl1529 + (i * 2 + 1)

             * variabl1487 + variabl14871, variabl1437 + variabl1617 + 6);

        for (int j = 0; j < variabl1853; j++) {

           color1(j + 1, g);

           g.fillRect(variabl1529 + i * 2 * variabl1487 + variabl1487

                + variabl25611 * j,

                variabl1437

                      + (variabl1617 - (variabl1617

                           * variabl20232[j][i] / variabl2281))

                      + 15, variabl25611, variabl1617

                      * variabl20232[j][i] / variabl2281 - 20);

           if (i == variabl26511 - 1) {

             g.fillRect(variabl1757, variabl1437 + variabl1617 + 20, 8,

                   8);

             g.drawString(

                   (variabl2253[variabl2253.length - 1] + "" + variabl2231[j])

                        .trim(), variabl1757 + 10, variabl1437

                        + variabl1617 + 30);

             variabl1757 = variabl1757

                   + (variabl2253[variabl2253.length - 1] + "" + variabl2231[j])

                        .trim().length() * variabl2607 + 10;

           }

           g.setColor(Color.BLACK);

           g.drawString("" + variabl20232[j][i], variabl1529 + (i * 2 + 1)

                * variabl1487 + variabl25611 * j,

                variabl1437

                      + (variabl1617 - (variabl1617

                           * variabl20232[j][i] / variabl2281))

                      + 6);

        }

     }

   }

 

   static void roundCake() {

     color1(5, g);

     int variabl2635 = 0;

     int[] variabl2505 = new int[variabl20231.length];

     for (int i = 0; i < variabl20231.length; i++)

        variabl2635 = variabl2635 + variabl20231[i];

     for (int i = 0; i < variabl20231.length; i++) {

        variabl2505[i] = 360 * variabl20231[i] / (variabl2635);

     }

     int x = 0, variabl1751 = 0, variabl2087 = 0, y2 = 0, y3 = 0;

     double y1 = 0;

     int k = 0;

     for (int i = 0; i < variabl26511; i++) {

        variabl2087 = variabl1751 + variabl2505[i];

        y1 = ((variabl2087 - variabl1751) / 2 + variabl1751);

        y3 = 250 + (int) (200 * Math.cos(y1 * 3.14 / 180));

        y2 = 250 - (int) (200 * Math.sin(y1 * 3.14 / 180));

        if (y2 < 100)

           y2 = y2 + 30;

        if (y2 > 400)

           y2 = y2 - 20;

        if (y3 > 250)

           y3 = y3 - 30;

        else

           y3 = y3 - 10;

        if (y3 < 100)

           y3 = y3 - 10;

        g.drawString(variabl2517[i], y3, y2);

        variabl1751 = variabl2087;

     }

     variabl1757 = 500;

     variabl2055 = variabl2347 + 100;

     for (int i = 0; i < variabl26511; i++) {

        color1(i + 1, g);

        g.fillRect(variabl1757, variabl2055 - 10, 8, 8);

        g.drawString(variabl2253[0] + "" + variabl2231[variabl2305] + " "

             + variabl20231[i], variabl1757 + 10, variabl2055);

        variabl2055 = variabl2055 + 30;

     }

     variabl1751 = 0;

     variabl2087 = 0;

     y2 = 0;

     y3 = 0;

     for (int i = 0; i < variabl26511; i++) {

        variabl2087 = variabl1751 + variabl2505[i];

        if (i == variabl26511 - 1)

           variabl2087 = 360;

        color1(i + 1, g);

        if (i == variabl26511 - 1)

           variabl2087 = 360;

        if (variabl1751 < 90) {

           if (variabl2087 <= 90)

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751,

                   variabl2087 - variabl1751);

           else if (variabl2087 <= 180) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751, 90);

             g.fillArc(100, variabl2347 + 30, 300, 300, 90,

                   variabl2087 - 90);

           } else if (variabl2087 <= 270) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751, 90);

             g.fillArc(100, variabl2347 + 30, 300, 300, 90, 90);

             g.fillArc(100, variabl2347 + 30, 300, 300, 180,

                   variabl2087 - 180);

           } else if (variabl2087 <= 360) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751, 90);

             g.fillArc(100, variabl2347 + 30, 300, 300, 90, 90);

             g.fillArc(100, variabl2347 + 30, 300, 300, 180, 90);

             g.fillArc(100, variabl2347 + 30, 300, 300, 270,

                   variabl2087 - 270);

           }

        } else if (variabl1751 < 180) {

           if (variabl2087 <= 180) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751,

                   variabl2087 - variabl1751);

           } else if (variabl2087 <= 270) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751,

                   180 - variabl1751);

             g.fillArc(100, variabl2347 + 30, 300, 300, 180,

                   variabl2087 - 180);

           } else if (variabl2087 <= 360) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751,

                   180 - variabl1751);

             g.fillArc(100, variabl2347 + 30, 300, 300, 180, 90);

             g.fillArc(100, variabl2347 + 30, 300, 300, 270,

                   variabl2087 - 270);

           }

        } else if (variabl1751 < 270) {

           if (variabl2087 <= 270) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751,

                   variabl2087 - variabl1751);

           } else if (variabl2087 <= 360) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751,

                   270 - variabl1751);

             g.fillArc(100, variabl2347 + 30, 300, 300, 270,

                   variabl2087 - 270);

           }

        } else if (variabl1751 < 360) {

           if (variabl2087 <= 360) {

             g.fillArc(100, variabl2347 + 30, 300, 300, variabl1751,

                   variabl2087 - variabl1751);

           }

        }

        variabl1751 = variabl2087;

     }

   }

 

   static void brokenLine() {

     g.setColor(Color.BLACK);

     int variabl1939 = variabl1727;

     int variabl1617 = variabl1783 - 100;

     int variabl1839 = variabl1617 / (variabl1415 + 1);

     int variabl1991 = (variabl2281 - variabl2371) / (variabl1415);

     int variabl1529 = 60;

     int variabl1437 = variabl2347 + 10;

     g.drawLine(variabl1529, variabl1437, variabl1529, variabl2347

           + variabl1617 + 10);

     int x = 0;

     int h0;

     for (int i = 0; i <= variabl1415; i++) {

        if (i < variabl1415) {

           h0 = (variabl1415 - i) * variabl1839;

           g.drawString(variabl2281 - (variabl1415 - i - 1) * variabl1991

                + "", variabl1529 - 40, variabl1437 + h0);

           g.drawLine(variabl1529 - 3, variabl1437 + h0, variabl1529 + 3,

                variabl1437 + h0);

        }

     }

     g.setColor(Color.BLACK);

     g.drawLine(variabl1529 - 10, variabl1437 + variabl1617 - 10,

           variabl1529 + variabl1727 - 100, variabl1437 + variabl1617 - 10);

     int variabl1487 = (variabl1727 - 140) / (variabl26511 * 2);

     int variabl14871 = variabl1487 / 4;

     int[] l0 = new int[variabl26511];

     int[] l1 = new int[variabl26511];

     int variabl2513 = 0;

     variabl1757 = 50;

     for (int i = 0; i < variabl26511; i++) {

        g.setColor(Color.RED);

        g.drawString(variabl1997[i], variabl1529 + (i * 2 + 1)

             * variabl1487 + variabl14871 + 10, variabl1437

             + variabl1617 + 6);

        l0[i] = variabl1529 + i * 2 * variabl1487 + variabl1487;

        l1[i] = variabl1437

             + (variabl1617 - (variabl1617 * variabl20231[i] / variabl2281))

             + 15;

        variabl2513++;

        g.fillRect(variabl1757 + 20, variabl1437 + variabl1617 + 20, 8, 8);

        g.drawString(variabl2253[0] + "" + variabl2231[variabl2305],

             variabl1757 + 30, variabl1437 + variabl1617 + 30);

 

        g.setColor(Color.BLACK);

        g.drawString(

             "" + variabl20231[i],

             variabl1529 + (i * 2 + 1) * variabl1487,

             variabl1437

                   + (variabl1617 - (variabl1617 * variabl20231[i] / variabl2281))

                   + 6);

     }

     g2 = (Graphics2D) g;

     g2.setStroke(new BasicStroke(5f));

     g.drawPolyline(l0, l1, variabl2513);

   }

 

   static void color1(int c, Graphics g1) {

     switch (c) {

     case 1:

        g1.setColor(Color.red);

        break;

     case 2:

        g1.setColor(Color.blue);

        break;

     case 3:

        g1.setColor(Color.orange);

        break;

     case 4:

        g1.setColor(Color.green);

        break;

     case 5:

        g1.setColor(Color.black);

        break;

     case 6:

        g1.setColor(Color.cyan);

        break;

     case 7:

        g1.setColor(Color.yellow);

        break;

     case 8:

        g1.setColor(Color.lightGray);

        break;

     case 9:

        g1.setColor(Color.red);

        break;

     case 10:

        g1.setColor(Color.blue);

        break;

     case 11:

        g1.setColor(Color.orange);

        break;

     case 12:

        g1.setColor(Color.green);

        break;

     case 13:

        g1.setColor(Color.black);

        break;

     case 14:

        g1.setColor(Color.cyan);

        break;

     case 15:

        g1.setColor(Color.yellow);

        break;

     case 16:

        g1.setColor(Color.lightGray);

        break;

     case 17:

        g1.setColor(Color.white);

        break;

     }

   }

 

   static void 数据表查询结构(String variabl2217) {

     String[] s10 = null;

     String[] sk = new String[300];

     int n1 = 0, n2 = 0;

     variabl2049 = "";

     main1.driver1();

     if (variabl2217.indexOf(",") < 0) {

        try {

           cont4 = main1.getConn();

           stat4 = cont4.createStatement(

                ResultSet.TYPE_SCROLL_INSENSITIVE,

                ResultSet.CONCUR_UPDATABLE);

           String s1 = "select * from " + variabl2217;

           rs = stat4.executeQuery(s1);

           rsmdt4 = rs.getMetaData();

           variabl2651 = rsmdt4.getColumnCount();

           variabl2517 = new String[variabl2651];

           variabl1501 = new String[variabl2651];

           variabl1489 = new int[variabl2651];

           for (int i = 0; i < variabl2651; i++) {

             variabl2517[i] = rsmdt4.getColumnName(i + 1);

           }

           rs.close();

           stat4.close();

           cont4.close();

        } catch (SQLException e1) {

           JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

        }

     } else {

        s10 = variabl2217.split(",");

        String s0 = "", s1 = "", s2 = "";

        int k = 0;

        for (int i = 0; i < s10.length; i++) {

           try {

             cont4 = main1.getConn();

             stat4 = cont4.createStatement(

                   ResultSet.TYPE_SCROLL_INSENSITIVE,

                   ResultSet.CONCUR_UPDATABLE);

             s1 = "select * from " + s10[i];

             rs = stat4.executeQuery(s1);

             rsmdt4 = rs.getMetaData();

             variabl2651 = rsmdt4.getColumnCount();

             for (int j = 0; j < variabl2651; j++) {

                s2 = rsmdt4.getColumnName(j + 1).toLowerCase();

                n2 = n1;

                if (i > 0) {

                   k = 0;

                   for (int j1 = 0; j1 < n2; j1++) {

                      if (sk[j1].equals(s2)) {

                        sk[j1] = s10[i - 1] + "." + sk[j1];

                        if (variabl2049.length() == 0)

                           variabl2049 = " where " + s10[i - 1]

                                + "." + s2 + " = " + s10[i]

                                + "." + s2;

                        else

                           variabl2049 = variabl2049 + " and "

                                + s10[i - 1] + "." + s2 + " = "

                                + s10[i] + "." + s2;

                        sk[n1] = s10[i] + "." + s2 + " as "

                              + (s2 + i);

                        n1++;

                        k = 1;

                        break;

                      }

                   }

                   if (k == 0) {

                      sk[n1] = s2;

                      n1++;

                   }

                } else {

                   sk[n1] = s2;

                   n1++;

                }

             }

             rs.close();

             stat4.close();

             cont4.close();

           } catch (SQLException e1) {

             JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

           }

        }

     }

   }

 

   static void 数据表查询数据(String variabl2217) {

     int c = 0;

     int b = 0;

     for (int i = variabl2253.length - 1; i >= 0; i--)

       if (("," + variabl1633 + ",").indexOf(variabl2253[i]) < 0)

           variabl1633 = variabl2253[i] + "," + variabl1633;

     try {

        cont4 = main1.getConn();

        stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

             ResultSet.CONCUR_UPDATABLE);

        s1 = "select " + variabl1633 + "  from " + variabl2217

             + variabl2049;

        rs = stat4.executeQuery(s1);

        rsmdt4 = rs.getMetaData();

        variabl2651 = rsmdt4.getColumnCount();

        variabl2517 = new String[variabl2651];

        variabl1501 = new String[variabl2651];

        variabl1489 = new int[variabl2651];

        int k1 = 0;

        for (int i1 = 0; i1 < variabl2651; i1++) {

           variabl2517[i1] = rsmdt4.getColumnName(i1 + 1);

           for (int j1 = 0; j1 < variabl2253.length; j1++)

             if (variabl2253[j1].equals(variabl2517[i1]))

                variabl1287[j1] = i1;

           variabl1501[i1] = rsmdt4.getColumnTypeName(i1 + 1);

           variabl1489[i1] = rsmdt4.getColumnDisplaySize(i1 + 1);

        }

        rs.last();

        variabl1853 = rs.getRow();

        variabl2197 = new String[variabl1853][variabl2651];

        while (c < variabl1853) {

           rs.absolute(c + 1);

           while (b < variabl2651) {

             variabl2197[c][b] = rs.getString(b + 1);

             if ((main1.variabl1545.lastIndexOf("," + variabl1501[b]

                   + ",")) > 0)

                if ((variabl2197[c][b] == null)

                     || (variabl2197[c][b].trim().length() == 0))

                   variabl2197[c][b] = "0";

                else if (variabl2197[c][b] == null)

                   variabl2197[c][b] = "";

             b++;

           }

           c++;

           b = 0;

        }

        rs.close();

        stat4.close();

        cont4.close();

     } catch (SQLException e1) {

        JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

     }

   }

}

100.源码100,公共程序,支持dataPrint5程序打印带统计图的报表表格。

/**

 * 程序文件名:statisticalChart1.java

 * 作者:程学先 

 * 用途:公共程序,支持dataPrint5程序打印带统计图的报表表格。

 * 本程序使用到了jcommon-1.0.16.jarjfreechart-1.0.13.jar包,

 * 需要到官方网站自行下载,并放到P1文件夹下COM文件夹中。

 * 调用语句:statisticalChart1(variabl1079,打印表格之数据,打印统计图之数据,

 * 关键字字段名,关键字字段宽度,统计图图形X轴分组字段名,统计图图形X轴数据标志字段名)

 * 本程序对数据要求较高,请保证表格中数据无空值。

 */

import java.awt.BasicStroke;

import java.awt.BorderLayout;

import java.awt.Canvas;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.GradientPaint;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.awt.print.PageFormat;

import java.awt.print.Printable;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.sql.ResultSet;

import javax.imageio.ImageIO;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JFrame;

import org.jfree.chart.ChartUtilities;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.axis.CategoryAxis;

import org.jfree.chart.axis.CategoryLabelPositions;

import org.jfree.chart.axis.NumberAxis;

import org.jfree.chart.plot.CategoryPlot;

import org.jfree.chart.plot.PlotOrientation;

import org.jfree.chart.renderer.category.BarRenderer;

import org.jfree.chart.title.TextTitle;

import org.jfree.data.category.DefaultCategoryDataset;

import org.jfree.ui.HorizontalAlignment;

 

public class statisticalChart1 extends JFrame implements Printable {

   private static statisticalChart1 frame;

   private PageFormat pf;

   private static PreviewCanvas1 canvas;

   private boolean isPreview = false;

   private boolean previewFlag = false;

   static String variabl2603;

   private static String s1 = "";

   private static int variabl1853, variabl18531;

   private static int variabl2113, variabl21131;

   private static String[][] variabl2197;

   private static String[][] variabl21971;

   private static String path;

   private static int variabl2483 = 0;

   private static String variabl2447;

   private static FileReader fr;

   private static String[] variabl2663;

   private static Graphics2D g2;

   private static Graphics g;

   private static String 数据字段名;

   private static String 分组字段名, variabl2253;

   private static String[] variabl23851 = null;

   private static int[] variabl22531 = null, variabl1287 = null;

   private static String[] variabl1819 = null, variabl18191 = null;

   private static int variabl1523 = 0, variabl1691 = 0;

   private static String[] variabl2385 = null;

   private static String[] variabl2837 = null;

 

   public static void gainReport() {

     variabl2663 = new String[17];

     if (variabl2447.length() < 1) {

        JOptionPane.showMessageDialog(null, "缺文件名!");

        return;

     }

     File file1 = new File(variabl2447);

     try {

        if (file1.exists())

           fr = new FileReader(file1);

        BufferedReader br = new BufferedReader(fr);

        String tempStr = null;

        for (int i = 0; (tempStr = br.readLine()) != null; i++) {

           variabl2663[i] = tempStr;

        }

     } catch (IOException e2) {

        JOptionPane.showMessageDialog(null, "打开文件错!");

     }

   }

 

   static void means(String variabl24470, String[][] variabl21972) {

     variabl2663 = new String[17];

     variabl2447 = variabl24470;

     gainReport();

     variabl1853 = variabl21972.length;

     variabl2253 = variabl2663[10];

     String[] variabl22532 = variabl2253.split(",");

     variabl2385 = variabl2663[3].split(",");

     variabl1819 = variabl2663[4].split(",");

     variabl2197 = new String[variabl1853][variabl2385.length];

     for (int i = 0; i < variabl21972.length; i++) {

        for (int j = 0; j < variabl21972[0].length; j++) {

           variabl2197[i][j] = variabl21972[i][j];

        }

     }

     s1 = "";

     int n1 = variabl2385.length - variabl22532.length;

     数据字段名 = "";

     variabl22531 = new int[variabl22532.length];

     variabl21971 = new String[variabl1853][n1];

     variabl1287 = new int[variabl22532.length];

     variabl18191 = new String[variabl22532.length];

     variabl2837 = new String[variabl1853];

     variabl23851 = new String[variabl22532.length];

     int c1 = 0;

     for (int i = 0; i < variabl2385.length; i++) {

        if (("," + variabl2663[10] + ",").indexOf("," + variabl2385[i]

             + ",") < 0) {

           if (数据字段名.length() == 0)

             数据字段名 = variabl2385[i];

           else

             数据字段名 = 数据字段名 + "," + variabl2385[i];

           for (int j = 0; j < variabl1853; j++) {

             variabl21971[j][c1] = variabl21972[j][i];

           }

           c1++;

        }

        for (int j1 = 0; j1 < variabl22532.length; j1++) {

           if (variabl2385[i].equals(variabl22532[j1])) {

             variabl1287[j1] = i;

             variabl18191[j1] = variabl1819[i];

             variabl22531[j1] = Integer.parseInt(variabl1819[i]);

             variabl23851[j1] = variabl22532[j1];

           }

        }

     }

     for (int j = 0; j < variabl1853; j++) {

        variabl2837[j] = "";

        for (int j1 = 0; j1 < variabl22532.length; j1++) {

           if (j1 == 0)

             variabl2837[j] = variabl21972[j][variabl1287[j1]];

           else

             variabl2837[j] = variabl2837[j] + ","

                   + variabl21972[j][variabl1287[j1]];

        }

     }

     String ss0 = "";

     variabl1523 = 0;

     String[] l0 = null;

     if (variabl1853 > 20) {

        boolean bol1 = true;

        while (bol1) {

           ss0 = JOptionPane

                .showInputDialog("请输入图表显示的起始记录号与欲显示记录数,之间用逗号分隔。");

           l0 = ss0.split(",");

           variabl1523 = Integer.parseInt(l0[0]);

           variabl1691 = Integer.parseInt(l0[1]);

           if (variabl1523 + variabl1691 > variabl1853) {

             JOptionPane.showMessageDialog(null, "所选记录范围超过记录总数:"

                   + variabl1853);

           } else

             bol1 = false;

        }

        variabl1853 = Integer.parseInt(l0[1]);

     }

     variabl2483 = main1.variabl2483;

     variabl2113 = variabl21971[0].length;

     frame = new statisticalChart1();

     frame.setVisible(true);

   }

 

   public statisticalChart1() {

     super();

     JFreeChart chart = createChart();

     path = "a1.jpg";

     int we1 = variabl2483;

     int we2 = Integer.parseInt(variabl2663[15]);

     try {

        ChartUtilities.writeChartAsJPEG(new FileOutputStream(path), chart,

             we1, we2);

     } catch (FileNotFoundException e1) {

        e1.printStackTrace();

     } catch (IOException e1) {

        e1.printStackTrace();

     }

     setTitle(variabl2663[0]);

     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     pf = new PageFormat();

     canvas = new PreviewCanvas1();

     int we3 = Integer.parseInt(variabl2663[6]) + 2;

     int variabl2483 = we1;

     int variabl2503 = we2 + variabl1853 * we3

           + Integer.parseInt(variabl2663[2])

           + Integer.parseInt(variabl2663[9]);

     this.setSize(new Dimension(variabl2483, variabl2503));

     BorderLayout borderLayout = new BorderLayout();

     borderLayout.setHgap(10);

     setLayout(borderLayout);

     canvas.setSize(new Dimension(variabl2483, variabl2503));

     add(canvas, BorderLayout.CENTER);

     final JPanel panel = new JPanel();

     panel.setOpaque(false);

     getContentPane().add(panel, BorderLayout.SOUTH);

     if (main1.n == 1) {

        PrinterJob job = PrinterJob.getPrinterJob();

        if (!job.printDialog()) {

           return;

        }

        job.setPrintable(new Printable() {

           public int print(Graphics graphics, PageFormat pageFormat,

                int pageIndex) throws PrinterException {

             isPreview = true;

             if (pageIndex < 1) {

                statisticalChart1.g = graphics;

                g2 = (Graphics2D) g;

                g2.setStroke(new BasicStroke(1f));

                printPicture(graphics, pageFormat, pageIndex);

                return Printable.PAGE_EXISTS;

             } else {

                return Printable.NO_SUCH_PAGE;

             }

           }

        });

        job.setJobName("打印报表");

        try {

           job.print();

        } catch (PrinterException e1) {

           e1.printStackTrace();

        }

     }

   }

 

   private static JFreeChart createChart() {

     DefaultCategoryDataset dataset = new DefaultCategoryDataset();

     String[] variabl23852 = 数据字段名.split(",");

     for (int i = 0; i < variabl21971.length; i++) {

        for (int j = 0; j < variabl21971[0].length; j++) {

           if ((variabl21971[i][j] == null)

                || (variabl21971[i][j].length() == 0))

             variabl21971[i][j] = 0 + "";

           int value = (int) Double.parseDouble(variabl21971[i][j]);

           String sf1 = variabl23852[j];

           String sf0 = variabl2837[i];

           dataset.addValue(value, sf1, sf0);

        }

     }

     JFreeChart chart = null;

     chart = ChartFactory.createBarChart("\n\n" + variabl2663[7], 分组字段名,

           数据字段名, dataset, PlotOrientation.VERTICAL, true, true, false);

     chart.setBackgroundPaint(Color.white);

     CategoryPlot plot = (CategoryPlot) chart.getPlot();

     NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

     rangeAxis.setTickLabelFont(new Font("Sans-serif", Font.PLAIN, 12));

     rangeAxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));

      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

     BarRenderer renderer = (BarRenderer) plot.getRenderer();

     GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f,

           0.0f, new Color(0, 0, 64));

     GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f,

           0.0f, new Color(0, 64, 0));

     renderer.setSeriesPaint(0, gp0);

     renderer.setSeriesPaint(1, gp1);

     CategoryAxis domainAxis = plot.getDomainAxis();

     domainAxis.setTickLabelFont(new Font("Sans-serif", Font.PLAIN, 20));

     domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 20));

      domainAxis.setCategoryLabelPositions(CategoryLabelPositions

           .createUpRotationLabelPositions(Math.PI / 6.0));

     TextTitle textTitle = chart.getTitle();

    textTitle.setFont(new Font(variabl2663[8], Font.PLAIN, Integer

           .parseInt(variabl2663[9])));

     chart.getLegend().setItemFont(

           new Font(variabl2663[8], Font.PLAIN, Integer

                .parseInt(variabl2663[9])));

      chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);

     return chart;

   }

 

  public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)

        throws PrinterException {

     printPicture(graphics, pageFormat, pageIndex);

     return Printable.PAGE_EXISTS;

   }

 

   class PreviewCanvas1 extends Canvas {

     public void paint(Graphics g) {

        try {

           super.paint(g);

           g2 = (Graphics2D) g;

           g2.translate(10, 10);

           int x = (int) (pf.getImageableX() - 1);

           int y = (int) (pf.getImageableY() - 1);

           int width = (int) (pf.getImageableWidth() + 1);

           int height = (int) (pf.getImageableHeight() + 1);

           int mw = (int) pf.getWidth();

           int mh = (int) pf.getHeight();

           g2.drawRect(0, 0, mw, mh);

          g2.setColor(new Color(255, 253, 234));

           g2.fillRect(1, 1, mw - 1 + 300, mh - 1);

           g2.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND,

               BasicStroke.JOIN_ROUND, 10f, new float[] { 5, 5 }, 0f));

           g2.setColor(Color.BLACK);

           g2.setColor(Color.WHITE);

           g2.fillRect(x + 1, y + 1, width - 1 + 300, height - 1);

           statisticalChart1.this.print(g, pf, 0);

        } catch (PrinterException e) {

           e.printStackTrace();

        }

     }

   }

 

   public void printPicture(Graphics graphics, PageFormat pageFormat,

        int pageIndex) {

     int x = (int) pageFormat.getImageableX() - 20;

     int y = (int) pageFormat.getImageableY();

     int w = (int) pageFormat.getImageableWidth();

     int w1 = 0;

     int w2 = (int) (Integer.parseInt(variabl2663[6]) * 1.5);

     g2 = (Graphics2D) graphics;

     g2.setColor(Color.BLUE);

     g2.setFont(new Font(variabl2663[1], Font.BOLD, Integer

           .parseInt(variabl2663[2])));

     g2.drawString(variabl2663[0], x + 60, y + 30);

     g2.setColor(Color.BLACK);

     g2.setFont(new Font(variabl2663[5], Font.PLAIN, Integer

           .parseInt(variabl2663[6])));

     g2.setStroke(new BasicStroke(1f));

     String[] we5 = variabl2663[3].split(",");

     String[] we6 = variabl2663[4].split(",");

     int[] we7 = new int[we6.length];

     int we8 = Integer.parseInt(variabl2663[6]);

     for (int i = 0; i < we6.length; i++) {

        we7[i] = Integer.parseInt(we6[i]);

     }

     try {

        y = y + 30 + Integer.parseInt(variabl2663[2]);

        int y1 = y;

        int xe1 = x;

        g2.drawLine(xe1, y1 - 20, xe1, y + (variabl1853 - 1) * w2);

        for (int i = 0; i < we6.length; i++) {

           g2.drawLine(xe1, y - 20, xe1 + we7[i], y - 20);

           g2.drawString(we5[i], xe1 + 5, y - 5);

           g2.drawLine(xe1 + we7[i], y1 - 20, xe1 + we7[i], y + 10);

           xe1 = xe1 + we7[i];

        }

        for (int i = 0; i < variabl1853; i++) {

           y1 = y;

           y = y + (int) (Integer.parseInt(variabl2663[6]) * 1.5);

           xe1 = x;

           g2.drawLine(xe1, y1, xe1, y);

           for (int j = 0; j < we6.length; j++) {

             w1 = we7[j];

             g2.drawLine(xe1, y1, xe1 + w1, y1);

             g2.drawString(variabl2197[i][j], xe1 + 5, y - 5);

             g2.drawLine(xe1 + w1, y1, xe1 + w1, y);

             if (i == variabl1853 - 1)

                g2.drawLine(xe1, y, xe1 + w1, y);

             xe1 = xe1 + w1;

           }

        }

        File file = new File("a1.jpg");

        BufferedImage image1 = ImageIO.read(file);

        g2.drawImage(image1, 10, y + 20, 820, 300, this);

     } catch (Exception ex) {

        ex.printStackTrace();

     }

     isPreview = true;

     previewFlag = true;

   }

}




https://blog.sciencenet.cn/blog-2551-1123129.html

上一篇:管理信息系统软件生产线源码95-97
下一篇:管理信息系统软件生产线源码101-103
收藏 IP: 183.94.46.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-9-19 21:58

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部