|||
版本1
87.源码87,部件程序,表单式报表(单记录式报表)打印格式文件设计程序。该类报表可打印文本、图片。
/*
* 程序文件名:printFormat5.java
* 作者:程学先
* 功能:表单式报表(单记录式报表)打印格式文件设计程序。该类报表可打印文本、图片。
* 用于辅助生成打印数据库中单或多数据表的单记录式报表格式文件。
* 为操作简单,设计时输入的所有参数以字符个数为单位,在打印报表中设置的宽度、高度、
* 左边距、到顶距等待填入字符单位数据再点击“辅助计算”根据字号计算其象素单位值。
* 在打印内容部分,要求输入行号、列号,其他数据(包括左边距、到顶距)均自动计算求值。
* 操作时只选字段、修改表头标签内容、选择行号和列号,加入到表格中,输入完毕后点击“辅助计算”。
* 在“辅助计算”前请检查:行号、列号、宽度、高度、字体、字号数据均不得缺失。
* 行号、列号数据应保持连续一致。
* 文本域框与图像框必须输入行号、列号、宽度、高度、字号,
* 注意其行号与其下一行的字段间行号间隔等于其高度。
* 所有数据保存在一个文件中,包括标题部分、打印数据部分、表尾等三部分
* 每组内容第一个数据标志组类型,1表示标题部分;
* 2表示数据内容部分。
* 3表示表尾部分
* 标题部分、表尾部分内容分常量与变量二类,常量照原样打印,
* 总标题、表尾部分属性包括:内容、变量名、行号、列号、宽度、高度、左边距、到顶距、
* 字体、字号等10个参数
* 数据内容部分属性包括:字段或标签名称、行号、列号、宽度、高度、左边距、到顶距、
* 字体、字号、有无下表格线、有无右表格线等11个参数
* 列号指一行内控件个数序号,例如一行内有2个非大数据类型字段、2个大数据类型字段,
* 则列号分别为1、2、3、4。又例如,一行内有2个大数据类型字段,之后有1个非大数据类型字段,
* 列号分别为1、2和3号。注意大数据类型可能占据多行,则每行它们都按其位置分配一个列号。
* 例如,一个大数据类型字段从第4行起占据1号位置,其高度为4个字符,则在4、5、6、7行中
* 它都占据列号1(其后字段从2起安排列号,不过,在加入该大数据字段时自动写入的是0号)。
* 又例如,第2行内有2个非大数据类型字段、2个大数据类型字段,要求2个大数据类型等高,
* 假如均为4个字符高,则在第2、3、4、5行它们都占据列号,不过本程序自动给它编为0号。
* 要求全表数据统一字号。
* 除大数据类型外,一般字段高度都应填:1,即1个字符高,实际象素高度要根据字号计算
* 标签宽度、字段宽度应当为所定义的字符个数,实际象素宽度约等于字号。
* 在一行内如果安排大数据类型的控件且不只一个,要求等高、等到顶距、等字号且连在一起。
* (中间除标签外没有其他控件)。 非大数据类型数据要不全在左边,列号从1起计数;
* 要不全在右边,从2或3起开始计数。
* 布局算法优先考虑大数据类型字段数据位置与大小,之后将其他字段顺序填入
* 从上到下,一个字段如果不是当行第一个字段并且安排得下就予安排。
* 如果不是第一个字段,当行安排不下,就移到下一行安排,如果仍然安排不下,请手工控制。
* 当全部安排之后,首先将第一列标签统一宽度,使某些行总宽度可能加大,通过调整面板宽度解决。
* 如果已经无法通过调整面板宽度解决,请手工控制。
* 最后,统一每一行右边对齐,将每行最右一个字段宽度加大使总的行宽度等于平均行宽度。
* 设计完成存盘之前,请检查每行最大宽度、高度要在屏幕范围内,避免超出屏幕范围。
* 实际窗口大小将依照输入数据情况自动设置。
* 采用高度超过1个字符的文本域控件的字段的数据类型必须为ntext或text。
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.*;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Vector;
public class printFormat5 extends JFrame {
private static printFormat5 frame1 = new printFormat5(); // 定义窗口
private static printFormat5 frame2 = new printFormat5();
private static printFormat5 frame3 = new printFormat5();
private static JPanel panel1 = new JPanel(); // 定义面板
private static JPanel panel2 = new JPanel();
private static JPanel panel3 = new JPanel();
private static DefaultTableModel 表格模型1; // 定义表格模型对象
private static DefaultTableModel 表格模型2;
private static DefaultTableModel 表格模型3;
private static JTable 表格1; // 定义表格对象
private static JTable 表格2;
private static JTable 表格3;
private static JScrollPane scrollPane1 = new JScrollPane(); // 定义表格滚动条
private static JScrollPane scrollPane2 = new JScrollPane();
private static JScrollPane scrollPane3 = new JScrollPane();
private static JScrollPane scrollPaneL1 = new JScrollPane();// 定义列表框滚动条
private static JScrollPane scrollPaneL2 = new JScrollPane();
private static JScrollPane scrollPaneL3 = new JScrollPane();
private static List list1 = new List();
private static List list2 = new List();
private static List list3 = new List();
private static JLabel fl0, fl1, fl2, fl3, fl4, fl5, fl6, fl7, fl8,
fl10, fl11, fl12;
private static JTextField fa0, fa1, fa2, fa3, fa4, fa5, fa6, fa7, fa8,
fa10, fa11, fa12;
private static JLabel fla1, fla2, fla3, fla4, fla5, fla6, fla7, fla8,
fla9,fla11, fla12;
private static JTextField faa1, faa2, faa3, faa4, faa5, faa6, faa7,
faa8, faa9, faa11, faa12;
private static JLabel flb1, flb2, flb3, flb4, flb5, flb6, flb7, flb8,
flb11, flb12;
private static JTextField fab1, fab2, fab3, fab4, fab5, fab6, fab7,
fab8, fab11, fab12;
private static String 当前值;
private static int 当前列号 = 0, 列数 = 0;
private static int 字段序号 = 0;
private static String[][] 表格数据;
private static String[] 列名1; // 数据表中列名
private static String[] 列数据类型;
private static int[] 列数据宽度;
private static File file1;
static Connection con; // 连接数据库
private static Statement sta; // 连接数据库
static String s1 = "", s2 = "";
private static ResultSet rs;
private static ResultSetMetaData rsmd;
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 String 字段名表 = "";
public static void means(String[] parameter) {
frame1 = new printFormat5(); // 定义窗口
frame2 = new printFormat5();
frame3 = new printFormat5();
panel1 = new JPanel(); // 定义面板
panel2 = new JPanel();
panel3 = new JPanel();
scrollPane1 = new JScrollPane(); // 定义表格滚动条
scrollPane2 = new JScrollPane();
scrollPane3 = new JScrollPane();
scrollPaneL1 = new JScrollPane();// 定义列表框滚动条
scrollPaneL2 = new JScrollPane();
scrollPaneL3 = new JScrollPane();
list1 = new List();
list2 = new List();
list3 = new List();
当前列号 = 0;
列数 = 0;
字段序号 = 0;
s1 = "";
s2 = "";
字号 = 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("打印报表标题设计页。 作者:程学先");
frame2.setTitle("单记录数据设计页。 ");
frame3.setTitle("表尾内容设计页。 ");
frame1.setBounds(10, 10, 950, 660); // 窗口位置大小
frame2.setBounds(30, 10, 950, 660);
frame3.setBounds(60, 10, 950, 660);
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 设置窗体的默认关闭模式
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
panel1.setBounds(10, 10, 950, 660); // 定义面板大小与位置
panel2.setBounds(30, 10, 950, 660);
panel3.setBounds(60, 10, 950, 660);
panel1.setLayout(null); // 关闭面板布局管理器
panel2.setLayout(null);
panel3.setLayout(null);
String[] 列名01 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度", "左边距", "到顶距",
"字体", "字号" }; // 定义表格列名数组
String[] 列名02 = { "标签内容", "字段名称", "行号", "列号", "标签宽", "字段宽", "高度",
"左边距", "到顶距", "字体", "字号" };
String[] 列名03 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度", "左边距", "到顶距",
"字体", "字号" };
main1.driver1();
String 表名 = parameter[4];
String 表名表 = parameter[0];
final String [] 表名1 = 表名表.split(",");
数据表查询结构(parameter[4]);
fl0 = new JLabel("数据表名");
fl0.setBounds(40, 10, 80, 20);
panel1.add(fl0);
fa0 = new JTextField("");
fa0.setText(表名);
fa0.setBounds(130, 10, 100, 20);
panel1.add(fa0);
fa0.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 0;
list1.removeAll();
for (int i = 0; i < 表名1.length; i++)
list1.add(表名1[i].toString());
}
});
fl10 = new JLabel("文件名");
fl10.setBounds(250, 10, 50, 20);
panel1.add(fl10);
fa10 = new JTextField("", 20);
fa10.setBounds(300, 10, 100, 20);
panel1.add(fa10);
fa10.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
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 (file1.exists()) {
FileReader fr = new FileReader(file1);
BufferedReader br = new BufferedReader(fr);
String tempStr = null;
for (int i = 0; (tempStr = br.readLine()) != null; i++) {
if (tempStr.substring(0, 2).equals("1,")) {
表格模型1.addRow(tempStr.substring(2,
tempStr.length()).split("。"));
} else if (tempStr.substring(0, 2).equals(
"2,")) {
表格模型2.addRow(tempStr.substring(2,
tempStr.length()).split("。"));
} else if (tempStr.substring(0, 2).equals(
"3,")) {
表格模型3.addRow(tempStr.substring(2,
tempStr.length()).split("。"));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
}
}
}
});
表格模型1 = new DefaultTableModel(表格数据, 列名01);
表格模型2 = new DefaultTableModel(表格数据, 列名02);
表格模型3 = new DefaultTableModel(表格数据, 列名03);
表格1 = new JTable(表格模型1); // 创建指定表格模型的表格
表格2 = new JTable(表格模型2);
表格3 = new JTable(表格模型3);
表格1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);// 设置表格的选择模式为单选
表格2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
表格3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
表格1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int 选中行号 = 表格1.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (表格模型1.getValueAt(选中行号, j) != null)
当前值 = 表格模型1.getValueAt(选中行号, j).toString();
else
当前值 = "";
switch (j) {
case 0:
fa1.setText(当前值.toString());
break;
case 1:
fa2.setText(当前值.toString());
break;
case 2:
fa11.setText(当前值.toString());
break;
case 3:
fa12.setText(当前值.toString());
break;
case 4:
fa3.setText(当前值.toString());
break;
case 5:
fa4.setText(当前值.toString());
break;
case 6:
fa5.setText(当前值.toString());
break;
case 7:
fa6.setText(当前值.toString());
break;
case 8:
fa7.setText(当前值.toString());
break;
case 9:
fa8.setText(当前值.toString());
break;
}
}
}
});
scrollPane1.setBounds(10, 40, 800, 400); // 表格滚动条大小、位置
scrollPane2.setBounds(10, 40, 800, 400);
scrollPane3.setBounds(10, 40, 800, 400);
scrollPane1.setViewportView(表格1); // 表格滚动条加到表格中
scrollPane2.setViewportView(表格2);
scrollPane3.setViewportView(表格3);
panel1.add(scrollPane1, BorderLayout.CENTER);// 面板中加入表格滚动条
panel2.add(scrollPane2, BorderLayout.CENTER);
panel3.add(scrollPane3, BorderLayout.CENTER);
fl1 = new JLabel("内容");
fl1.setBounds(70, 460, 40, 20);
panel1.add(fl1);
fa1 = new JTextField("", 20);
fa1.setBounds(110, 460, 100, 20);
panel1.add(fa1);
fa1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 1;
list1.removeAll();
for (int i = 0; i < 列数; i++) {
list1.add(列名1[i]);
}
}
});
fl2 = new JLabel("变量名");
fl2.setBounds(230, 460, 50, 20);
panel1.add(fl2);
fa2 = new JTextField("", 20);
fa2.setBounds(280, 460, 60, 20);
panel1.add(fa2);
fa2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 2;
list1.removeAll();
for (int i = 0; i < 列数; i++) {
list1.add(列名1[i]);
}
}
});
fl11 = new JLabel("行号");
fl11.setBounds(370, 460, 40, 20);
panel1.add(fl11);
fa11 = new JTextField("", 20);
fa11.setBounds(410, 460, 60, 20);
panel1.add(fa11);
fa11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 11;
list1.removeAll();
}
});
fl12 = new JLabel("列号");
fl12.setBounds(500, 460, 40, 20);
panel1.add(fl12);
fa12 = new JTextField("", 20);
fa12.setBounds(540, 460, 60, 20);
panel1.add(fa12);
fa12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 12;
list1.removeAll();
}
});
fl3 = new JLabel("宽度");
fl3.setBounds(630, 460, 40, 20);
panel1.add(fl3);
fa3 = new JTextField("", 20);
fa3.setBounds(670, 460, 60, 20);
panel1.add(fa3);
fa3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 3;
list1.removeAll();
}
});
fl4 = new JLabel("高度");
fl4.setBounds(760, 460, 40, 20);
panel1.add(fl4);
fa4 = new JTextField("", 20);
fa4.setBounds(800, 460, 60, 20);
panel1.add(fa4);
fa4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 4;
list1.removeAll();
}
});
fl5 = new JLabel("左边距");
fl5.setBounds(60, 500, 50, 20);
panel1.add(fl5);
fa5 = new JTextField("", 20);
fa5.setBounds(110, 500, 100, 20);
panel1.add(fa5);
fa5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 5;
list1.removeAll();
}
});
fl6 = new JLabel("到顶距");
panel1.add(fl6);
fa6 = new JTextField("", 20);
panel1.add(fa6);
fl6.setBounds(220, 500, 60, 20);
fa6.setBounds(280, 500, 60, 20);
fa6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 6;
list1.removeAll();
}
});
fl7 = new JLabel("字体");
panel1.add(fl7);
fa7 = new JTextField("", 20);
panel1.add(fa7);
fl7.setBounds(370, 500, 40, 20);
fa7.setBounds(410, 500, 120, 20);
fa7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 7;
list1.removeAll();
for (int i = 0; i < 字体.length; i++) {
list1.add(字体[i]);
}
}
});
fl8 = new JLabel("字号");
panel1.add(fl8);
fa8 = new JTextField("", 20);
panel1.add(fa8);
fl8.setBounds(560, 500, 40, 20);
fa8.setBounds(600, 500, 100, 20);
fa8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 8;
list1.removeAll();
for (int i = 0; i < 字号.length; i++) {
list1.add(字号[i]);
}
}
});
list1.setBounds(840, 10, 120, 430);
panel1.add(list1);
list1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list1.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
String s0 = "";
switch (当前列号) {
case 0: // 表名
if (fa0.getText().length() == 0)
s0 = list1.getSelectedItem();
else
s0 = fa0.getText() + "," + list1.getSelectedItem();
fa0.setText(s0);
数据表查询结构(s0);
break;
case 1:
fa1.setText(list1.getSelectedItem());
break;
case 2:
fa2.setText(list1.getSelectedItem());
break;
case 3:
fa3.setText(list1.getSelectedItem());
break;
case 4:
fa4.setText(list1.getSelectedItem());
break;
case 5:
fa5.setText(list1.getSelectedItem());
break;
case 6:
fa6.setText(list1.getSelectedItem());
break;
case 7:
fa7.setText(list1.getSelectedItem());
break;
case 8:
fa8.setText(list1.getSelectedItem());
break;
case 11:
fa11.setText(list1.getSelectedItem());
break;
case 12:
fa12.setText(list1.getSelectedItem());
break;
}
}
}
});
final JButton addButton = new JButton("添加到表格中");
addButton.setBounds(50, 540, 120, 20);
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < 表格模型1.getRowCount(); i++) {
if ((表格模型1.getValueAt(i, 0) != null)
&& (表格模型1.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fa1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 < 0) { // 新行
String[] rowValues = { fa1.getText(), fa2.getText(),
fa11.getText(), fa12.getText(), fa3.getText(),
fa4.getText(), fa5.getText(), fa6.getText(),
fa7.getText(), fa8.getText() };
表格模型1.addRow(rowValues);
int rowCount = 表格1.getRowCount() + 1;
fa1.setText("");
fa2.setText("0");
fa3.setText("0");
fa4.setText("0");
fa5.setText("0");
fa6.setText("0");
fa7.setText("");
fa8.setText("0");
fa11.setText("0");
fa12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel1.add(addButton);
final JButton updButton = new JButton("修改表格数据");
updButton.setBounds(170, 540, 120, 20);
updButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1;
for (int i = 0; i < 表格模型1.getRowCount(); i++) {
if ((表格模型1.getValueAt(i, 0) != null)
&& (表格模型1.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fa1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 >= 0) {
表格模型1.setValueAt(fa1.getText(), 选中行号, 0);
表格模型1.setValueAt(fa2.getText(), 选中行号, 1);
表格模型1.setValueAt(fa11.getText(), 选中行号, 2);
表格模型1.setValueAt(fa12.getText(), 选中行号, 3);
表格模型1.setValueAt(fa3.getText(), 选中行号, 4);
表格模型1.setValueAt(fa4.getText(), 选中行号, 5);
表格模型1.setValueAt(fa5.getText(), 选中行号, 6);
表格模型1.setValueAt(fa6.getText(), 选中行号, 7);
表格模型1.setValueAt(fa7.getText(), 选中行号, 8);
表格模型1.setValueAt(fa8.getText(), 选中行号, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel1.add(updButton);
final JButton delButton = new JButton("从表格中删除");
delButton.setBounds(290, 540, 120, 20);
delButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = 表格1.getSelectedRow();
if (选中行号 != -1)
表格模型1.removeRow(选中行号);
}
});
panel1.add(delButton);
final JButton countButton = new JButton("辅助计算");
countButton.setBounds(410, 540, 120, 20);
countButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 数据条数 = 表格模型1.getRowCount();
String[][] 数据 = new String[数据条数][11];
int[][] 数据1 = new int[数据条数][11];
for (int i = 0; i < 数据条数; i++) {
for (int j = 0; j < 10; j++)
数据[i][j] = 表格模型1.getValueAt(i, j).toString().trim();
for (int j = 4; j < 10; j++) {
if (j != 8) {
if (数据[i][j].length() > 0)
数据1[i][j] = Integer.valueOf(数据[i][j]);
else
数据1[i][j] = 0;
}
}
for (int j = 4; j < 8; j++) {
if (j != 5)
数据1[i][j] = 数据1[i][j] * 数据1[i][9];
else
数据1[i][j] = (int) (数据1[i][j] * 数据1[i][9] * 1.12);
数据[i][j] = "" + 数据1[i][j];
}
}
表格模型1.setRowCount(0);
for (int i = 0; i < 数据条数; i++)
表格模型1.addRow(数据[i]);
}
});
panel1.add(countButton);
final JButton creButton = new JButton("表格内容存盘");
creButton.setBounds(530, 540, 120, 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);
for (int i = 0; i < 表格模型1.getRowCount(); i++) {
String s3 = "1,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((表格模型1.getValueAt(i, j) != null)
&& (表格模型1.getValueAt(i, j).toString()
.length() > 0))
s3 = s3 + 表格模型1.getValueAt(i, j).toString()
+ "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
for (int i = 0; i < 表格模型2.getRowCount(); i++) {
String s3 = "2,", s4 = "";
for (int j = 0; j < 11; j++) {
if ((表格模型2.getValueAt(i, j) != null)
&& (表格模型2.getValueAt(i, j).toString()
.length() > 0))
s3 = s3 + 表格模型2.getValueAt(i, j).toString()
+ "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
for (int i = 0; i < 表格模型3.getRowCount(); i++) {
String s3 = "3,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((表格模型3.getValueAt(i, j) != null)
&& (表格模型3.getValueAt(i, j).toString()
.length() > 0))
s3 = s3 + 表格模型3.getValueAt(i, j).toString()
+ "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
fs.close();
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "写文件错。");
}
}
});
panel1.add(creButton);
final JButton clearButton = new JButton("清参数文本框");
clearButton.setBounds(650, 540, 120, 20);
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fa1.setText("");
fa2.setText("0");
fa3.setText("0");
fa4.setText("0");
fa5.setText("0");
fa6.setText("0");
fa7.setText("");
fa8.setText("0");
fa11.setText("0");
fa12.setText("0");
}
});
panel1.add(clearButton);
final JButton exitButton = new JButton("退出");
exitButton.setBounds(770, 540, 120, 20);
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
panel1.setVisible(false);
frame1.setVisible(false);
frame1.dispose();
frame2.setVisible(false);
frame2.dispose();
frame3.setVisible(false);
frame3.dispose();
}
});
panel1.add(exitButton);
fla1 = new JLabel("标签内容");
fla1.setBounds(20, 460, 60, 20);
panel2.add(fla1);
faa1 = new JTextField("", 20);
faa1.setBounds(80, 460, 100, 20);
panel2.add(faa1);
faa1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 1;
list2.removeAll();
for (int i = 0; i < 列数; i++) {
list2.add(列名1[i]);
}
}
});
fla2 = new JLabel("字段名称");
fla2.setBounds(180, 460, 60, 20);
panel2.add(fla2);
faa2 = new JTextField("", 20);
faa2.setBounds(240, 460, 100, 20);
panel2.add(faa2);
faa2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 2;
list2.removeAll();
for (int i = 0; i < 列数; i++) {
list2.add(列名1[i]);
}
}
});
fla11 = new JLabel("行号");
fla11.setBounds(340, 460, 40, 20);
panel2.add(fla11);
faa11 = new JTextField("", 20);
faa11.setBounds(380, 460, 60, 20);
panel2.add(faa11);
faa11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 11;
list2.removeAll();
}
});
fla12 = new JLabel("列号");
fla12.setBounds(440, 460, 40, 20);
panel2.add(fla12);
faa12 = new JTextField("", 20);
faa12.setBounds(480, 460, 60, 20);
panel2.add(faa12);
faa12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 12;
list2.removeAll();
}
});
fla3 = new JLabel("标签宽度");
fla3.setBounds(540, 460, 60, 20);
panel2.add(fla3);
faa3 = new JTextField("", 20);
faa3.setBounds(600, 460, 60, 20);
panel2.add(faa3);
faa3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 3;
list2.removeAll();
}
});
fla4 = new JLabel("字段宽度");
fla4.setBounds(680, 460, 60, 20);
panel2.add(fla4);
faa4 = new JTextField("", 20);
faa4.setBounds(740, 460, 60, 20);
panel2.add(faa4);
faa4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 4;
list2.removeAll();
}
});
fla5 = new JLabel("高度");
fla5.setBounds(20, 500, 60, 20);
panel2.add(fla5);
faa5 = new JTextField("", 20);
faa5.setBounds(80, 500, 100, 20);
panel2.add(faa5);
faa5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 5;
list2.removeAll();
}
});
fla6 = new JLabel("左边距");
fla6.setBounds(200, 500, 40, 20);
panel2.add(fla6);
faa6 = new JTextField("", 20);
faa6.setBounds(240, 500, 80, 20);
panel2.add(faa6);
faa6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 6;
list2.removeAll();
}
});
fla7 = new JLabel("到顶距");
fla7.setBounds(340, 500, 40, 20);
panel2.add(fla7);
faa7 = new JTextField("", 20);
faa7.setBounds(380, 500, 80, 20);
panel2.add(faa7);
faa7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 7;
list2.removeAll();
}
});
fla8 = new JLabel("字体");
panel2.add(fla8);
faa8 = new JTextField("", 20);
panel2.add(faa8);
fla8.setBounds(480, 500, 40, 20);
faa8.setBounds(520, 500, 80, 20);
faa8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 8;
list2.removeAll();
for (int i = 0; i < 字体.length; i++) {
list2.add(字体[i]);
}
}
});
fla9 = new JLabel("字号");
panel2.add(fla9);
faa9 = new JTextField("", 20);
panel2.add(faa9);
fla9.setBounds(620, 500, 40, 20);
faa9.setBounds(660, 500, 80, 20);
faa9.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 9;
for (int i = 0; i < 字号.length; i++) {
list2.add(字号[i]);
}
}
});
faa1.setText(" ");
faa2.setText(" ");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("0");
faa8.setText("宋体");
faa9.setText("0");
faa11.setText("0");
faa12.setText("0");
list2.setBounds(840, 10, 120, 430);
panel2.add(list2);
list2.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list2.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (当前列号) {
case 1:
faa1.setText(list2.getSelectedItem());
faa2.setText(list2.getSelectedItem());
字段序号 = list2.getSelectedIndex();
if (((main1.文本数据类型 + main1.图形数据类型).lastIndexOf(","
+ 列数据类型[字段序号])) < 0) {
faa4.setText("" + 列数据宽度[字段序号]);
faa3.setText("" + 列名1[字段序号].length());
faa5.setText("1");
}
faa8.setText("宋体");
faa9.setText("12");
break;
case 2: // 字段名
faa2.setText(list2.getSelectedItem());
break;
case 3:
faa3.setText(list2.getSelectedItem());
break;
case 4:
faa4.setText(list2.getSelectedItem());
break;
case 5:
faa5.setText(list2.getSelectedItem());
break;
case 6:
faa6.setText(list2.getSelectedItem());
break;
case 7:
faa7.setText(list2.getSelectedItem());
break;
case 8:
faa8.setText(list2.getSelectedItem());
break;
case 9:
faa9.setText(list2.getSelectedItem());
break;
case 11:
faa11.setText(list2.getSelectedItem());
break;
case 12:
faa12.setText(list2.getSelectedItem());
break;
}
}
}
});
表格2.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int 选中行号 = 表格2.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (表格模型2.getValueAt(选中行号, j) != null)
当前值 = 表格模型2.getValueAt(选中行号, j).toString();
else
当前值 = "";
switch (j) {
case 0:
faa1.setText(当前值.toString());
break;
case 2:
faa11.setText(当前值.toString());
break;
case 3:
faa12.setText(当前值.toString());
break;
case 1:
faa2.setText(当前值.toString());
break;
case 4:
faa3.setText(当前值.toString());
break;
case 5:
faa4.setText(当前值.toString());
break;
case 6:
faa5.setText(当前值.toString());
break;
case 7:
faa6.setText(当前值.toString());
break;
case 8:
faa7.setText(当前值.toString());
break;
case 9:
faa8.setText(当前值.toString());
break;
case 10:
faa9.setText(当前值.toString());
break;
}
}
}
});
final JButton addButton1 = new JButton("添加到表格中");
addButton1.setBounds(50, 540, 170, 20);
addButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < 表格模型2.getRowCount(); i++) {
if ((表格模型2.getValueAt(i, 0) != null)
&& (表格模型2.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(faa1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 < 0) { // 新行
String[] rowValues = { faa1.getText(), faa2.getText(),
faa11.getText(), faa12.getText(), faa3.getText(),
faa4.getText(), faa5.getText(), faa6.getText(),
faa7.getText(), faa8.getText(), faa9.getText() };
表格模型2.addRow(rowValues);
faa1.setText(" ");
faa2.setText(" ");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("0");
faa8.setText("宋体");
faa9.setText("0");
faa11.setText("0");
faa12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel2.add(addButton1);
final JButton updButton1 = new JButton("修改表格数据");
updButton1.setBounds(220, 540, 170, 20);
updButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1;
for (int i = 0; i < 表格模型2.getRowCount(); i++) {
if ((表格模型2.getValueAt(i, 0) != null)
&& (表格模型2.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(faa1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 >= 0) {
表格模型2.setValueAt(faa1.getText(), 选中行号, 0);
表格模型2.setValueAt(faa11.getText(), 选中行号, 2);
表格模型2.setValueAt(faa12.getText(), 选中行号, 3);
表格模型2.setValueAt(faa2.getText(), 选中行号, 1);
表格模型2.setValueAt(faa3.getText(), 选中行号, 4);
表格模型2.setValueAt(faa4.getText(), 选中行号, 5);
表格模型2.setValueAt(faa5.getText(), 选中行号, 6);
表格模型2.setValueAt(faa6.getText(), 选中行号, 7);
表格模型2.setValueAt(faa7.getText(), 选中行号, 8);
表格模型2.setValueAt(faa8.getText(), 选中行号, 9);
表格模型2.setValueAt(faa9.getText(), 选中行号, 10);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel2.add(updButton1);
final JButton delButton1 = new JButton("从表格中删除");
delButton1.setBounds(390, 540, 170, 20);
delButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = 表格2.getSelectedRow();
if (选中行号 != -1)
表格模型2.removeRow(选中行号);
}
});
panel2.add(delButton1);
final JButton countButton1 = new JButton("辅助计算");
countButton1.setBounds(560, 540, 170, 20);
countButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] 一条记录 = new String[11];
int 高 = 0, 行 = 0, 列 = 0;
int 大数据高度 = 0;
int 总行数 = 0;
int[] 第i行标志1 = new int[150];
int[] 第i行标志2 = new int[150];
int 标签宽度 = 0;
for (int i = 0; i < 表格模型2.getRowCount(); i++) {
列 = Integer.valueOf(表格模型2.getValueAt(i, 3).toString());
if ((列 == 1)
&& (Integer.valueOf(表格模型2.getValueAt(i, 4)
.toString()) > 标签宽度))
标签宽度 = Integer.valueOf(表格模型2.getValueAt(i, 4)
.toString());
}
for (int i = 0; i < 表格模型2.getRowCount(); i++) {
if (Integer.valueOf(表格模型2.getValueAt(i, 3).toString()) == 1) {
表格模型2.setValueAt("" + 标签宽度, i, 4);
}
}
for (int i = 0; i < 表格模型2.getRowCount(); i++) {
高 = Integer.valueOf(表格模型2.getValueAt(i, 6).toString());
行 = Integer.valueOf(表格模型2.getValueAt(i, 2).toString());
列 = Integer.valueOf(表格模型2.getValueAt(i, 3).toString());
if (行 > 总行数)
总行数 = 行;
if (高 > 1) {
for (int j = 1; j < 11; j++)
一条记录[j] = 表格模型2.getValueAt(i, j).toString();
if ((列 == 1) || (列 == 2 && 第i行标志1[行] == 1)) {
if (第i行标志1[行] == 0)
第i行标志1[行] = 1;
for (int j = 1; j < 高; j++) {
一条记录[3] = "0";
一条记录[2] = (行 + j) + "";
if (行 + j > 总行数)
总行数 = 行 + j;
一条记录[6] = "1";
表格模型2.addRow(一条记录);
}
} else {
if (第i行标志1[行] == 0)
第i行标志1[行] = 行 + 1;
第i行标志2[行] = 高;
for (int j = 1; j < 高; j++) {
一条记录[3] = "98";
一条记录[2] = (行 + j) + "";
第i行标志2[行 + j] = 高;
if (行 + j > 总行数)
总行数 = 行 + j;
一条记录[6] = "1";
表格模型2.addRow(一条记录);
}
}
}
}
int 数据条数 = 表格模型2.getRowCount();
String[][] 数据 = new String[数据条数][15];
int[][] 数据1 = new int[数据条数][15];
int n1 = 0;
for (int i = 0; i < 数据条数; i++) {
for (int j = 1; j < 11; j++) {
if (表格模型2.getValueAt(i, j) != null) {
数据[i][j - 1] = 表格模型2.getValueAt(i, j).toString();
} else
数据[i][j - 1] = "0";
if (表格模型2.getValueAt(i, 0) == null)
数据[i][12] = " ";
else
数据[i][12] = 表格模型2.getValueAt(i, 0).toString();
s2 = 数据[i][j - 1].trim();
if ((j > 1) && (j < 9) || (j == 10))
if ((s2 == null) || (s2.length() < 1))
数据1[i][j - 1] = 0;
else
数据1[i][j - 1] = Integer.valueOf(s2);
}
数据[i][11] = "" + i;
数据1[i][11] = i;
}
String trim = "";
int trim1 = 0;
for (int i = 0; i < 数据条数 - 1; i++) {
for (int j = 0; j < 数据条数 - 1 - i; j++) {
if (数据1[j][1] * 100 + 数据1[j][2] > 数据1[j + 1][1] * 100
+ 数据1[j + 1][2]) {
for (int k = 0; k < 15; k++) {
trim = 数据[j][k];
trim1 = 数据1[j][k];
数据[j][k] = 数据[j + 1][k];
数据1[j][k] = 数据1[j + 1][k];
数据[j + 1][k] = trim;
数据1[j + 1][k] = trim1;
}
}
}
}
int[] 第i行列数 = new int[总行数 + 1];
int[] 第i行宽度 = new int[总行数 + 1];
int[] 第i行末列序号 = new int[数据1.length];
int kuand = 0;
for (int i = 0; i < 数据1.length; i++) {
行 = 数据1[i][1];
列 = 数据1[i][2];
if (第i行标志2[行] > 0) {
if ((列 < 98) && (数据1[i][5] < 2)) {
if (列 > 第i行列数[行]) {
第i行列数[行] = 列;
第i行末列序号[行] = i;
}
第i行宽度[行] = 第i行宽度[行] + 数据1[i][3] + 数据1[i][4];
if (第i行宽度[行] > kuand)
kuand = 第i行宽度[行];
}
}
}
for (int i = 0; i < 数据1.length; i++) {
行 = 数据1[i][1];
列 = 数据1[i][2];
if (第i行标志2[行] > 0) {
for (int k1 = 1; k1 <= 总行数; k1++) {
if ((第i行末列序号[k1] > 0) && (第i行末列序号[k1] == i)) {
数据1[i][4] = 数据1[i][4] + kuand - 第i行宽度[k1];
break;
}
}
}
}
第i行列数 = new int[总行数 + 1];
第i行宽度 = new int[总行数 + 1];
第i行末列序号 = new int[数据1.length];
kuand = 0;
for (int i = 0; i < 数据1.length; i++) {
行 = 数据1[i][1];
列 = 数据1[i][2];
if (列 >= 第i行列数[行]) {
第i行列数[行] = 列;
第i行末列序号[行] = i;
}
第i行宽度[行] = 第i行宽度[行] + 数据1[i][3] + 数据1[i][4];
if (第i行宽度[行] > kuand)
kuand = 第i行宽度[行];
}
for (int k1 = 0; k1 <= 总行数; k1++) {
int k3 = 第i行末列序号[k1];
if (k3 > 0) {
数据1[k3][4] = 数据1[k3][4] + kuand - 第i行宽度[k1];
}
}
int m1 = 0;
行 = 0;
for (int i = 0; i < 数据1.length; i++) {
if (数据1[i][1] != 行) {
行 = 数据1[i][1];
m1 = 0;
}
数据1[i][6] = m1;
m1 = m1 + 数据1[i][3] + 数据1[i][4];
数据1[i][7] = 数据1[i][1] - 1;
}
表格模型2.setRowCount(0);
for (int i = 0; i < 数据1.length; i++) {
if ((数据1[i][2] > 0) && (数据1[i][2] < 98)) {
数据[i][1] = 数据1[i][1] + "";
数据[i][2] = 数据1[i][2] + "";
数据[i][3] = 数据1[i][3] * 数据1[i][9] + "";
数据[i][4] = 数据1[i][4] * 数据1[i][9] + "";
数据[i][5] = (int) (数据1[i][5] * 数据1[i][9] * 2) + "";
数据[i][6] = 数据1[i][6] * 数据1[i][9] + "";
数据[i][7] = (int) (数据1[i][7] * 数据1[i][9] * 2) + "";
}
}
for (int i = 0; i < 数据1.length; i++) {
if ((数据1[i][2] > 0) && (数据1[i][2] < 98)) {
for (int j = 1; j < 11; j++) {
一条记录[j] = 数据[i][j - 1];
}
一条记录[0] = 数据[i][12];
表格模型2.addRow(一条记录);
}
}
}
});
panel2.add(countButton1);
final JButton clearButton1 = new JButton("清参数文本框");
clearButton1.setBounds(730, 540, 170, 20);
clearButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
faa1.setText(" ");
faa2.setText(" ");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("0");
faa8.setText("宋体");
faa9.setText("0");
faa11.setText("0");
faa12.setText("0");
}
});
panel2.add(clearButton1);
flb1 = new JLabel("内容");
flb1.setBounds(70, 460, 40, 20);
panel3.add(flb1);
fab1 = new JTextField("", 20);
fab1.setBounds(110, 460, 100, 20);
panel3.add(fab1);
fab1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 1;
list3.removeAll();
}
});
flb2 = new JLabel("变量名");
flb2.setBounds(230, 460, 50, 20);
panel3.add(flb2);
fab2 = new JTextField("", 20);
fab2.setBounds(280, 460, 60, 20);
panel3.add(fab2);
fab2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 2;
list3.removeAll();
}
});
flb11 = new JLabel("行号");
flb11.setBounds(370, 460, 40, 20);
panel3.add(flb11);
fab11 = new JTextField("", 20);
fab11.setBounds(410, 460, 60, 20);
panel3.add(fab11);
fab11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 11;
list3.removeAll();
}
});
flb12 = new JLabel("列号");
flb12.setBounds(500, 460, 40, 20);
panel3.add(flb12);
fab12 = new JTextField("", 20);
fab12.setBounds(540, 460, 60, 20);
panel3.add(fab12);
fab12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 12;
list3.removeAll();
}
});
flb3 = new JLabel("宽度");
flb3.setBounds(630, 460, 40, 20);
panel3.add(flb3);
fab3 = new JTextField("", 20);
fab3.setBounds(670, 460, 60, 20);
panel3.add(fab3);
fab3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 3;
list3.removeAll();
}
});
flb4 = new JLabel("高度");
flb4.setBounds(760, 460, 40, 20);
panel3.add(flb4);
fab4 = new JTextField("", 20);
fab4.setBounds(800, 460, 60, 20);
panel3.add(fab4);
fab4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 4;
list3.removeAll();
}
});
flb5 = new JLabel("左边距");
flb5.setBounds(60, 500, 50, 20);
panel3.add(flb5);
fab5 = new JTextField("", 20);
fab5.setBounds(110, 500, 100, 20);
panel3.add(fab5);
fab5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 5;
list3.removeAll();
}
});
flb6 = new JLabel("到顶距");
panel3.add(flb6);
fab6 = new JTextField("", 20);
panel3.add(fab6);
flb6.setBounds(220, 500, 60, 20);
fab6.setBounds(280, 500, 60, 20);
fab6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 6;
list3.removeAll();
}
});
flb7 = new JLabel("字体");
panel3.add(flb7);
fab7 = new JTextField("", 20);
panel3.add(fab7);
flb7.setBounds(370, 500, 40, 20);
fab7.setBounds(410, 500, 120, 20);
fab7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 7;
list3.removeAll();
for (int i = 0; i < 字体.length; i++) {
list3.add(字体[i]);
}
}
});
flb8 = new JLabel("字号");
panel3.add(flb8);
fab8 = new JTextField("", 20);
panel3.add(fab8);
flb8.setBounds(560, 500, 40, 20);
fab8.setBounds(600, 500, 100, 20);
fab8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 8;
list3.removeAll();
for (int i = 0; i < 字号.length; i++) {
list3.add(字号[i]);
}
}
});
list3.setBounds(840, 10, 170, 430);
panel3.add(list3);
list3.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list3.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (当前列号) {
case 1:
fab1.setText(list3.getSelectedItem());
break;
case 2:
fab2.setText(list3.getSelectedItem());
break;
case 3:
fab3.setText(list3.getSelectedItem());
break;
case 4:
fab4.setText(list3.getSelectedItem());
break;
case 5:
fab5.setText(list3.getSelectedItem());
break;
case 6:
fab6.setText(list3.getSelectedItem());
break;
case 7:
fab7.setText(list3.getSelectedItem());
break;
case 8:
fab8.setText(list3.getSelectedItem());
break;
case 11:
fab11.setText(list3.getSelectedItem());
break;
case 12:
fab12.setText(list3.getSelectedItem());
break;
}
}
}
});
表格3.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int 选中行号 = 表格3.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (表格模型3.getValueAt(选中行号, j) != null)
当前值 = 表格模型3.getValueAt(选中行号, j).toString();
else
当前值 = "";
switch (j) {
case 0:
fab1.setText(当前值.toString());
break;
case 1:
fab2.setText(当前值.toString());
break;
case 2:
fab11.setText(当前值.toString());
break;
case 3:
fab12.setText(当前值.toString());
break;
case 4:
fab3.setText(当前值.toString());
break;
case 5:
fab4.setText(当前值.toString());
break;
case 6:
fab5.setText(当前值.toString());
break;
case 7:
fab6.setText(当前值.toString());
break;
case 8:
fab7.setText(当前值.toString());
break;
case 9:
fab8.setText(当前值.toString());
break;
}
}
}
});
final JButton addButton3 = new JButton("添加到表格中");
addButton3.setBounds(50, 540, 170, 20);
addButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < 表格模型3.getRowCount(); i++) {
if ((表格模型3.getValueAt(i, 0) != null)
&& (表格模型3.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fab1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 < 0) { // 新行
String[] rowValues = { fab1.getText(), fab2.getText(),
fab11.getText(), fab12.getText(), fab3.getText(),
fab4.getText(), fab5.getText(), fab6.getText(),
fab7.getText(), fab8.getText() };
表格模型3.addRow(rowValues);
int rowCount = 表格3.getRowCount() + 1;
fab1.setText("");
fab2.setText("0");
fab3.setText("0");
fab4.setText("0");
fab5.setText("0");
fab6.setText("0");
fab7.setText("");
fab8.setText("0");
fab11.setText("0");
fab12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel3.add(addButton3);
final JButton updButton3 = new JButton("修改表格数据");
updButton3.setBounds(220, 540, 170, 20);
updButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1;
for (int i = 0; i < 表格模型3.getRowCount(); i++) {
if ((表格模型3.getValueAt(i, 0) != null)
&& (表格模型3.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fab1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 >= 0) {
表格模型3.setValueAt(fab1.getText(), 选中行号, 0);
表格模型3.setValueAt(fab2.getText(), 选中行号, 1);
表格模型3.setValueAt(fab11.getText(), 选中行号, 2);
表格模型3.setValueAt(fab12.getText(), 选中行号, 3);
表格模型3.setValueAt(fab3.getText(), 选中行号, 4);
表格模型3.setValueAt(fab4.getText(), 选中行号, 5);
表格模型3.setValueAt(fab3.getText(), 选中行号, 6);
表格模型3.setValueAt(fab6.getText(), 选中行号, 7);
表格模型3.setValueAt(fab7.getText(), 选中行号, 8);
表格模型3.setValueAt(fab8.getText(), 选中行号, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel3.add(updButton3);
final JButton delButton3 = new JButton("从表格中删除");
delButton3.setBounds(390, 540, 170, 20);
delButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = 表格3.getSelectedRow();
if (选中行号 != -1)
表格模型3.removeRow(选中行号);
}
});
panel3.add(delButton3);
final JButton countButton3 = new JButton("辅助计算");
countButton3.setBounds(560, 540, 170, 20);
countButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 数据条数 = 表格模型3.getRowCount();
String[][] 数据 = new String[数据条数][11];
int[][] 数据1 = new int[数据条数][11];
for (int i = 0; i < 数据条数; i++) {
for (int j = 0; j < 10; j++)
数据[i][j] = 表格模型3.getValueAt(i, j).toString().trim();
for (int j = 4; j < 10; j++) {
if (j != 8) {
if (数据[i][j].length() > 0)
数据1[i][j] = Integer.valueOf(数据[i][j]);
else
数据1[i][j] = 0;
}
}
for (int j = 4; j < 8; j++) {
if (j != 5)
数据1[i][j] = 数据1[i][j] * 数据1[i][9];
else
数据1[i][j] = (int) (数据1[i][j] * 数据1[i][9] * 1.12);
数据[i][j] = "" + 数据1[i][j];
}
}
表格模型3.setRowCount(0);
for (int i = 0; i < 数据条数; i++)
表格模型3.addRow(数据[i]);
}
});
panel3.add(countButton3);
final JButton clearButton3 = new JButton("清参数文本框");
clearButton3.setBounds(730, 540, 170, 20);
clearButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fab1.setText("");
fab2.setText("0");
fab3.setText("0");
fab4.setText("0");
fab3.setText("0");
fab6.setText("0");
fab7.setText("");
fab8.setText("0");
fab11.setText("0");
fab12.setText("0");
}
});
panel3.add(clearButton3);
frame3.add(panel3);
frame2.add(panel2);
frame1.add(panel1); // 把面板添加到窗体
frame3.setVisible(true);
frame2.setVisible(true);
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];
}
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.close();
sta.close();
con.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
}
88.源码88,部件程序,表单式报表(单记录式报表)打印预览程序,可以打印预览文本域图片。
/**
* 程序文件名:dataPreview2.java
* 作者:程学先
* 功能:表单式报表(单记录式报表)打印预览程序,可以打印预览文本域图片。
* 根据printFormat5生成单记录式打印格式文件打印预览单记录式报表。
* 完成时间:2013年11月27日
* 调用语句:dataPreview2.means(parameter);
* 必须提供的参数:“数据表表名”、 “打印格式文件名称”。
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.table.*;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.ArrayList;
public class dataPreview2 extends JFrame {
static dataPreview2 frame = new dataPreview2();
static String 表名 = "";
static DefaultTableModel tableModel;
static JTable table;
static JScrollPane scrollPane = new JScrollPane();
static JScrollPane scrollPane1;
static JTextField aTextField;
static JButton previewButton2;
static String s1 = "", s2 = "", s3 = "";
static ResultSet rs;
static int 列数;
static String[] 列名;
static String[] 列数据类型;
static int[] 列数据宽度;
static int[] 表列数据宽度;
static int 记录条数, 行号 = -1;
static String[][] 表格数据;
static byte 图像[];
static String 打印格式文件名;
private static ArrayList<struct1> title = new ArrayList<struct1>();
private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();
private static ArrayList<struct3> table1 = new ArrayList<struct3>();
static Connection cont4;
static ResultSetMetaData rsmd4;
static Statement stat4;
static int 窗口宽 = 1000, 窗口高 = 600, 页高 = 600;
private static Graphics2D g3;
private static Graphics g;
private static Font font;
private static TextLayout layout;
public static String[] sw = new String[11];
static String[] 按钮集 = null;
static String 要求按钮号表;
static int 按钮数 = 0, 按钮宽 = 0;
private static String 连接条件 = "";
private static String 字段名表 = "";
private static int x1 = 0, y1 = 0, w1 = 0, w2 = 0, h1 = 0, 左边 = 0, 到顶 = 0,
高度 = 0, 右边 = 0;
static void print1() {
g3 = (Graphics2D) g;
struct1[] 标题 = new struct1[title.size()];
到顶 = 0;
左边 = 0;
for (int i = 0; i < title.size(); i++) {
标题[i] = title.get(i);
g3.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]) + 30;
g3.drawString(标题[i].title[0], x1, y1);
到顶 = y1 + Integer.valueOf(标题[i].title[5]);
}
struct2[] 表体 = new struct2[tableTitle.size()];
int[] w10 = new int[tableTitle.size()];
int[] w20 = new int[tableTitle.size()];
int[] h10 = new int[tableTitle.size()];
int[] h20 = new int[tableTitle.size()];
int[] t10 = new int[tableTitle.size()];
int[] l10 = new int[tableTitle.size()];
int[] le0 = new int[tableTitle.size()];
int[] f0 = new int[tableTitle.size()];
for (int i = 0; i < tableTitle.size(); i++) {
表体[i] = tableTitle.get(i);
w10[i] = Integer.valueOf(表体[i].tableTitle[4]);
w20[i] = Integer.valueOf(表体[i].tableTitle[5]);
h10[i] = Integer.valueOf(表体[i].tableTitle[6]);
h20[i] = Integer.valueOf(表体[i].tableTitle[10]);
t10[i] = Integer.valueOf(表体[i].tableTitle[8]);
l10[i] = Integer.valueOf(表体[i].tableTitle[2]);
le0[i] = Integer.valueOf(表体[i].tableTitle[7]);
for (int j = 0; j < 列数; j++) {
if (列名[j].equalsIgnoreCase(表体[i].tableTitle[1])) {
f0[i] = j;
break;
}
}
}
FontRenderContext frc = new FontRenderContext(null, false, false);
char p1 = 10, p2 = 13;
for (int i = 0; i < tableTitle.size(); i++) {
x1 = le0[i];
y1 = t10[i] + 到顶;
w1 = w10[i];
w2 = w20[i];
h1 = h10[i];
if (l10[i] == 1) {
g3.drawLine(x1, y1, x1 + w1 + w2, y1);
if (x1 + w1 + w2 > 右边)
右边 = x1 + w1 + w2;
}
g3.drawLine(x1, y1, x1, y1 + h1);
g3.setFont(new Font(表体[i].tableTitle[9], Font.PLAIN, Integer
.valueOf(表体[i].tableTitle[10])));
g3.drawLine(x1 + w10[i], y1, x1 + w1, y1 + h1);
if (表格数据[行号][f0[i]] == null)
表格数据[行号][f0[i]] = " ";
font = new Font(表体[i].tableTitle[9], Font.PLAIN,
Integer.valueOf(表体[i].tableTitle[10]));
g3.setFont(font);
g3.drawString(表体[i].tableTitle[0], x1 + 2, y1 + h20[i]);
if (((main1.文本数据类型 + main1.图形数据类型)
.lastIndexOf("," + 列数据类型[i] + ",") >= 0)
|| (h1 > h20[i] * 2)) {
if (main1.图形数据类型.indexOf("," + 列数据类型[i] + ",") >= 0) {
x1 = le0[i];
y1 = t10[i] + 到顶;
w2 = w20[i];
h1 = h10[i];
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select " + 列名[i] + " from " + 表名;
if (表名.indexOf(",") > 0)
sql = sql + 连接条件;
if ((sw[3].length() > 0) && (sw[4].length() > 0))
if (sql.indexOf("where") > 0)
sql = sql + " and " + sw[4] + " = '" + sw[5]+ "'";
else
sql = sql + " where " + sw[4] + " = '" + sw[5]+ "'";
rs = stat4.executeQuery(sql);
rs.absolute(行号 + 1);
InputStream image = rs.getBinaryStream(列名[i]);
String image0 = image.toString();
long length = image0.length();
byte[] buffer = new byte[(int) length / 7];
File file = new File("a1.jpg");
int ch = 0;
if (file.exists()) {
file.delete();
}
file.createNewFile();
FileOutputStream file1 = new FileOutputStream(file,
true);
boolean go = true;
while (go) {
while ((ch = image.read(buffer)) != -1) {
file1.write(buffer);
}
go = false;
}
BufferedImage image1 = ImageIO.read(file);
g.drawImage(image1, x1 + w1 + 2, y1, w2, h1, null);
rs.close();
file1.close();
stat4.close();
cont4.close();
} catch (Exception e) {
e.printStackTrace();
}
} else {
int j = 0, y2 = y1;
float j1 = 0f;
s2 = 表格数据[行号][f0[i]];
s3 = "";
if ((s2.lastIndexOf("" + p1) < s2.length())
&& (s2.lastIndexOf("" + p1) > 0))
s2 = s2 + p1;
for (int k = 0; k < s2.length(); k++) {
if ((j1 < w2)
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p1))
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p2)) && (k != s2.length() - 1)) {
s3 = s3 + s2.substring(k, k + 1);
if (s2.substring(k, k + 1).compareTo("z") < 0) {
if (s2.substring(k, k + 1).compareTo("0") < 0)
j1 = j1 + h20[i] * 0.43f;
else
j1 = j1 + h20[i] * 0.64f;
} else
j1 = j1 + h20[i];
} else {
if (j1 >= w2)
s3 = s3 + s2.substring(k, k + 1);
j = j + h20[i];
if (j1 >= w2 - 2) {
layout = new TextLayout(s3, font, frc)
.getJustifiedLayout(w2 - 2);
;
layout.draw(g3, x1 + w1 + 2, y2 + h20[i]);
} else
g3.drawString(s3, x1 + w1 + 2, y2 + h20[i]);
y2 = y2 + h20[i];
s3 = "";
j1 = 0;
}
if (j >= h1)
break;
}
}
}
else {
g3.drawString(表格数据[行号][f0[i]], x1 + w1 + 2, y1 + h20[i]);
}
g3.drawLine(x1, y1 + h1, x1 + w1 + w2, y1 + h1);
if (y1 + h1 > 高度)
高度 = y1 + h1;
}
g3.drawLine(右边, t10[0] + 到顶, 右边, 高度);
y1 = 高度 + 10;
struct3[] 表尾 = new struct3[table1.size()];
for (int i = 0; i < table1.size(); i++) {
表尾[i] = table1.get(i);
g3.setFont(new Font(表尾[i].table1[8], Font.PLAIN, Integer
.valueOf(表尾[i].table1[9])));
x1 = Integer.valueOf(表尾[i].table1[6]);
y1 = y1 + Integer.valueOf(表尾[i].table1[5]);
g3.drawString(表尾[i].table1[0], x1, y1);
}
}
public static void means(String[] parameter) {
sw = new String[11];
sw[1] = main1.sw1 + "";
sw[2] = main1.sw2;
sw[3] = main1.sw3;
sw[4] = main1.sw4;
sw[5] = main1.sw5;
sw[6] = main1.sw6;
sw[7] = main1.sw7;
sw[8] = main1.sw8;
sw[9] = main1.sw9;
sw[10] = main1.sw10;
main1.sw1 = 0;
main1.sw2 = "";
main1.sw3 = "";
main1.sw4 = "";
main1.sw5 = "";
main1.sw6 = "";
main1.sw7 = "";
main1.sw8 = "";
main1.sw9 = "";
main1.sw10 = "";
frame = new dataPreview2();
表名 = "";
scrollPane = new JScrollPane();
s1 = "";
s2 = "";
s3 = "";
行号 = -1;
title = new ArrayList<struct1>();
tableTitle = new ArrayList<struct2>();
table1 = new ArrayList<struct3>();
窗口宽 = 1000;
窗口高 = 600;
页高 = 600;
x1 = 0;
y1 = 0;
w1 = 0;
w2 = 0;
h1 = 0;
左边 = 0;
到顶 = 0;
高度 = 0;
右边 = 0;
表名 = parameter[4];
打印格式文件名 = parameter[15];
连接条件 = parameter[20];
String[] 按钮集01 = { "当前记录预览", "预览下一条", "退出" };
按钮集 = new String[按钮集01.length];
按钮数 = 0;
for (int i0 = 0; i0 < 按钮集01.length; i0++)
按钮集[i0] = 按钮集01[i0];
if (parameter[11].length() > 0) {
要求按钮号表 = parameter[11];// 需要显示的按钮的顺序号
要求按钮号表 = 要求按钮号表.replaceAll(";", ";");
要求按钮号表 = 要求按钮号表.replaceAll("。", ";");
要求按钮号表 = 要求按钮号表.replaceAll(":", ";");
要求按钮号表 = 要求按钮号表.replaceAll(":", ";");
if (要求按钮号表.indexOf(";") > 0) { // 如果有按钮更名要求
String s601[] = 要求按钮号表.split(",");
要求按钮号表 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (s601[i01].indexOf(";") > 0) {
String s602[] = s601[i01].split(";");
按钮集[Integer.parseInt((s602[0]))] = s602[1];
要求按钮号表 = 要求按钮号表 + "," + s602[0];// 只留号,去更名
按钮数++;
} else {
要求按钮号表 = 要求按钮号表 + "," + s601[i01];// 只留号,原无更名
按钮数++;
}
}
}
else {
String s601[] = 要求按钮号表.split(",");
要求按钮号表 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (i01 == 0)
要求按钮号表 = s601[i01];
else
要求按钮号表 = 要求按钮号表 + "," + s601[i01];
按钮数++;
}
}
} else {
要求按钮号表 = ""; // 没输入要求按钮号,定全部按钮号
for (int i1 = 0; i1 < 按钮集.length; i1++) {
if (i1 == 0)
要求按钮号表 = 要求按钮号表 + i1;
else
要求按钮号表 = 要求按钮号表 + "," + i1;
按钮数++;
}
}
要求按钮号表 = "," + 要求按钮号表 + ",";
窗口宽 = main1.窗口宽;
窗口高 = main1.窗口高;
int m1, m2;
try {
if (parameter[17].length() == 0) {
m1 = 0;
m2 = 0;
} else {
m1 = Integer.parseInt(parameter[17]);// 宽度参数
m2 = Integer.parseInt(parameter[18]);
}
if (m1 > 0) {
if (m2 < 80) {
m1 = m1 * 10;
m2 = m2 * 10;
}
窗口宽 = m1;
窗口高 = m2;
}
} catch (Exception e2) {
}
File file1 = new File(打印格式文件名);
try {
if (file1.exists()) { // 如果文件存在
FileReader fr = new FileReader(file1);// 读方式打开文件
BufferedReader br = new BufferedReader(fr);// 建立文件输入字符流
String tempStr = null;
int 行号 = 0, 列号 = 0;
String[] su1 = new String[11];
for (int i = 0; (tempStr = br.readLine()) != null; i++) {// 读文件
if (tempStr.substring(0, 4).indexOf("。2") > 0) { // 可视化生成的格式文件中文本框类型
String[] su = tempStr.split("。");
su1[2] = su[8];
su1[3] = su[9];
su1[0] = su[10];
su1[1] = su[11];
su1[4] = su[17];
su1[5] = su[21];
su1[6] = su[18];
su1[7] = su[15];
su1[8] = su[16];
su1[9] = su[23];
su1[10] = su[24];
tableTitle.add(new struct2(su1));
} else if (tempStr.substring(0, 2).equals("1,")) { // 数字化生成的格式文件
title.add(new struct1(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("2,")) {
tableTitle.add(new struct2(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("3,")) {
table1.add(new struct3(tempStr.substring(2,
tempStr.length()).split("。")));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
字段名表 = "";
for (int i = 0; i < tableTitle.size(); i++) {
if (字段名表.length() == 0)
字段名表 = tableTitle.get(i).tableTitle[1];
else
字段名表 = 字段名表 + "," + tableTitle.get(i).tableTitle[1];
}
数据表查询结构(表名);
数据表查询数据(表名);
frame.setLayout(null);
frame.setTitle("单记录式报表预览程序 作者:程学先");
frame.setBounds(10, 10, 窗口宽 - 10, 1000);
frame.getContentPane().setLayout(null);
final JPanel panel = new JPanel();
panel.setBounds(10, 10, 窗口宽 - 50, 1000);
panel.setLayout(null);
frame.getContentPane().add(panel);
tableModel = new DefaultTableModel(表格数据, 列名);
table = new JTable(tableModel);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane.getViewport().add(table, null);
scrollPane.setBounds(30, 50, 窗口宽 - 100, 窗口高 - 150);
panel.add(scrollPane);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
行号 = table.getSelectedRow(); // 获得被选中行的索引
}
});
按钮宽 = (窗口宽 - 160) / 按钮数;
int 左边距 = 100;
final JButton previewButton1 = new JButton(按钮集[0]);
previewButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (行号 < 0) {
行号 = 1;
} else {
panel.remove(scrollPane);
g = panel.getGraphics();
panel.paint(g);
print1();
previewButton2.setEnabled(true);
}
}
});
previewButton1.setBounds(左边距, 20, 按钮宽, 20);
if (要求按钮号表.indexOf(",0,") >= 0) {
左边距 = 左边距 + 按钮宽;
panel.add(previewButton1);
}
previewButton2 = new JButton(按钮集[1]);
previewButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (记录条数 > 行号) {
g.clearRect(0, 0, 1000, 800);
行号++;
panel.paint(g);
print1();
}
}
});
previewButton2.setBounds(左边距, 20, 按钮宽, 20);
if (要求按钮号表.indexOf(",1,") >= 0) {
左边距 = 左边距 + 按钮宽;
panel.add(previewButton2);
previewButton2.setEnabled(false);
}
final JButton exitButton = new JButton(按钮集[2]);
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ((sw[2].length() > 0) && (sw[3].length() > 0)
&& (sw[4].length() > 0))
WorkflowDrivek1.means(sw);
panel.setVisible(false);
frame.setVisible(false);
frame.dispose();
}
});
exitButton.setBounds(左边距, 20, 按钮宽, 20);
if (要求按钮号表.indexOf(",2,") >= 0) {
左边距 = 左边距 + 按钮宽;
panel.add(exitButton);
}
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
static void 数据表查询结构(String 数据表名) {
String[] s10 = null;
String[] sk = new String[300];
int n1 = 0, n2 = 0;
连接条件 = "";
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);
rsmd4 = rs.getMetaData();
列数 = rsmd4.getColumnCount();
列名 = new String[列数];
列数据类型 = new String[列数];
列数据宽度 = new int[列数];
for (int i = 0; i < 列数; i++) {
列名[i] = rsmd4.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);
rsmd4 = rs.getMetaData();
列数 = rsmd4.getColumnCount();
for (int j = 0; j < 列数; j++) { // 读取所有表的列名,同名的加表名
s2 = rsmd4.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;
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select " + 字段名表 + " from " + 数据表名 + 连接条件;
rs = stat4.executeQuery(s1);
rsmd4 = rs.getMetaData();
列数 = rsmd4.getColumnCount();
列名 = new String[列数];
列数据类型 = new String[列数];
列数据宽度 = new int[列数];
for (int i1 = 0; i1 < 列数; i1++) {
列名[i1] = rsmd4.getColumnName(i1 + 1);
列数据类型[i1] = rsmd4.getColumnTypeName(i1 + 1);
列数据宽度[i1] = rsmd4.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, "读取数据库数据出错!");
}
}
}
89.源码89,部件程序,表单式报表(单记录式报表)打印程序,可以打印文本域图片。
/**
* 程序文件名:dataPrint2.java
* 作者:程学先
* 功能:表单式报表(单记录式报表)打印程序,可以打印文本域图片。
* 根据printFormat5生成单记录式打印格式文件打印单记录式报表。
* 完成时间:2013年11月27日
* 调用语句:dataPrint2.means(parameter);
* 必须提供的参数:“数据表表名”、 “打印格式文件名称”。
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
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 javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.table.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.ArrayList;
import java.util.HashSet;
public class dataPrint2 extends JFrame {
static dataPrint2 frame = new dataPrint2();
static String 表名 = "";
static DefaultTableModel tableModel;
static JTable table;
static JScrollPane scrollPane = new JScrollPane();
static JScrollPane scrollPane1;
static JTextField aTextField;
static JButton previewButton2;
static String s1 = "", s2 = "", s3 = "";
static ResultSet rs;
static int 列数;
static String[] 列名;
static String[] 列数据类型;
static int[] 列数据宽度;
static int[] 表列数据宽度;
static int 记录条数, 行号 = -1;
static String[][] 表格数据;
static byte 图像[];
static String 打印格式文件名;
private static ArrayList<struct1> title = new ArrayList<struct1>();
private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();
private static ArrayList<struct3> table1 = new ArrayList<struct3>();
static Connection cont4;
static ResultSetMetaData rsmd4;
static Statement stat4;
static int 窗口宽 = 1000, 窗口高 = 600, 页高 = 600;
private static Graphics2D g3;
private static Graphics g;
private static Font font;
private static TextLayout layout;
public static String[] sw = new String[11];
static String[] 按钮集 = null;
static String 要求按钮号表;
static int 按钮数 = 0, 按钮宽 = 0;
private static String 连接条件 = "";
private static String 字段名表 = "";
private static int x1 = 0, y1 = 0, w1 = 0, w2 = 0, h1 = 0, 左边 = 0, 到顶 = 0,
高度 = 0, 右边 = 0;
static void print1() {
struct1[] 标题 = new struct1[title.size()];
到顶 = 0;
左边 = 0;
for (int i = 0; i < title.size(); i++) {
标题[i] = title.get(i);
g3.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]) + 30;
g3.drawString(标题[i].title[0], x1, y1);
到顶 = y1 + Integer.valueOf(标题[i].title[5]);
}
struct2[] 表体 = new struct2[tableTitle.size()];
int[] w10 = new int[tableTitle.size()];
int[] w20 = new int[tableTitle.size()];
int[] h10 = new int[tableTitle.size()];
int[] h20 = new int[tableTitle.size()];
int[] t10 = new int[tableTitle.size()];
int[] l10 = new int[tableTitle.size()];
int[] le0 = new int[tableTitle.size()];
int[] f0 = new int[tableTitle.size()];
for (int i = 0; i < tableTitle.size(); i++) {
表体[i] = tableTitle.get(i);
w10[i] = Integer.valueOf(表体[i].tableTitle[4]);
w20[i] = Integer.valueOf(表体[i].tableTitle[5]);
h10[i] = Integer.valueOf(表体[i].tableTitle[6]);
h20[i] = Integer.valueOf(表体[i].tableTitle[10]);
t10[i] = Integer.valueOf(表体[i].tableTitle[8]);
l10[i] = Integer.valueOf(表体[i].tableTitle[2]);
le0[i] = Integer.valueOf(表体[i].tableTitle[7]);
for (int j = 0; j < 列数; j++)
if (列名[j].trim().equalsIgnoreCase(表体[i].tableTitle[1].trim())) {
f0[i] = j;
break;
}
}
FontRenderContext frc = new FontRenderContext(null, false, false);
char p1 = 10, p2 = 13;
for (int i = 0; i < tableTitle.size(); i++) {
x1 = le0[i];
y1 = t10[i] + 到顶;
w1 = w10[i];
w2 = w20[i];
h1 = h10[i];
if (l10[i] == 1) {
g3.drawLine(x1, y1, x1 + w1 + w2, y1);
if (x1 + w1 + w2 > 右边)
右边 = x1 + w1 + w2;
}
g3.drawLine(x1, y1, x1, y1 + h1);
g3.setFont(new Font(表体[i].tableTitle[9], Font.PLAIN, Integer
.valueOf(表体[i].tableTitle[10])));
g3.drawLine(x1 + w10[i], y1, x1 + w1, y1 + h1);
if (表格数据[行号][f0[i]] == null)
表格数据[行号][f0[i]] = " ";
font = new Font(表体[i].tableTitle[9], Font.PLAIN,
Integer.valueOf(表体[i].tableTitle[10]));
g3.setFont(font);
g3.drawString(表体[i].tableTitle[0], x1 + 2, y1 + h20[i]);
if (((main1.文本数据类型 + main1.图形数据类型)
.lastIndexOf("," + 列数据类型[i] + ",") >= 0)
|| (h1 > h20[i] * 2)) {
if (main1.图形数据类型.indexOf("," + 列数据类型[i] + ",") >= 0) {
x1 = le0[i];
y1 = t10[i] + 到顶;
w2 = w20[i];
h1 = h10[i];
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select " + 列名[i] + " from " + 表名;
if (表名.indexOf(",") > 0)
sql = sql + 连接条件;
if ((sw[3].length() > 0) && (sw[4].length() > 0))
if (sql.indexOf("where") > 0)
sql = sql + " and " + sw[4] + " = '" + sw[5]
+ "'";
else
sql = sql + " where " + sw[4] + " = '" + sw[5]
+ "'";
rs = stat4.executeQuery(sql);
rs.absolute(行号 + 1);
InputStream image = rs.getBinaryStream(列名[i]);
String image0 = image.toString();
long length = image0.length();
byte[] buffer = new byte[(int) length / 7];
File file = new File("a1.jpg");
int ch = 0;
if (file.exists()) {
file.delete();
}
file.createNewFile();
FileOutputStream file1 = new FileOutputStream(file,
true);
boolean go = true;
while (go) {
while ((ch = image.read(buffer)) != -1) {
file1.write(buffer);
}
go = false;
}
BufferedImage image1 = ImageIO.read(file);
g.drawImage(image1, x1 + w1 + 2, y1, w2, h1, null);
rs.close();
file1.close();
stat4.close();
cont4.close();
} catch (Exception e) {
e.printStackTrace();
}
} else {
int j = 0, y2 = y1;
float j1 = 0f;
s2 = 表格数据[行号][f0[i]];
s3 = "";
if ((s2.lastIndexOf("" + p1) < s2.length())
&& (s2.lastIndexOf("" + p1) > 0))
s2 = s2 + p1;
for (int k = 0; k < s2.length(); k++) {
if ((j1 < w2)
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p1))
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p2))) {
s3 = s3 + s2.substring(k, k + 1);
if (s2.substring(k, k + 1).compareTo("z") < 0) {
if (s2.substring(k, k + 1).compareTo("0") < 0)
j1 = j1 + h20[i] * 0.37f;
else
j1 = j1 + h20[i] * 0.57f;
} else
j1 = j1 + h20[i];
} else {
j = j + h20[i];
if (j1 >= w2 - 2) {
layout = new TextLayout(s3, font, frc)
.getJustifiedLayout(w2 - 2);
;
layout.draw(g3, x1 + w1 + 2, y2 + h20[i]);
} else
g3.drawString(s3, x1 + w1 + 2, y2 + h20[i]);
y2 = y2 + h20[i];
s3 = "";
j1 = 0;
}
if (j >= h1)
break;
}
}
} else
g3.drawString(表格数据[行号][f0[i]], x1 + w1 + 2, y1 + h20[i]);
g3.drawLine(x1, y1 + h1, x1 + w1 + w2, y1 + h1);
if (y1 + h1 > 高度)
高度 = y1 + h1;
}
g3.drawLine(右边, t10[0] + 到顶, 右边, 高度);
y1 = 高度 + 10;
struct3[] 表尾 = new struct3[table1.size()];
for (int i = 0; i < table1.size(); i++) {
表尾[i] = table1.get(i);
g3.setFont(new Font(表尾[i].table1[8], Font.PLAIN, Integer
.valueOf(表尾[i].table1[9])));
x1 = Integer.valueOf(表尾[i].table1[6]);
y1 = y1 + Integer.valueOf(表尾[i].table1[5]);
g3.drawString(表尾[i].table1[0], x1, y1);
}
}
public static void means(String[] parameter) {
sw = new String[11];
sw[1] = main1.sw1 + "";
sw[2] = main1.sw2;
sw[3] = main1.sw3;
sw[4] = main1.sw4;
sw[5] = main1.sw5;
sw[6] = main1.sw6;
sw[7] = main1.sw7;
sw[8] = main1.sw8;
sw[9] = main1.sw9;
sw[10] = main1.sw10;
main1.sw1 = 0;
main1.sw2 = "";
main1.sw3 = "";
main1.sw4 = "";
main1.sw5 = "";
main1.sw6 = "";
main1.sw7 = "";
main1.sw8 = "";
main1.sw9 = "";
main1.sw10 = "";
frame = new dataPrint2();
表名 = "";
scrollPane = new JScrollPane();
s1 = "";
s2 = "";
s3 = "";
行号 = -1;
title = new ArrayList<struct1>();
tableTitle = new ArrayList<struct2>();
table1 = new ArrayList<struct3>();
窗口宽 = 1000;
窗口高 = 600;
页高 = 600;
x1 = 0;
y1 = 0;
w1 = 0;
w2 = 0;
h1 = 0;
左边 = 0;
到顶 = 0;
高度 = 0;
右边 = 0;
String[] 按钮集01 = { "打印", "打印下一条", "退出" };
按钮集 = new String[按钮集01.length];
按钮数 = 0;
for (int i0 = 0; i0 < 按钮集01.length; i0++)
按钮集[i0] = 按钮集01[i0];
if (parameter[11].length() > 0) {
要求按钮号表 = parameter[11];// 需要显示的按钮的顺序号
要求按钮号表 = 要求按钮号表.replaceAll(";", ";");
要求按钮号表 = 要求按钮号表.replaceAll("。", ";");
要求按钮号表 = 要求按钮号表.replaceAll(":", ";");
要求按钮号表 = 要求按钮号表.replaceAll(":", ";");
if (要求按钮号表.indexOf(";") > 0) { // 如果有按钮更名要求
String s601[] = 要求按钮号表.split(",");
要求按钮号表 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (s601[i01].indexOf(";") > 0) {
String s602[] = s601[i01].split(";");
按钮集[Integer.parseInt((s602[0]))] = s602[1];
要求按钮号表 = 要求按钮号表 + "," + s602[0];// 只留号,去更名
按钮数++;
} else {
要求按钮号表 = 要求按钮号表 + "," + s601[i01];// 只留号,原无更名
按钮数++;
}
}
}
else {
String s601[] = 要求按钮号表.split(",");
要求按钮号表 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (i01 == 0)
要求按钮号表 = s601[i01];
else
要求按钮号表 = 要求按钮号表 + s601[i01];
按钮数++;
}
}
} else {
要求按钮号表 = ""; // 没输入要求按钮号,定全部按钮号
for (int i1 = 0; i1 < 按钮集.length; i1++) {
if (i1 == 0)
要求按钮号表 = 要求按钮号表 + i1;
else
要求按钮号表 = 要求按钮号表 + "," + i1;
按钮数++;
}
}
要求按钮号表 = "," + 要求按钮号表 + ",";
窗口宽 = main1.窗口宽;
窗口高 = main1.窗口高;
int m1, m2;
try {
if (parameter[17].length() == 0) {
m1 = 0;
m2 = 0;
} else {
m1 = Integer.parseInt(parameter[17]);// 宽度参数
m2 = Integer.parseInt(parameter[18]);
}
if (m1 > 0) {
if (m2 < 80) {
m1 = m1 * 10;
m2 = m2 * 10;
}
窗口宽 = m1;
窗口高 = m2;
}
} catch (Exception e2) {
}
表名 = parameter[4];
打印格式文件名 = parameter[15];
连接条件 = parameter[20];
File file1 = new File(打印格式文件名);
try {
if (file1.exists()) { // 如果文件存在
FileReader fr = new FileReader(file1);// 读方式打开文件
BufferedReader br = new BufferedReader(fr);// 建立文件输入字符流
String tempStr = null;
for (int i = 0; (tempStr = br.readLine()) != null; i++) {// 读文件
if (tempStr.substring(0, 2).equals("1,")) {
title.add(new struct1(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("2,")) {
tableTitle.add(new struct2(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("3,")) {
table1.add(new struct3(tempStr.substring(2,
tempStr.length()).split("。")));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
字段名表 = "";
for (int i = 0; i < tableTitle.size(); i++) {
if (字段名表.length() == 0)
字段名表 = tableTitle.get(i).tableTitle[1];
else
字段名表 = 字段名表 + "," + tableTitle.get(i).tableTitle[1];
}
数据表查询结构(表名);
数据表查询数据(表名);
frame.show();
frame.setLayout(null);
frame.setTitle("单记录式报表程序 作者:程学先");
frame.setBounds(10, 10, 窗口宽 - 10, 1000);
frame.getContentPane().setLayout(null);
final JPanel panel = new JPanel();
panel.setBounds(10, 10, 窗口宽 - 50, 1000);
panel.setLayout(null);
frame.getContentPane().add(panel);
tableModel = new DefaultTableModel(表格数据, 列名);
table = new JTable(tableModel);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane.getViewport().add(table, null);
scrollPane.setBounds(30, 50, 窗口宽 - 100, 窗口高 - 150);
panel.add(scrollPane);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
行号 = table.getSelectedRow();
}
});
按钮宽 = (窗口宽 - 100) / 按钮数;
int 左边距 = 30;
final JButton previewButton1 = new JButton(按钮集[0]);
previewButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (行号 < 0) {
JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");
return;
} else {
final PrinterJob job = PrinterJob.getPrinterJob();
if (!job.printDialog())
return;
job.setPrintable(new Printable() {
public int print(Graphics graphics,
PageFormat pageFormat, int pageIndex)
throws PrinterException {
dataPrint2.g = graphics;
if (pageIndex < 1) {
g3 = (Graphics2D) g;
g3.setStroke(new BasicStroke(1f));
print1();
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
});
try {
job.print();
} catch (Exception e1) {
e1.printStackTrace();
}
previewButton2.setEnabled(true);
}
}
});
previewButton1.setBounds(左边距, 20, 按钮宽, 20);
if (要求按钮号表.indexOf(",0,") >= 0) {
左边距 = 左边距 + 按钮宽;
panel.add(previewButton1);
}
previewButton2 = new JButton(按钮集[1]);
previewButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (记录条数 > 行号) {
final PrinterJob job = PrinterJob.getPrinterJob();
if (!job.printDialog())
return;
job.setPrintable(new Printable() {
public int print(Graphics graphics,
PageFormat pageFormat, int pageIndex)
throws PrinterException {
dataPrint2.g = graphics;
if (pageIndex < 1) {
g3 = (Graphics2D) g;
g3.setStroke(new BasicStroke(1f));
print1();
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
});
try {
job.print();
} catch (Exception e1) {
e1.printStackTrace();
}
previewButton2.setEnabled(true);
}
}
});
previewButton2.setBounds(左边距, 20, 按钮宽, 20);
if (要求按钮号表.indexOf(",1,") >= 0) {
左边距 = 左边距 + 按钮宽;
panel.add(previewButton2);
}
previewButton2.setEnabled(false);
final JButton exitButton = new JButton(按钮集01[2]);
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ((sw[2].length() > 0) && (sw[3].length() > 0)
&& (sw[4].length() > 0))
WorkflowDrivek1.means(sw);
panel.setVisible(false);
frame.setVisible(false);
frame.dispose();
}
});
exitButton.setBounds(左边距, 20, 按钮宽, 20);
if (要求按钮号表.indexOf(",2,") >= 0) {
左边距 = 左边距 + 按钮宽;
panel.add(exitButton);
}
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
static void 数据表查询结构(String 数据表名) {
String[] s10 = null;
String[] sk = new String[300];
int n1 = 0, n2 = 0;
连接条件 = "";
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);
rsmd4 = rs.getMetaData();
列数 = rsmd4.getColumnCount();
列名 = new String[列数];
列数据类型 = new String[列数];
列数据宽度 = new int[列数];
for (int i = 0; i < 列数; i++) {
列名[i] = rsmd4.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);
rsmd4 = rs.getMetaData();
列数 = rsmd4.getColumnCount();
for (int j = 0; j < 列数; j++) { // 读取所有表的列名,同名的加表名
s2 = rsmd4.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;
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select " + 字段名表 + " from " + 数据表名 + 连接条件;
rs = stat4.executeQuery(s1);
rsmd4 = rs.getMetaData();
列数 = rsmd4.getColumnCount();
列名 = new String[列数];
列数据类型 = new String[列数];
列数据宽度 = new int[列数];
for (int i1 = 0; i1 < 列数; i1++) {
列名[i1] = rsmd4.getColumnName(i1 + 1);
列数据类型[i1] = rsmd4.getColumnTypeName(i1 + 1);
列数据宽度[i1] = rsmd4.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, "读取数据库数据出错!");
}
}
}
版本2
87.源码87,部件程序,表单式报表(单记录式报表)打印格式文件设计程序。该类报表可打印文本、图片。
/*
* 程序文件名:printFormat5.java
* 作者:程学先
* 功能:表单式报表(单记录式报表)打印格式文件设计程序。
* 用于辅助生成打印数据库中单或多数据表的单记录式报表格式文件。
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.*;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Vector;
public class printFormat5 extends JFrame {
private static printFormat5 frame1 = new printFormat5();
private static printFormat5 frame2 = new printFormat5();
private static printFormat5 frame3 = new printFormat5();
private static JPanel panel1 = new JPanel();
private static JPanel panel2 = new JPanel();
private static JPanel panel3 = new JPanel();
private static DefaultTableModel variabl19651;
private static DefaultTableModel variabl19652;
private static DefaultTableModel variabl19653;
private static JTable variabl26551;
private static JTable variabl26552;
private static JTable variabl26553;
private static JScrollPane scrollPane1 = new JScrollPane();
private static JScrollPane scrollPane2 = new JScrollPane();
private static JScrollPane scrollPane3 = new JScrollPane();
private static JScrollPane scrollPaneL1 = new JScrollPane();
private static JScrollPane scrollPaneL2 = new JScrollPane();
private static JScrollPane scrollPaneL3 = new JScrollPane();
private static List list1 = new List();
private static List list2 = new List();
private static List list3 = new List();
private static JLabel fl0, fl1, fl2, fl3, fl4, fl5, fl6, fl7, fl8, fl10,
fl11, fl12;
private static JTextField fa0, fa1, fa2, fa3, fa4, fa5, fa6, fa7, fa8,
fa10, fa11, fa12;
private static JLabel fla1, fla2, fla3, fla4, fla5, fla6, fla7, fla8, fla9,
fla11, fla12;
private static JTextField faa1, faa2, faa3, faa4, faa5, faa6, faa7, faa8,
faa9, faa11, faa12;
private static JLabel flb1, flb2, flb3, flb4, flb5, flb6, flb7, flb8,
flb11, flb12;
private static JTextField fab1, fab2, fab3, fab4, fab5, fab6, fab7, fab8,
fab11, fab12;
private static String variabl2327;
private static int variabl1739 = 0, variabl2651 = 0;
private static int variabl2127 = 0;
private static String[][] variabl2197;
private static String[] variabl25171;
private static String[] variabl1501;
private static int[] variabl1489;
private static File file1;
static Connection con;
private static Statement sta;
static String s1 = "", s2 = "";
private static ResultSet rs;
private static ResultSetMetaData rsmd;
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 variabl2049 = "";
private static String variabl1633 = "";
public static void means(String[] parameter) {
frame1 = new printFormat5();
frame2 = new printFormat5();
frame3 = new printFormat5();
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
scrollPane1 = new JScrollPane();
scrollPane2 = new JScrollPane();
scrollPane3 = new JScrollPane();
scrollPaneL1 = new JScrollPane();
scrollPaneL2 = new JScrollPane();
scrollPaneL3 = new JScrollPane();
list1 = new List();
list2 = new List();
list3 = new List();
variabl1739 = 0;
variabl2651 = 0;
variabl2127 = 0;
s1 = "";
s2 = "";
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("打印报表标题设计页。 作者:程学先");
frame2.setTitle("单记录数据设计页。 ");
frame3.setTitle("表尾内容设计页。 ");
frame1.setBounds(10, 10, 950, 660);
frame2.setBounds(30, 10, 950, 660);
frame3.setBounds(60, 10, 950, 660);
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
panel1.setBounds(10, 10, 950, 660);
panel2.setBounds(30, 10, 950, 660);
panel3.setBounds(60, 10, 950, 660);
panel1.setLayout(null);
panel2.setLayout(null);
panel3.setLayout(null);
String[] variabl251701 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度",
"左边距", "到顶距", "字体", "字号" };
String[] variabl251702 = { "标签内容", "字段名称", "行号", "列号", "标签宽", "字段宽",
"高度", "左边距", "到顶距", "字体", "字号" };
String[] variabl251703 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度",
"左边距", "到顶距", "字体", "字号" };
main1.driver1();
String variabl2603 = parameter[4];
String variabl2429 = parameter[0];
final String[] variabl26031 = variabl2429.split(",");
数据表查询结构(parameter[4]);
fl0 = new JLabel("数据表名");
fl0.setBounds(40, 10, 80, 20);
panel1.add(fl0);
fa0 = new JTextField("");
fa0.setText(variabl2603);
fa0.setBounds(130, 10, 100, 20);
panel1.add(fa0);
fa0.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 0;
list1.removeAll();
for (int i = 0; i < variabl26031.length; i++)
list1.add(variabl26031[i].toString());
}
});
fl10 = new JLabel("文件名");
fl10.setBounds(250, 10, 50, 20);
panel1.add(fl10);
fa10 = new JTextField("", 20);
fa10.setBounds(300, 10, 100, 20);
panel1.add(fa10);
fa10.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
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 (file1.exists()) {
FileReader fr = new FileReader(file1);
BufferedReader br = new BufferedReader(fr);
String tempStr = null;
for (int i = 0; (tempStr = br.readLine()) != null; i++) {
if (tempStr.substring(0, 2).equals("1,")) {
variabl19651.addRow(tempStr.substring(
2, tempStr.length()).split("。"));
} else if (tempStr.substring(0, 2).equals(
"2,")) {
variabl19652.addRow(tempStr.substring(
2, tempStr.length()).split("。"));
} else if (tempStr.substring(0, 2).equals(
"3,")) {
variabl19653.addRow(tempStr.substring(
2, tempStr.length()).split("。"));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
}
}
}
});
variabl19651 = new DefaultTableModel(variabl2197, variabl251701);
variabl19652 = new DefaultTableModel(variabl2197, variabl251702);
variabl19653 = new DefaultTableModel(variabl2197, variabl251703);
variabl26551 = new JTable(variabl19651);
variabl26552 = new JTable(variabl19652);
variabl26553 = new JTable(variabl19653);
variabl26551.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
variabl26552.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
variabl26553.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
variabl26551.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int variabl1823 = variabl26551.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (variabl19651.getValueAt(variabl1823, j) != null)
variabl2327 = variabl19651.getValueAt(variabl1823, j)
.toString();
else
variabl2327 = "";
switch (j) {
case 0:
fa1.setText(variabl2327.toString());
break;
case 1:
fa2.setText(variabl2327.toString());
break;
case 2:
fa11.setText(variabl2327.toString());
break;
case 3:
fa12.setText(variabl2327.toString());
break;
case 4:
fa3.setText(variabl2327.toString());
break;
case 5:
fa4.setText(variabl2327.toString());
break;
case 6:
fa5.setText(variabl2327.toString());
break;
case 7:
fa6.setText(variabl2327.toString());
break;
case 8:
fa7.setText(variabl2327.toString());
break;
case 9:
fa8.setText(variabl2327.toString());
break;
}
}
}
});
scrollPane1.setBounds(10, 40, 800, 400);
scrollPane2.setBounds(10, 40, 800, 400);
scrollPane3.setBounds(10, 40, 800, 400);
scrollPane1.setViewportView(variabl26551);
scrollPane2.setViewportView(variabl26552);
scrollPane3.setViewportView(variabl26553);
panel1.add(scrollPane1, BorderLayout.CENTER);
panel2.add(scrollPane2, BorderLayout.CENTER);
panel3.add(scrollPane3, BorderLayout.CENTER);
fl1 = new JLabel("内容");
fl1.setBounds(70, 460, 40, 20);
panel1.add(fl1);
fa1 = new JTextField("", 20);
fa1.setBounds(110, 460, 100, 20);
panel1.add(fa1);
fa1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 1;
list1.removeAll();
for (int i = 0; i < variabl2651; i++) {
list1.add(variabl25171[i]);
}
}
});
fl2 = new JLabel("变量名");
fl2.setBounds(230, 460, 50, 20);
panel1.add(fl2);
fa2 = new JTextField("", 20);
fa2.setBounds(280, 460, 60, 20);
panel1.add(fa2);
fa2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 2;
list1.removeAll();
for (int i = 0; i < variabl2651; i++) {
list1.add(variabl25171[i]);
}
}
});
fl11 = new JLabel("行号");
fl11.setBounds(370, 460, 40, 20);
panel1.add(fl11);
fa11 = new JTextField("", 20);
fa11.setBounds(410, 460, 60, 20);
panel1.add(fa11);
fa11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 11;
list1.removeAll();
}
});
fl12 = new JLabel("列号");
fl12.setBounds(500, 460, 40, 20);
panel1.add(fl12);
fa12 = new JTextField("", 20);
fa12.setBounds(540, 460, 60, 20);
panel1.add(fa12);
fa12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 12;
list1.removeAll();
}
});
fl3 = new JLabel("宽度");
fl3.setBounds(630, 460, 40, 20);
panel1.add(fl3);
fa3 = new JTextField("", 20);
fa3.setBounds(670, 460, 60, 20);
panel1.add(fa3);
fa3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 3;
list1.removeAll();
}
});
fl4 = new JLabel("高度");
fl4.setBounds(760, 460, 40, 20);
panel1.add(fl4);
fa4 = new JTextField("", 20);
fa4.setBounds(800, 460, 60, 20);
panel1.add(fa4);
fa4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 4;
list1.removeAll();
}
});
fl5 = new JLabel("左边距");
fl5.setBounds(60, 500, 50, 20);
panel1.add(fl5);
fa5 = new JTextField("", 20);
fa5.setBounds(110, 500, 100, 20);
panel1.add(fa5);
fa5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 5;
list1.removeAll();
}
});
fl6 = new JLabel("到顶距");
panel1.add(fl6);
fa6 = new JTextField("", 20);
panel1.add(fa6);
fl6.setBounds(220, 500, 60, 20);
fa6.setBounds(280, 500, 60, 20);
fa6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 6;
list1.removeAll();
}
});
fl7 = new JLabel("字体");
panel1.add(fl7);
fa7 = new JTextField("", 20);
panel1.add(fa7);
fl7.setBounds(370, 500, 40, 20);
fa7.setBounds(410, 500, 120, 20);
fa7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 7;
list1.removeAll();
for (int i = 0; i < variabl2629.length; i++) {
list1.add(variabl2629[i]);
}
}
});
fl8 = new JLabel("字号");
panel1.add(fl8);
fa8 = new JTextField("", 20);
panel1.add(fa8);
fl8.setBounds(560, 500, 40, 20);
fa8.setBounds(600, 500, 100, 20);
fa8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 8;
list1.removeAll();
for (int i = 0; i < variabl2607.length; i++) {
list1.add(variabl2607[i]);
}
}
});
list1.setBounds(840, 10, 120, 430);
panel1.add(list1);
list1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list1.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
String s0 = "";
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:
fa1.setText(list1.getSelectedItem());
break;
case 2:
fa2.setText(list1.getSelectedItem());
break;
case 3:
fa3.setText(list1.getSelectedItem());
break;
case 4:
fa4.setText(list1.getSelectedItem());
break;
case 5:
fa5.setText(list1.getSelectedItem());
break;
case 6:
fa6.setText(list1.getSelectedItem());
break;
case 7:
fa7.setText(list1.getSelectedItem());
break;
case 8:
fa8.setText(list1.getSelectedItem());
break;
case 11:
fa11.setText(list1.getSelectedItem());
break;
case 12:
fa12.setText(list1.getSelectedItem());
break;
}
}
}
});
final JButton addButton = new JButton("添加到表格中");
addButton.setBounds(50, 540, 120, 20);
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < variabl19651.getRowCount(); i++) {
if ((variabl19651.getValueAt(i, 0) != null)
&& (variabl19651.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fa1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 < 0) {
String[] rowValues = { fa1.getText(), fa2.getText(),
fa11.getText(), fa12.getText(), fa3.getText(),
fa4.getText(), fa5.getText(), fa6.getText(),
fa7.getText(), fa8.getText() };
variabl19651.addRow(rowValues);
int rowCount = variabl26551.getRowCount() + 1;
fa1.setText("");
fa2.setText("0");
fa3.setText("0");
fa4.setText("0");
fa5.setText("0");
fa6.setText("0");
fa7.setText("");
fa8.setText("0");
fa11.setText("0");
fa12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel1.add(addButton);
final JButton updButton = new JButton("修改表格数据");
updButton.setBounds(170, 540, 120, 20);
updButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1;
for (int i = 0; i < variabl19651.getRowCount(); i++) {
if ((variabl19651.getValueAt(i, 0) != null)
&& (variabl19651.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fa1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 >= 0) {
variabl19651.setValueAt(fa1.getText(), variabl1823, 0);
variabl19651.setValueAt(fa2.getText(), variabl1823, 1);
variabl19651.setValueAt(fa11.getText(), variabl1823, 2);
variabl19651.setValueAt(fa12.getText(), variabl1823, 3);
variabl19651.setValueAt(fa3.getText(), variabl1823, 4);
variabl19651.setValueAt(fa4.getText(), variabl1823, 5);
variabl19651.setValueAt(fa5.getText(), variabl1823, 6);
variabl19651.setValueAt(fa6.getText(), variabl1823, 7);
variabl19651.setValueAt(fa7.getText(), variabl1823, 8);
variabl19651.setValueAt(fa8.getText(), variabl1823, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel1.add(updButton);
final JButton delButton = new JButton("从表格中删除");
delButton.setBounds(290, 540, 120, 20);
delButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = variabl26551.getSelectedRow();
if (variabl1823 != -1)
variabl19651.removeRow(variabl1823);
}
});
panel1.add(delButton);
final JButton countButton = new JButton("辅助计算");
countButton.setBounds(410, 540, 120, 20);
countButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl2059 = variabl19651.getRowCount();
String[][] variabl2649 = new String[variabl2059][11];
int[][] variabl26491 = new int[variabl2059][11];
for (int i = 0; i < variabl2059; i++) {
for (int j = 0; j < 10; j++)
variabl2649[i][j] = variabl19651.getValueAt(i, j)
.toString().trim();
for (int j = 4; j < 10; j++) {
if (j != 8) {
if (variabl2649[i][j].length() > 0)
variabl26491[i][j] = Integer
.valueOf(variabl2649[i][j]);
else
variabl26491[i][j] = 0;
}
}
for (int j = 4; j < 8; j++) {
if (j != 5)
variabl26491[i][j] = variabl26491[i][j]
* variabl26491[i][9];
else
variabl26491[i][j] = (int) (variabl26491[i][j]
* variabl26491[i][9] * 1.12);
variabl2649[i][j] = "" + variabl26491[i][j];
}
}
variabl19651.setRowCount(0);
for (int i = 0; i < variabl2059; i++)
variabl19651.addRow(variabl2649[i]);
}
});
panel1.add(countButton);
final JButton creButton = new JButton("表格内容存盘");
creButton.setBounds(530, 540, 120, 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);
for (int i = 0; i < variabl19651.getRowCount(); i++) {
String s3 = "1,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((variabl19651.getValueAt(i, j) != null)
&& (variabl19651.getValueAt(i, j)
.toString().length() > 0))
s3 = s3
+ variabl19651.getValueAt(i, j)
.toString() + "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
for (int i = 0; i < variabl19652.getRowCount(); i++) {
String s3 = "2,", s4 = "";
for (int j = 0; j < 11; j++) {
if ((variabl19652.getValueAt(i, j) != null)
&& (variabl19652.getValueAt(i, j)
.toString().length() > 0))
s3 = s3
+ variabl19652.getValueAt(i, j)
.toString() + "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
for (int i = 0; i < variabl19653.getRowCount(); i++) {
String s3 = "3,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((variabl19653.getValueAt(i, j) != null)
&& (variabl19653.getValueAt(i, j)
.toString().length() > 0))
s3 = s3
+ variabl19653.getValueAt(i, j)
.toString() + "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
fs.close();
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "写文件错。");
}
}
});
panel1.add(creButton);
final JButton clearButton = new JButton("清参数文本框");
clearButton.setBounds(650, 540, 120, 20);
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fa1.setText("");
fa2.setText("0");
fa3.setText("0");
fa4.setText("0");
fa5.setText("0");
fa6.setText("0");
fa7.setText("");
fa8.setText("0");
fa11.setText("0");
fa12.setText("0");
}
});
panel1.add(clearButton);
final JButton exitButton = new JButton("退出");
exitButton.setBounds(770, 540, 120, 20);
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
panel1.setVisible(false);
frame1.setVisible(false);
frame1.dispose();
frame2.setVisible(false);
frame2.dispose();
frame3.setVisible(false);
frame3.dispose();
}
});
panel1.add(exitButton);
fla1 = new JLabel("标签内容");
fla1.setBounds(20, 460, 60, 20);
panel2.add(fla1);
faa1 = new JTextField("", 20);
faa1.setBounds(80, 460, 100, 20);
panel2.add(faa1);
faa1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 1;
list2.removeAll();
for (int i = 0; i < variabl2651; i++) {
list2.add(variabl25171[i]);
}
}
});
fla2 = new JLabel("字段名称");
fla2.setBounds(180, 460, 60, 20);
panel2.add(fla2);
faa2 = new JTextField("", 20);
faa2.setBounds(240, 460, 100, 20);
panel2.add(faa2);
faa2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 2;
list2.removeAll();
for (int i = 0; i < variabl2651; i++) {
list2.add(variabl25171[i]);
}
}
});
fla11 = new JLabel("行号");
fla11.setBounds(340, 460, 40, 20);
panel2.add(fla11);
faa11 = new JTextField("", 20);
faa11.setBounds(380, 460, 60, 20);
panel2.add(faa11);
faa11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 11;
list2.removeAll();
}
});
fla12 = new JLabel("列号");
fla12.setBounds(440, 460, 40, 20);
panel2.add(fla12);
faa12 = new JTextField("", 20);
faa12.setBounds(480, 460, 60, 20);
panel2.add(faa12);
faa12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 12;
list2.removeAll();
}
});
fla3 = new JLabel("标签宽度");
fla3.setBounds(540, 460, 60, 20);
panel2.add(fla3);
faa3 = new JTextField("", 20);
faa3.setBounds(600, 460, 60, 20);
panel2.add(faa3);
faa3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 3;
list2.removeAll();
}
});
fla4 = new JLabel("字段宽度");
fla4.setBounds(680, 460, 60, 20);
panel2.add(fla4);
faa4 = new JTextField("", 20);
faa4.setBounds(740, 460, 60, 20);
panel2.add(faa4);
faa4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 4;
list2.removeAll();
}
});
fla5 = new JLabel("高度");
fla5.setBounds(20, 500, 60, 20);
panel2.add(fla5);
faa5 = new JTextField("", 20);
faa5.setBounds(80, 500, 100, 20);
panel2.add(faa5);
faa5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 5;
list2.removeAll();
}
});
fla6 = new JLabel("左边距");
fla6.setBounds(200, 500, 40, 20);
panel2.add(fla6);
faa6 = new JTextField("", 20);
faa6.setBounds(240, 500, 80, 20);
panel2.add(faa6);
faa6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 6;
list2.removeAll();
}
});
fla7 = new JLabel("到顶距");
fla7.setBounds(340, 500, 40, 20);
panel2.add(fla7);
faa7 = new JTextField("", 20);
faa7.setBounds(380, 500, 80, 20);
panel2.add(faa7);
faa7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 7;
list2.removeAll();
}
});
fla8 = new JLabel("字体");
panel2.add(fla8);
faa8 = new JTextField("", 20);
panel2.add(faa8);
fla8.setBounds(480, 500, 40, 20);
faa8.setBounds(520, 500, 80, 20);
faa8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 8;
list2.removeAll();
for (int i = 0; i < variabl2629.length; i++) {
list2.add(variabl2629[i]);
}
}
});
fla9 = new JLabel("字号");
panel2.add(fla9);
faa9 = new JTextField("", 20);
panel2.add(faa9);
fla9.setBounds(620, 500, 40, 20);
faa9.setBounds(660, 500, 80, 20);
faa9.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 9;
for (int i = 0; i < variabl2607.length; i++) {
list2.add(variabl2607[i]);
}
}
});
faa1.setText(" ");
faa2.setText(" ");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("0");
faa8.setText("宋体");
faa9.setText("0");
faa11.setText("0");
faa12.setText("0");
list2.setBounds(840, 10, 120, 430);
panel2.add(list2);
list2.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list2.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (variabl1739) {
case 1:
faa1.setText(list2.getSelectedItem());
faa2.setText(list2.getSelectedItem());
variabl2127 = list2.getSelectedIndex();
if (((main1.variabl1537 + main1.variabl1539)
.lastIndexOf("," + variabl1501[variabl2127])) < 0) {
faa4.setText("" + variabl1489[variabl2127]);
faa3.setText(""
+ variabl25171[variabl2127].length());
faa5.setText("1");
}
faa8.setText("宋体");
faa9.setText("12");
break;
case 2:
faa2.setText(list2.getSelectedItem());
break;
case 3:
faa3.setText(list2.getSelectedItem());
break;
case 4:
faa4.setText(list2.getSelectedItem());
break;
case 5:
faa5.setText(list2.getSelectedItem());
break;
case 6:
faa6.setText(list2.getSelectedItem());
break;
case 7:
faa7.setText(list2.getSelectedItem());
break;
case 8:
faa8.setText(list2.getSelectedItem());
break;
case 9:
faa9.setText(list2.getSelectedItem());
break;
case 11:
faa11.setText(list2.getSelectedItem());
break;
case 12:
faa12.setText(list2.getSelectedItem());
break;
}
}
}
});
variabl26552.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int variabl1823 = variabl26552.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (variabl19652.getValueAt(variabl1823, j) != null)
variabl2327 = variabl19652.getValueAt(variabl1823, j)
.toString();
else
variabl2327 = "";
switch (j) {
case 0:
faa1.setText(variabl2327.toString());
break;
case 2:
faa11.setText(variabl2327.toString());
break;
case 3:
faa12.setText(variabl2327.toString());
break;
case 1:
faa2.setText(variabl2327.toString());
break;
case 4:
faa3.setText(variabl2327.toString());
break;
case 5:
faa4.setText(variabl2327.toString());
break;
case 6:
faa5.setText(variabl2327.toString());
break;
case 7:
faa6.setText(variabl2327.toString());
break;
case 8:
faa7.setText(variabl2327.toString());
break;
case 9:
faa8.setText(variabl2327.toString());
break;
case 10:
faa9.setText(variabl2327.toString());
break;
}
}
}
});
final JButton addButton1 = new JButton("添加到表格中");
addButton1.setBounds(50, 540, 170, 20);
addButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < variabl19652.getRowCount(); i++) {
if ((variabl19652.getValueAt(i, 0) != null)
&& (variabl19652.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(faa1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 < 0) {
String[] rowValues = { faa1.getText(), faa2.getText(),
faa11.getText(), faa12.getText(), faa3.getText(),
faa4.getText(), faa5.getText(), faa6.getText(),
faa7.getText(), faa8.getText(), faa9.getText() };
variabl19652.addRow(rowValues);
faa1.setText(" ");
faa2.setText(" ");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("0");
faa8.setText("宋体");
faa9.setText("0");
faa11.setText("0");
faa12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel2.add(addButton1);
final JButton updButton1 = new JButton("修改表格数据");
updButton1.setBounds(220, 540, 170, 20);
updButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1;
for (int i = 0; i < variabl19652.getRowCount(); i++) {
if ((variabl19652.getValueAt(i, 0) != null)
&& (variabl19652.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(faa1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 >= 0) {
variabl19652.setValueAt(faa1.getText(), variabl1823, 0);
variabl19652.setValueAt(faa11.getText(), variabl1823, 2);
variabl19652.setValueAt(faa12.getText(), variabl1823, 3);
variabl19652.setValueAt(faa2.getText(), variabl1823, 1);
variabl19652.setValueAt(faa3.getText(), variabl1823, 4);
variabl19652.setValueAt(faa4.getText(), variabl1823, 5);
variabl19652.setValueAt(faa5.getText(), variabl1823, 6);
variabl19652.setValueAt(faa6.getText(), variabl1823, 7);
variabl19652.setValueAt(faa7.getText(), variabl1823, 8);
variabl19652.setValueAt(faa8.getText(), variabl1823, 9);
variabl19652.setValueAt(faa9.getText(), variabl1823, 10);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel2.add(updButton1);
final JButton delButton1 = new JButton("从表格中删除");
delButton1.setBounds(390, 540, 170, 20);
delButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = variabl26552.getSelectedRow();
if (variabl1823 != -1)
variabl19652.removeRow(variabl1823);
}
});
panel2.add(delButton1);
final JButton countButton1 = new JButton("辅助计算");
countButton1.setBounds(560, 540, 170, 20);
countButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] variabl1919 = new String[11];
int variabl2707 = 0, variabl2705 = 0, variabl2703 = 0;
int variabl1397 = 0;
int variabl2243 = 0;
int[] variabl13611 = new int[150];
int[] variabl13612 = new int[150];
int variabl2027 = 0;
for (int i = 0; i < variabl19652.getRowCount(); i++) {
variabl2703 = Integer.valueOf(variabl19652.getValueAt(i, 3)
.toString());
if ((variabl2703 == 1)
&& (Integer.valueOf(variabl19652.getValueAt(i, 4)
.toString()) > variabl2027))
variabl2027 = Integer.valueOf(variabl19652.getValueAt(
i, 4).toString());
}
for (int i = 0; i < variabl19652.getRowCount(); i++) {
if (Integer.valueOf(variabl19652.getValueAt(i, 3)
.toString()) == 1) {
variabl19652.setValueAt("" + variabl2027, i, 4);
}
}
for (int i = 0; i < variabl19652.getRowCount(); i++) {
variabl2707 = Integer.valueOf(variabl19652.getValueAt(i, 6)
.toString());
variabl2705 = Integer.valueOf(variabl19652.getValueAt(i, 2)
.toString());
variabl2703 = Integer.valueOf(variabl19652.getValueAt(i, 3)
.toString());
if (variabl2705 > variabl2243)
variabl2243 = variabl2705;
if (variabl2707 > 1) {
for (int j = 1; j < 11; j++)
variabl1919[j] = variabl19652.getValueAt(i, j)
.toString();
if ((variabl2703 == 1)
|| (variabl2703 == 2 && variabl13611[variabl2705] == 1)) {
if (variabl13611[variabl2705] == 0)
variabl13611[variabl2705] = 1;
for (int j = 1; j < variabl2707; j++) {
variabl1919[3] = "0";
variabl1919[2] = (variabl2705 + j) + "";
if (variabl2705 + j > variabl2243)
variabl2243 = variabl2705 + j;
variabl1919[6] = "1";
variabl19652.addRow(variabl1919);
}
} else {
if (variabl13611[variabl2705] == 0)
variabl13611[variabl2705] = variabl2705 + 1;
variabl13612[variabl2705] = variabl2707;
for (int j = 1; j < variabl2707; j++) {
variabl1919[3] = "98";
variabl1919[2] = (variabl2705 + j) + "";
variabl13612[variabl2705 + j] = variabl2707;
if (variabl2705 + j > variabl2243)
variabl2243 = variabl2705 + j;
variabl1919[6] = "1";
variabl19652.addRow(variabl1919);
}
}
}
}
int variabl2059 = variabl19652.getRowCount();
String[][] variabl2649 = new String[variabl2059][15];
int[][] variabl26491 = new int[variabl2059][15];
int n1 = 0;
for (int i = 0; i < variabl2059; i++) {
for (int j = 1; j < 11; j++) {
if (variabl19652.getValueAt(i, j) != null) {
variabl2649[i][j - 1] = variabl19652.getValueAt(i,
j).toString();
} else
variabl2649[i][j - 1] = "0";
if (variabl19652.getValueAt(i, 0) == null)
variabl2649[i][12] = " ";
else
variabl2649[i][12] = variabl19652.getValueAt(i, 0)
.toString();
s2 = variabl2649[i][j - 1].trim();
if ((j > 1) && (j < 9) || (j == 10))
if ((s2 == null) || (s2.length() < 1))
variabl26491[i][j - 1] = 0;
else
variabl26491[i][j - 1] = Integer.valueOf(s2);
}
variabl2649[i][11] = "" + i;
variabl26491[i][11] = i;
}
String trim = "";
int trim1 = 0;
for (int i = 0; i < variabl2059 - 1; i++) {
for (int j = 0; j < variabl2059 - 1 - i; j++) {
if (variabl26491[j][1] * 100 + variabl26491[j][2] > variabl26491[j + 1][1]
* 100 + variabl26491[j + 1][2]) {
for (int k = 0; k < 15; k++) {
trim = variabl2649[j][k];
trim1 = variabl26491[j][k];
variabl2649[j][k] = variabl2649[j + 1][k];
variabl26491[j][k] = variabl26491[j + 1][k];
variabl2649[j + 1][k] = trim;
variabl26491[j + 1][k] = trim1;
}
}
}
}
int[] variabl1341 = new int[variabl2243 + 1];
int[] variabl1471 = new int[variabl2243 + 1];
int[] variabl1063 = new int[variabl26491.length];
int kuand = 0;
for (int i = 0; i < variabl26491.length; i++) {
variabl2705 = variabl26491[i][1];
variabl2703 = variabl26491[i][2];
if (variabl13612[variabl2705] > 0) {
if ((variabl2703 < 98) && (variabl26491[i][5] < 2)) {
if (variabl2703 > variabl1341[variabl2705]) {
variabl1341[variabl2705] = variabl2703;
variabl1063[variabl2705] = i;
}
variabl1471[variabl2705] = variabl1471[variabl2705]
+ variabl26491[i][3] + variabl26491[i][4];
if (variabl1471[variabl2705] > kuand)
kuand = variabl1471[variabl2705];
}
}
}
for (int i = 0; i < variabl26491.length; i++) {
variabl2705 = variabl26491[i][1];
variabl2703 = variabl26491[i][2];
if (variabl13612[variabl2705] > 0) {
for (int k1 = 1; k1 <= variabl2243; k1++) {
if ((variabl1063[k1] > 0) && (variabl1063[k1] == i)) {
variabl26491[i][4] = variabl26491[i][4] + kuand
- variabl1471[k1];
break;
}
}
}
}
variabl1341 = new int[variabl2243 + 1];
variabl1471 = new int[variabl2243 + 1];
variabl1063 = new int[variabl26491.length];
kuand = 0;
for (int i = 0; i < variabl26491.length; i++) {
variabl2705 = variabl26491[i][1];
variabl2703 = variabl26491[i][2];
if (variabl2703 >= variabl1341[variabl2705]) {
variabl1341[variabl2705] = variabl2703;
variabl1063[variabl2705] = i;
}
variabl1471[variabl2705] = variabl1471[variabl2705]
+ variabl26491[i][3] + variabl26491[i][4];
if (variabl1471[variabl2705] > kuand)
kuand = variabl1471[variabl2705];
}
for (int k1 = 0; k1 <= variabl2243; k1++) {
int k3 = variabl1063[k1];
if (k3 > 0) {
variabl26491[k3][4] = variabl26491[k3][4] + kuand
- variabl1471[k1];
}
}
int m1 = 0;
variabl2705 = 0;
for (int i = 0; i < variabl26491.length; i++) {
if (variabl26491[i][1] != variabl2705) {
variabl2705 = variabl26491[i][1];
m1 = 0;
}
variabl26491[i][6] = m1;
m1 = m1 + variabl26491[i][3] + variabl26491[i][4];
variabl26491[i][7] = variabl26491[i][1] - 1;
}
variabl19652.setRowCount(0);
for (int i = 0; i < variabl26491.length; i++) {
if ((variabl26491[i][2] > 0) && (variabl26491[i][2] < 98)) {
variabl2649[i][1] = variabl26491[i][1] + "";
variabl2649[i][2] = variabl26491[i][2] + "";
variabl2649[i][3] = variabl26491[i][3]
* variabl26491[i][9] + "";
variabl2649[i][4] = variabl26491[i][4]
* variabl26491[i][9] + "";
variabl2649[i][5] = (int) (variabl26491[i][5]
* variabl26491[i][9] * 2)
+ "";
variabl2649[i][6] = variabl26491[i][6]
* variabl26491[i][9] + "";
variabl2649[i][7] = (int) (variabl26491[i][7]
* variabl26491[i][9] * 2)
+ "";
}
}
for (int i = 0; i < variabl26491.length; i++) {
if ((variabl26491[i][2] > 0) && (variabl26491[i][2] < 98)) {
for (int j = 1; j < 11; j++) {
variabl1919[j] = variabl2649[i][j - 1];
}
variabl1919[0] = variabl2649[i][12];
variabl19652.addRow(variabl1919);
}
}
}
});
panel2.add(countButton1);
final JButton clearButton1 = new JButton("清参数文本框");
clearButton1.setBounds(730, 540, 170, 20);
clearButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
faa1.setText(" ");
faa2.setText(" ");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("0");
faa8.setText("宋体");
faa9.setText("0");
faa11.setText("0");
faa12.setText("0");
}
});
panel2.add(clearButton1);
flb1 = new JLabel("内容");
flb1.setBounds(70, 460, 40, 20);
panel3.add(flb1);
fab1 = new JTextField("", 20);
fab1.setBounds(110, 460, 100, 20);
panel3.add(fab1);
fab1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 1;
list3.removeAll();
}
});
flb2 = new JLabel("变量名");
flb2.setBounds(230, 460, 50, 20);
panel3.add(flb2);
fab2 = new JTextField("", 20);
fab2.setBounds(280, 460, 60, 20);
panel3.add(fab2);
fab2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 2;
list3.removeAll();
}
});
flb11 = new JLabel("行号");
flb11.setBounds(370, 460, 40, 20);
panel3.add(flb11);
fab11 = new JTextField("", 20);
fab11.setBounds(410, 460, 60, 20);
panel3.add(fab11);
fab11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 11;
list3.removeAll();
}
});
flb12 = new JLabel("列号");
flb12.setBounds(500, 460, 40, 20);
panel3.add(flb12);
fab12 = new JTextField("", 20);
fab12.setBounds(540, 460, 60, 20);
panel3.add(fab12);
fab12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 12;
list3.removeAll();
}
});
flb3 = new JLabel("宽度");
flb3.setBounds(630, 460, 40, 20);
panel3.add(flb3);
fab3 = new JTextField("", 20);
fab3.setBounds(670, 460, 60, 20);
panel3.add(fab3);
fab3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 3;
list3.removeAll();
}
});
flb4 = new JLabel("高度");
flb4.setBounds(760, 460, 40, 20);
panel3.add(flb4);
fab4 = new JTextField("", 20);
fab4.setBounds(800, 460, 60, 20);
panel3.add(fab4);
fab4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 4;
list3.removeAll();
}
});
flb5 = new JLabel("左边距");
flb5.setBounds(60, 500, 50, 20);
panel3.add(flb5);
fab5 = new JTextField("", 20);
fab5.setBounds(110, 500, 100, 20);
panel3.add(fab5);
fab5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 5;
list3.removeAll();
}
});
flb6 = new JLabel("到顶距");
panel3.add(flb6);
fab6 = new JTextField("", 20);
panel3.add(fab6);
flb6.setBounds(220, 500, 60, 20);
fab6.setBounds(280, 500, 60, 20);
fab6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 6;
list3.removeAll();
}
});
flb7 = new JLabel("字体");
panel3.add(flb7);
fab7 = new JTextField("", 20);
panel3.add(fab7);
flb7.setBounds(370, 500, 40, 20);
fab7.setBounds(410, 500, 120, 20);
fab7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 7;
list3.removeAll();
for (int i = 0; i < variabl2629.length; i++) {
list3.add(variabl2629[i]);
}
}
});
flb8 = new JLabel("字号");
panel3.add(flb8);
fab8 = new JTextField("", 20);
panel3.add(fab8);
flb8.setBounds(560, 500, 40, 20);
fab8.setBounds(600, 500, 100, 20);
fab8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 8;
list3.removeAll();
for (int i = 0; i < variabl2607.length; i++) {
list3.add(variabl2607[i]);
}
}
});
list3.setBounds(840, 10, 170, 430);
panel3.add(list3);
list3.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list3.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (variabl1739) {
case 1:
fab1.setText(list3.getSelectedItem());
break;
case 2:
fab2.setText(list3.getSelectedItem());
break;
case 3:
fab3.setText(list3.getSelectedItem());
break;
case 4:
fab4.setText(list3.getSelectedItem());
break;
case 5:
fab5.setText(list3.getSelectedItem());
break;
case 6:
fab6.setText(list3.getSelectedItem());
break;
case 7:
fab7.setText(list3.getSelectedItem());
break;
case 8:
fab8.setText(list3.getSelectedItem());
break;
case 11:
fab11.setText(list3.getSelectedItem());
break;
case 12:
fab12.setText(list3.getSelectedItem());
break;
}
}
}
});
variabl26553.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int variabl1823 = variabl26553.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (variabl19653.getValueAt(variabl1823, j) != null)
variabl2327 = variabl19653.getValueAt(variabl1823, j)
.toString();
else
variabl2327 = "";
switch (j) {
case 0:
fab1.setText(variabl2327.toString());
break;
case 1:
fab2.setText(variabl2327.toString());
break;
case 2:
fab11.setText(variabl2327.toString());
break;
case 3:
fab12.setText(variabl2327.toString());
break;
case 4:
fab3.setText(variabl2327.toString());
break;
case 5:
fab4.setText(variabl2327.toString());
break;
case 6:
fab5.setText(variabl2327.toString());
break;
case 7:
fab6.setText(variabl2327.toString());
break;
case 8:
fab7.setText(variabl2327.toString());
break;
case 9:
fab8.setText(variabl2327.toString());
break;
}
}
}
});
final JButton addButton3 = new JButton("添加到表格中");
addButton3.setBounds(50, 540, 170, 20);
addButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < variabl19653.getRowCount(); i++) {
if ((variabl19653.getValueAt(i, 0) != null)
&& (variabl19653.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fab1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 < 0) {
String[] rowValues = { fab1.getText(), fab2.getText(),
fab11.getText(), fab12.getText(), fab3.getText(),
fab4.getText(), fab5.getText(), fab6.getText(),
fab7.getText(), fab8.getText() };
variabl19653.addRow(rowValues);
int rowCount = variabl26553.getRowCount() + 1;
fab1.setText("");
fab2.setText("0");
fab3.setText("0");
fab4.setText("0");
fab5.setText("0");
fab6.setText("0");
fab7.setText("");
fab8.setText("0");
fab11.setText("0");
fab12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel3.add(addButton3);
final JButton updButton3 = new JButton("修改表格数据");
updButton3.setBounds(220, 540, 170, 20);
updButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1;
for (int i = 0; i < variabl19653.getRowCount(); i++) {
if ((variabl19653.getValueAt(i, 0) != null)
&& (variabl19653.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fab1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 >= 0) {
variabl19653.setValueAt(fab1.getText(), variabl1823, 0);
variabl19653.setValueAt(fab2.getText(), variabl1823, 1);
variabl19653.setValueAt(fab11.getText(), variabl1823, 2);
variabl19653.setValueAt(fab12.getText(), variabl1823, 3);
variabl19653.setValueAt(fab3.getText(), variabl1823, 4);
variabl19653.setValueAt(fab4.getText(), variabl1823, 5);
variabl19653.setValueAt(fab3.getText(), variabl1823, 6);
variabl19653.setValueAt(fab6.getText(), variabl1823, 7);
variabl19653.setValueAt(fab7.getText(), variabl1823, 8);
variabl19653.setValueAt(fab8.getText(), variabl1823, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel3.add(updButton3);
final JButton delButton3 = new JButton("从表格中删除");
delButton3.setBounds(390, 540, 170, 20);
delButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = variabl26553.getSelectedRow();
if (variabl1823 != -1)
variabl19653.removeRow(variabl1823);
}
});
panel3.add(delButton3);
final JButton countButton3 = new JButton("辅助计算");
countButton3.setBounds(560, 540, 170, 20);
countButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl2059 = variabl19653.getRowCount();
String[][] variabl2649 = new String[variabl2059][11];
int[][] variabl26491 = new int[variabl2059][11];
for (int i = 0; i < variabl2059; i++) {
for (int j = 0; j < 10; j++)
variabl2649[i][j] = variabl19653.getValueAt(i, j)
.toString().trim();
for (int j = 4; j < 10; j++) {
if (j != 8) {
if (variabl2649[i][j].length() > 0)
variabl26491[i][j] = Integer
.valueOf(variabl2649[i][j]);
else
variabl26491[i][j] = 0;
}
}
for (int j = 4; j < 8; j++) {
if (j != 5)
variabl26491[i][j] = variabl26491[i][j]
* variabl26491[i][9];
else
variabl26491[i][j] = (int) (variabl26491[i][j]
* variabl26491[i][9] * 1.12);
variabl2649[i][j] = "" + variabl26491[i][j];
}
}
variabl19653.setRowCount(0);
for (int i = 0; i < variabl2059; i++)
variabl19653.addRow(variabl2649[i]);
}
});
panel3.add(countButton3);
final JButton clearButton3 = new JButton("清参数文本框");
clearButton3.setBounds(730, 540, 170, 20);
clearButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fab1.setText("");
fab2.setText("0");
fab3.setText("0");
fab4.setText("0");
fab3.setText("0");
fab6.setText("0");
fab7.setText("");
fab8.setText("0");
fab11.setText("0");
fab12.setText("0");
}
});
panel3.add(clearButton3);
frame3.add(panel3);
frame2.add(panel2);
frame1.add(panel1);
frame3.setVisible(true);
frame2.setVisible(true);
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];
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];
}
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.close();
sta.close();
con.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
}
88.源码88,部件程序,表单式报表(单记录式报表)打印预览程序,可以打印预览文本域图片。
/**
* 程序文件名:dataPreview2.java
* 作者:程学先
* 功能:表单式报表(单记录式报表)打印预览程序,
* 根据printFormat5生成单记录式打印格式文件打印预览单记录式报表。
* 完成时间:2013年11月27日
* 调用语句:dataPreview2.means(parameter);
* 必须提供的参数:“数据表表名”、 “打印格式文件名称”。
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.table.*;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.ArrayList;
public class dataPreview2 extends JFrame {
static dataPreview2 frame = new dataPreview2();
static String variabl2603 = "";
static DefaultTableModel tableModel;
static JTable table;
static JScrollPane scrollPane = new JScrollPane();
static JScrollPane scrollPane1;
static JTextField aTextField;
static JButton previewButton2;
static String s1 = "", s2 = "", s3 = "";
static ResultSet rs;
static int variabl2651;
static String[] variabl2517;
static String[] variabl1501;
static int[] variabl1489;
static int[] variabl1119;
static int variabl1853, variabl2593 = -1;
static String[][] variabl2197;
static byte variabl2585[];
static String variabl1079;
private static ArrayList<struct1> title = new ArrayList<struct1>();
private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();
private static ArrayList<struct3> table1 = new ArrayList<struct3>();
static Connection cont4;
static ResultSetMetaData rsmd4;
static Statement stat4;
static int variabl2483 = 1000, variabl2503 = 600, variabl2681 = 600;
private static Graphics2D g3;
private static Graphics g;
private static Font font;
private static TextLayout layout;
public static String[] sw = new String[11];
static String[] variabl2405 = null;
static String variabl1187;
static int variabl2851 = 0, variabl2339 = 0;
private static String variabl2049 = "";
private static String variabl1633 = "";
private static int x1 = 0, y1 = 0, w1 = 0, w2 = 0, h1 = 0, variabl2661 = 0,
variabl2657 = 0, variabl2631 = 0, variabl2623 = 0;
static void print1() {
g3 = (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);
g3.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]) + 30;
g3.drawString(variabl2535[i].title[0], x1, y1);
variabl2657 = y1 + Integer.valueOf(variabl2535[i].title[5]);
}
struct2[] variabl2685 = new struct2[tableTitle.size()];
int[] w10 = new int[tableTitle.size()];
int[] w20 = new int[tableTitle.size()];
int[] h10 = new int[tableTitle.size()];
int[] h20 = new int[tableTitle.size()];
int[] t10 = new int[tableTitle.size()];
int[] l10 = new int[tableTitle.size()];
int[] le0 = new int[tableTitle.size()];
int[] f0 = new int[tableTitle.size()];
for (int i = 0; i < tableTitle.size(); i++) {
variabl2685[i] = tableTitle.get(i);
w10[i] = Integer.valueOf(variabl2685[i].tableTitle[4]);
w20[i] = Integer.valueOf(variabl2685[i].tableTitle[5]);
h10[i] = Integer.valueOf(variabl2685[i].tableTitle[6]);
h20[i] = Integer.valueOf(variabl2685[i].tableTitle[10]);
t10[i] = Integer.valueOf(variabl2685[i].tableTitle[8]);
l10[i] = Integer.valueOf(variabl2685[i].tableTitle[2]);
le0[i] = Integer.valueOf(variabl2685[i].tableTitle[7]);
for (int j = 0; j < variabl2651; j++) {
if (variabl2517[j]
.equalsIgnoreCase(variabl2685[i].tableTitle[1])) {
f0[i] = j;
break;
}
}
}
FontRenderContext frc = new FontRenderContext(null, false, false);
char p1 = 10, p2 = 13;
for (int i = 0; i < tableTitle.size(); i++) {
x1 = le0[i];
y1 = t10[i] + variabl2657;
w1 = w10[i];
w2 = w20[i];
h1 = h10[i];
if (l10[i] == 1) {
g3.drawLine(x1, y1, x1 + w1 + w2, y1);
if (x1 + w1 + w2 > variabl2623)
variabl2623 = x1 + w1 + w2;
}
g3.drawLine(x1, y1, x1, y1 + h1);
g3.setFont(new Font(variabl2685[i].tableTitle[9], Font.PLAIN,
Integer.valueOf(variabl2685[i].tableTitle[10])));
g3.drawLine(x1 + w10[i], y1, x1 + w1, y1 + h1);
if (variabl2197[variabl2593][f0[i]] == null)
variabl2197[variabl2593][f0[i]] = " ";
font = new Font(variabl2685[i].tableTitle[9], Font.PLAIN,
Integer.valueOf(variabl2685[i].tableTitle[10]));
g3.setFont(font);
g3.drawString(variabl2685[i].tableTitle[0], x1 + 2, y1 + h20[i]);
if (((main1.variabl1537 + main1.variabl1539).lastIndexOf(","
+ variabl1501[i] + ",") >= 0)
|| (h1 > h20[i] * 2)) {
if (main1.variabl1539.indexOf("," + variabl1501[i] + ",") >= 0) {
x1 = le0[i];
y1 = t10[i] + variabl2657;
w2 = w20[i];
h1 = h10[i];
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select " + variabl2517[i] + " from "
+ variabl2603;
if (variabl2603.indexOf(",") > 0)
sql = sql + variabl2049;
if ((sw[3].length() > 0) && (sw[4].length() > 0))
if (sql.indexOf("where") > 0)
sql = sql + " and " + sw[4] + " = '" + sw[5]
+ "'";
else
sql = sql + " where " + sw[4] + " = '" + sw[5]
+ "'";
rs = stat4.executeQuery(sql);
rs.absolute(variabl2593 + 1);
InputStream image = rs.getBinaryStream(variabl2517[i]);
String image0 = image.toString();
long length = image0.length();
byte[] buffer = new byte[(int) length / 7];
File file = new File("a1.jpg");
int ch = 0;
if (file.exists()) {
file.delete();
}
file.createNewFile();
FileOutputStream file1 = new FileOutputStream(file,
true);
boolean go = true;
while (go) {
while ((ch = image.read(buffer)) != -1) {
file1.write(buffer);
}
go = false;
}
BufferedImage image1 = ImageIO.read(file);
g.drawImage(image1, x1 + w1 + 2, y1, w2, h1, null);
rs.close();
file1.close();
stat4.close();
cont4.close();
} catch (Exception e) {
e.printStackTrace();
}
} else {
int j = 0, y2 = y1;
float j1 = 0f;
s2 = variabl2197[variabl2593][f0[i]];
s3 = "";
if ((s2.lastIndexOf("" + p1) < s2.length())
&& (s2.lastIndexOf("" + p1) > 0))
s2 = s2 + p1;
for (int k = 0; k < s2.length(); k++) {
if ((j1 < w2)
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p1))
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p2)) && (k != s2.length() - 1)) {
s3 = s3 + s2.substring(k, k + 1);
if (s2.substring(k, k + 1).compareTo("z") < 0) {
if (s2.substring(k, k + 1).compareTo("0") < 0)
j1 = j1 + h20[i] * 0.43f;
else
j1 = j1 + h20[i] * 0.64f;
} else
j1 = j1 + h20[i];
} else {
if (j1 >= w2)
s3 = s3 + s2.substring(k, k + 1);
j = j + h20[i];
if (j1 >= w2 - 2) {
layout = new TextLayout(s3, font, frc)
.getJustifiedLayout(w2 - 2);
;
layout.draw(g3, x1 + w1 + 2, y2 + h20[i]);
} else
g3.drawString(s3, x1 + w1 + 2, y2 + h20[i]);
y2 = y2 + h20[i];
s3 = "";
j1 = 0;
}
if (j >= h1)
break;
}
}
}
else {
g3.drawString(variabl2197[variabl2593][f0[i]], x1 + w1 + 2, y1
+ h20[i]);
}
g3.drawLine(x1, y1 + h1, x1 + w1 + w2, y1 + h1);
if (y1 + h1 > variabl2631)
variabl2631 = y1 + h1;
}
g3.drawLine(variabl2623, t10[0] + variabl2657, variabl2623, variabl2631);
y1 = variabl2631 + 10;
struct3[] variabl2665 = new struct3[table1.size()];
for (int i = 0; i < table1.size(); i++) {
variabl2665[i] = table1.get(i);
g3.setFont(new Font(variabl2665[i].table1[8], Font.PLAIN, Integer
.valueOf(variabl2665[i].table1[9])));
x1 = Integer.valueOf(variabl2665[i].table1[6]);
y1 = y1 + Integer.valueOf(variabl2665[i].table1[5]);
g3.drawString(variabl2665[i].table1[0], x1, y1);
}
}
public static void means(String[] parameter) {
sw = new String[11];
sw[1] = main1.sw1 + "";
sw[2] = main1.sw2;
sw[3] = main1.sw3;
sw[4] = main1.sw4;
sw[5] = main1.sw5;
sw[6] = main1.sw6;
sw[7] = main1.sw7;
sw[8] = main1.sw8;
sw[9] = main1.sw9;
sw[10] = main1.sw10;
main1.sw1 = 0;
main1.sw2 = "";
main1.sw3 = "";
main1.sw4 = "";
main1.sw5 = "";
main1.sw6 = "";
main1.sw7 = "";
main1.sw8 = "";
main1.sw9 = "";
main1.sw10 = "";
frame = new dataPreview2();
variabl2603 = "";
scrollPane = new JScrollPane();
s1 = "";
s2 = "";
s3 = "";
variabl2593 = -1;
title = new ArrayList<struct1>();
tableTitle = new ArrayList<struct2>();
table1 = new ArrayList<struct3>();
variabl2483 = 1000;
variabl2503 = 600;
variabl2681 = 600;
x1 = 0;
y1 = 0;
w1 = 0;
w2 = 0;
h1 = 0;
variabl2661 = 0;
variabl2657 = 0;
variabl2631 = 0;
variabl2623 = 0;
variabl2603 = parameter[4];
variabl1079 = parameter[15];
variabl2049 = parameter[20];
String[] variabl240501 = { "当前记录预览", "预览下一条", "退出" };
variabl2405 = new String[variabl240501.length];
variabl2851 = 0;
for (int i0 = 0; i0 < variabl240501.length; i0++)
variabl2405[i0] = variabl240501[i0];
if (parameter[11].length() > 0) {
variabl1187 = parameter[11];
variabl1187 = variabl1187.replaceAll(";", ";");
variabl1187 = variabl1187.replaceAll("。", ";");
variabl1187 = variabl1187.replaceAll(":", ";");
variabl1187 = variabl1187.replaceAll(":", ";");
if (variabl1187.indexOf(";") > 0) {
String s601[] = variabl1187.split(",");
variabl1187 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (s601[i01].indexOf(";") > 0) {
String s602[] = s601[i01].split(";");
variabl2405[Integer.parseInt((s602[0]))] = s602[1];
variabl1187 = variabl1187 + "," + s602[0];
variabl2851++;
} else {
variabl1187 = variabl1187 + "," + s601[i01];
variabl2851++;
}
}
} else {
String s601[] = variabl1187.split(",");
variabl1187 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (i01 == 0)
variabl1187 = s601[i01];
else
variabl1187 = variabl1187 + "," + s601[i01];
variabl2851++;
}
}
} else {
variabl1187 = "";
for (int i1 = 0; i1 < variabl2405.length; i1++) {
if (i1 == 0)
variabl1187 = variabl1187 + i1;
else
variabl1187 = variabl1187 + "," + i1;
variabl2851++;
}
}
variabl1187 = "," + variabl1187 + ",";
variabl2483 = main1.variabl2483;
variabl2503 = main1.variabl2503;
int m1, m2;
try {
if (parameter[17].length() == 0) {
m1 = 0;
m2 = 0;
} else {
m1 = Integer.parseInt(parameter[17]);
m2 = Integer.parseInt(parameter[18]);
}
if (m1 > 0) {
if (m2 < 80) {
m1 = m1 * 10;
m2 = m2 * 10;
}
variabl2483 = m1;
variabl2503 = m2;
}
} catch (Exception e2) {
}
File file1 = new File(variabl1079);
try {
if (file1.exists()) {
FileReader fr = new FileReader(file1);
BufferedReader br = new BufferedReader(fr);
String tempStr = null;
int variabl2593 = 0, variabl2547 = 0;
String[] su1 = new String[11];
for (int i = 0; (tempStr = br.readLine()) != null; i++) {
if (tempStr.substring(0, 4).indexOf("。2") > 0) {
String[] su = tempStr.split("。");
su1[2] = su[8];
su1[3] = su[9];
su1[0] = su[10];
su1[1] = su[11];
su1[4] = su[17];
su1[5] = su[21];
su1[6] = su[18];
su1[7] = su[15];
su1[8] = su[16];
su1[9] = su[23];
su1[10] = su[24];
tableTitle.add(new struct2(su1));
} else if (tempStr.substring(0, 2).equals("1,")) {
title.add(new struct1(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("2,")) {
tableTitle.add(new struct2(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("3,")) {
table1.add(new struct3(tempStr.substring(2,
tempStr.length()).split("。")));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
variabl1633 = "";
for (int i = 0; i < tableTitle.size(); i++) {
if (variabl1633.length() == 0)
variabl1633 = tableTitle.get(i).tableTitle[1];
else
variabl1633 = variabl1633 + ","
+ tableTitle.get(i).tableTitle[1];
}
数据表查询结构(variabl2603);
数据表查询数据(variabl2603);
frame.setLayout(null);
frame.setTitle("单记录式报表预览程序 作者:程学先");
frame.setBounds(10, 10, variabl2483 - 10, 1000);
frame.getContentPane().setLayout(null);
final JPanel panel = new JPanel();
panel.setBounds(10, 10, variabl2483 - 50, 1000);
panel.setLayout(null);
frame.getContentPane().add(panel);
tableModel = new DefaultTableModel(variabl2197, variabl2517);
table = new JTable(tableModel);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane.getViewport().add(table, null);
scrollPane.setBounds(30, 50, variabl2483 - 100, variabl2503 - 150);
panel.add(scrollPane);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
variabl2593 = table.getSelectedRow();
}
});
variabl2339 = (variabl2483 - 160) / variabl2851;
int variabl2337 = 100;
final JButton previewButton1 = new JButton(variabl2405[0]);
previewButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (variabl2593 < 0) {
variabl2593 = 1;
} else {
panel.remove(scrollPane);
g = panel.getGraphics();
panel.paint(g);
print1();
previewButton2.setEnabled(true);
}
}
});
previewButton1.setBounds(variabl2337, 20, variabl2339, 20);
if (variabl1187.indexOf(",0,") >= 0) {
variabl2337 = variabl2337 + variabl2339;
panel.add(previewButton1);
}
previewButton2 = new JButton(variabl2405[1]);
previewButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (variabl1853 > variabl2593) {
g.clearRect(0, 0, 1000, 800);
variabl2593++;
panel.paint(g);
print1();
}
}
});
previewButton2.setBounds(variabl2337, 20, variabl2339, 20);
if (variabl1187.indexOf(",1,") >= 0) {
variabl2337 = variabl2337 + variabl2339;
panel.add(previewButton2);
previewButton2.setEnabled(false);
}
final JButton exitButton = new JButton(variabl2405[2]);
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ((sw[2].length() > 0) && (sw[3].length() > 0)
&& (sw[4].length() > 0))
WorkflowDrivek1.means(sw);
panel.setVisible(false);
frame.setVisible(false);
frame.dispose();
}
});
exitButton.setBounds(variabl2337, 20, variabl2339, 20);
if (variabl1187.indexOf(",2,") >= 0) {
variabl2337 = variabl2337 + variabl2339;
panel.add(exitButton);
}
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
static void 数据表查询结构(String variabl2217) {
String[] s10 = null;
String[] sk = new String[300];
int n1 = 0, n2 = 0;
variabl2049 = "";
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);
rsmd4 = rs.getMetaData();
variabl2651 = rsmd4.getColumnCount();
variabl2517 = new String[variabl2651];
variabl1501 = new String[variabl2651];
variabl1489 = new int[variabl2651];
for (int i = 0; i < variabl2651; i++) {
variabl2517[i] = rsmd4.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);
rsmd4 = rs.getMetaData();
variabl2651 = rsmd4.getColumnCount();
for (int j = 0; j < variabl2651; j++) {
s2 = rsmd4.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;
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select " + variabl1633 + " from " + variabl2217
+ variabl2049;
rs = stat4.executeQuery(s1);
rsmd4 = rs.getMetaData();
variabl2651 = rsmd4.getColumnCount();
variabl2517 = new String[variabl2651];
variabl1501 = new String[variabl2651];
variabl1489 = new int[variabl2651];
for (int i1 = 0; i1 < variabl2651; i1++) {
variabl2517[i1] = rsmd4.getColumnName(i1 + 1);
variabl1501[i1] = rsmd4.getColumnTypeName(i1 + 1);
variabl1489[i1] = rsmd4.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, "读取数据库数据出错!");
}
}
}
89.源码89,部件程序,表单式报表(单记录式报表)打印程序,可以打印文本域图片。
/**
* 程序文件名:dataPrint2.java
* 作者:程学先
* 功能:表单式报表(单记录式报表)打印程序,
* 根据printFormat5生成单记录式打印格式文件打印单记录式报表。
* 完成时间:2013年11月27日
* 调用语句:dataPrint2.means(parameter);
* 必须提供的参数:“数据表表名”、 “打印格式文件名称”。
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
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 javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.table.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.ArrayList;
import java.util.HashSet;
public class dataPrint2 extends JFrame {
static dataPrint2 frame = new dataPrint2();
static String variabl2603 = "";
static DefaultTableModel tableModel;
static JTable table;
static JScrollPane scrollPane = new JScrollPane();
static JScrollPane scrollPane1;
static JTextField aTextField;
static JButton previewButton2;
static String s1 = "", s2 = "", s3 = "";
static ResultSet rs;
static int variabl2651;
static String[] variabl2517;
static String[] variabl1501;
static int[] variabl1489;
static int[] variabl1119;
static int variabl1853, variabl2593 = -1;
static String[][] variabl2197;
static byte variabl2585[];
static String variabl1079;
private static ArrayList<struct1> title = new ArrayList<struct1>();
private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();
private static ArrayList<struct3> table1 = new ArrayList<struct3>();
static Connection cont4;
static ResultSetMetaData rsmd4;
static Statement stat4;
static int variabl2483 = 1000, variabl2503 = 600, variabl2681 = 600;
private static Graphics2D g3;
private static Graphics g;
private static Font font;
private static TextLayout layout;
public static String[] sw = new String[11];
static String[] variabl2405 = null;
static String variabl1187;
static int variabl2851 = 0, variabl2339 = 0;
private static String variabl2049 = "";
private static String variabl1633 = "";
private static int x1 = 0, y1 = 0, w1 = 0, w2 = 0, h1 = 0, variabl2661 = 0, variabl2657 = 0,
variabl2631 = 0, variabl2623 = 0;
static void print1() {
struct1[] variabl2535 = new struct1[title.size()];
variabl2657 = 0;
variabl2661 = 0;
for (int i = 0; i < title.size(); i++) {
variabl2535[i] = title.get(i);
g3.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]) + 30;
g3.drawString(variabl2535[i].title[0], x1, y1);
variabl2657 = y1 + Integer.valueOf(variabl2535[i].title[5]);
}
struct2[] variabl2685 = new struct2[tableTitle.size()];
int[] w10 = new int[tableTitle.size()];
int[] w20 = new int[tableTitle.size()];
int[] h10 = new int[tableTitle.size()];
int[] h20 = new int[tableTitle.size()];
int[] t10 = new int[tableTitle.size()];
int[] l10 = new int[tableTitle.size()];
int[] le0 = new int[tableTitle.size()];
int[] f0 = new int[tableTitle.size()];
for (int i = 0; i < tableTitle.size(); i++) {
variabl2685[i] = tableTitle.get(i);
w10[i] = Integer.valueOf(variabl2685[i].tableTitle[4]);
w20[i] = Integer.valueOf(variabl2685[i].tableTitle[5]);
h10[i] = Integer.valueOf(variabl2685[i].tableTitle[6]);
h20[i] = Integer.valueOf(variabl2685[i].tableTitle[10]);
t10[i] = Integer.valueOf(variabl2685[i].tableTitle[8]);
l10[i] = Integer.valueOf(variabl2685[i].tableTitle[2]);
le0[i] = Integer.valueOf(variabl2685[i].tableTitle[7]);
for (int j = 0; j < variabl2651; j++)
if (variabl2517[j].trim().equalsIgnoreCase(variabl2685[i].tableTitle[1].trim())) {
f0[i] = j;
break;
}
}
FontRenderContext frc = new FontRenderContext(null, false, false);
char p1 = 10, p2 = 13;
for (int i = 0; i < tableTitle.size(); i++) {
x1 = le0[i];
y1 = t10[i] + variabl2657;
w1 = w10[i];
w2 = w20[i];
h1 = h10[i];
if (l10[i] == 1) {
g3.drawLine(x1, y1, x1 + w1 + w2, y1);
if (x1 + w1 + w2 > variabl2623)
variabl2623 = x1 + w1 + w2;
}
g3.drawLine(x1, y1, x1, y1 + h1);
g3.setFont(new Font(variabl2685[i].tableTitle[9], Font.PLAIN, Integer
.valueOf(variabl2685[i].tableTitle[10])));
g3.drawLine(x1 + w10[i], y1, x1 + w1, y1 + h1);
if (variabl2197[variabl2593][f0[i]] == null)
variabl2197[variabl2593][f0[i]] = " ";
font = new Font(variabl2685[i].tableTitle[9], Font.PLAIN,
Integer.valueOf(variabl2685[i].tableTitle[10]));
g3.setFont(font);
g3.drawString(variabl2685[i].tableTitle[0], x1 + 2, y1 + h20[i]);
if (((main1.variabl1537 + main1.variabl1539)
.lastIndexOf("," + variabl1501[i] + ",") >= 0)
|| (h1 > h20[i] * 2)) {
if (main1.variabl1539.indexOf("," + variabl1501[i] + ",") >= 0) {
x1 = le0[i];
y1 = t10[i] + variabl2657;
w2 = w20[i];
h1 = h10[i];
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select " + variabl2517[i] + " from " + variabl2603;
if (variabl2603.indexOf(",") > 0)
sql = sql + variabl2049;
if ((sw[3].length() > 0) && (sw[4].length() > 0))
if (sql.indexOf("where") > 0)
sql = sql + " and " + sw[4] + " = '" + sw[5]
+ "'";
else
sql = sql + " where " + sw[4] + " = '" + sw[5]
+ "'";
rs = stat4.executeQuery(sql);
rs.absolute(variabl2593 + 1);
InputStream image = rs.getBinaryStream(variabl2517[i]);
String image0 = image.toString();
long length = image0.length();
byte[] buffer = new byte[(int) length / 7];
File file = new File("a1.jpg");
int ch = 0;
if (file.exists()) {
file.delete();
}
file.createNewFile();
FileOutputStream file1 = new FileOutputStream(file,
true);
boolean go = true;
while (go) {
while ((ch = image.read(buffer)) != -1) {
file1.write(buffer);
}
go = false;
}
BufferedImage image1 = ImageIO.read(file);
g.drawImage(image1, x1 + w1 + 2, y1, w2, h1, null);
rs.close();
file1.close();
stat4.close();
cont4.close();
} catch (Exception e) {
e.printStackTrace();
}
} else {
int j = 0, y2 = y1;
float j1 = 0f;
s2 = variabl2197[variabl2593][f0[i]];
s3 = "";
if ((s2.lastIndexOf("" + p1) < s2.length())
&& (s2.lastIndexOf("" + p1) > 0))
s2 = s2 + p1;
for (int k = 0; k < s2.length(); k++) {
if ((j1 < w2)
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p1))
&& (!s2.substring(k, k + 1).equalsIgnoreCase(
"" + p2))) {
s3 = s3 + s2.substring(k, k + 1);
if (s2.substring(k, k + 1).compareTo("z") < 0) {
if (s2.substring(k, k + 1).compareTo("0") < 0)
j1 = j1 + h20[i] * 0.37f;
else
j1 = j1 + h20[i] * 0.57f;
} else
j1 = j1 + h20[i];
} else {
j = j + h20[i];
if (j1 >= w2 - 2) {
layout = new TextLayout(s3, font, frc)
.getJustifiedLayout(w2 - 2);
;
layout.draw(g3, x1 + w1 + 2, y2 + h20[i]);
} else
g3.drawString(s3, x1 + w1 + 2, y2 + h20[i]);
y2 = y2 + h20[i];
s3 = "";
j1 = 0;
}
if (j >= h1)
break;
}
}
} else
g3.drawString(variabl2197[variabl2593][f0[i]], x1 + w1 + 2, y1 + h20[i]);
g3.drawLine(x1, y1 + h1, x1 + w1 + w2, y1 + h1);
if (y1 + h1 > variabl2631)
variabl2631 = y1 + h1;
}
g3.drawLine(variabl2623, t10[0] + variabl2657, variabl2623, variabl2631);
y1 = variabl2631 + 10;
struct3[] variabl2665 = new struct3[table1.size()];
for (int i = 0; i < table1.size(); i++) {
variabl2665[i] = table1.get(i);
g3.setFont(new Font(variabl2665[i].table1[8], Font.PLAIN, Integer
.valueOf(variabl2665[i].table1[9])));
x1 = Integer.valueOf(variabl2665[i].table1[6]);
y1 = y1 + Integer.valueOf(variabl2665[i].table1[5]);
g3.drawString(variabl2665[i].table1[0], x1, y1);
}
}
public static void means(String[] parameter) {
sw = new String[11];
sw[1] = main1.sw1 + "";
sw[2] = main1.sw2;
sw[3] = main1.sw3;
sw[4] = main1.sw4;
sw[5] = main1.sw5;
sw[6] = main1.sw6;
sw[7] = main1.sw7;
sw[8] = main1.sw8;
sw[9] = main1.sw9;
sw[10] = main1.sw10;
main1.sw1 = 0;
main1.sw2 = "";
main1.sw3 = "";
main1.sw4 = "";
main1.sw5 = "";
main1.sw6 = "";
main1.sw7 = "";
main1.sw8 = "";
main1.sw9 = "";
main1.sw10 = "";
frame = new dataPrint2();
variabl2603 = "";
scrollPane = new JScrollPane();
s1 = "";
s2 = "";
s3 = "";
variabl2593 = -1;
title = new ArrayList<struct1>();
tableTitle = new ArrayList<struct2>();
table1 = new ArrayList<struct3>();
variabl2483 = 1000;
variabl2503 = 600;
variabl2681 = 600;
x1 = 0;
y1 = 0;
w1 = 0;
w2 = 0;
h1 = 0;
variabl2661 = 0;
variabl2657 = 0;
variabl2631 = 0;
variabl2623 = 0;
String[] variabl240501 = { "打印", "打印下一条", "退出" };
variabl2405 = new String[variabl240501.length];
variabl2851 = 0;
for (int i0 = 0; i0 < variabl240501.length; i0++)
variabl2405[i0] = variabl240501[i0];
if (parameter[11].length() > 0) {
variabl1187 = parameter[11];
variabl1187 = variabl1187.replaceAll(";", ";");
variabl1187 = variabl1187.replaceAll("。", ";");
variabl1187 = variabl1187.replaceAll(":", ";");
variabl1187 = variabl1187.replaceAll(":", ";");
if (variabl1187.indexOf(";") > 0) {
String s601[] = variabl1187.split(",");
variabl1187 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (s601[i01].indexOf(";") > 0) {
String s602[] = s601[i01].split(";");
variabl2405[Integer.parseInt((s602[0]))] = s602[1];
variabl1187 = variabl1187 + "," + s602[0];
variabl2851++;
} else {
variabl1187 = variabl1187 + "," + s601[i01];
variabl2851++;
}
}
}
else {
String s601[] = variabl1187.split(",");
variabl1187 = "";
for (int i01 = 0; i01 < s601.length; i01++) {
if (i01 == 0)
variabl1187 = s601[i01];
else
variabl1187 = variabl1187 + s601[i01];
variabl2851++;
}
}
} else {
variabl1187 = "";
for (int i1 = 0; i1 < variabl2405.length; i1++) {
if (i1 == 0)
variabl1187 = variabl1187 + i1;
else
variabl1187 = variabl1187 + "," + i1;
variabl2851++;
}
}
variabl1187 = "," + variabl1187 + ",";
variabl2483 = main1.variabl2483;
variabl2503 = main1.variabl2503;
int m1, m2;
try {
if (parameter[17].length() == 0) {
m1 = 0;
m2 = 0;
} else {
m1 = Integer.parseInt(parameter[17]);
m2 = Integer.parseInt(parameter[18]);
}
if (m1 > 0) {
if (m2 < 80) {
m1 = m1 * 10;
m2 = m2 * 10;
}
variabl2483 = m1;
variabl2503 = m2;
}
} catch (Exception e2) {
}
variabl2603 = parameter[4];
variabl1079 = parameter[15];
variabl2049 = parameter[20];
File file1 = new File(variabl1079);
try {
if (file1.exists()) {
FileReader fr = new FileReader(file1);
BufferedReader br = new BufferedReader(fr);
String tempStr = null;
for (int i = 0; (tempStr = br.readLine()) != null; i++) {
if (tempStr.substring(0, 2).equals("1,")) {
title.add(new struct1(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("2,")) {
tableTitle.add(new struct2(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("3,")) {
table1.add(new struct3(tempStr.substring(2,
tempStr.length()).split("。")));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
variabl1633 = "";
for (int i = 0; i < tableTitle.size(); i++) {
if (variabl1633.length() == 0)
variabl1633 = tableTitle.get(i).tableTitle[1];
else
variabl1633 = variabl1633 + "," + tableTitle.get(i).tableTitle[1];
}
数据表查询结构(variabl2603);
数据表查询数据(variabl2603);
frame.show();
frame.setLayout(null);
frame.setTitle("单记录式报表程序 作者:程学先");
frame.setBounds(10, 10, variabl2483 - 10, 1000);
frame.getContentPane().setLayout(null);
final JPanel panel = new JPanel();
panel.setBounds(10, 10, variabl2483 - 50, 1000);
panel.setLayout(null);
frame.getContentPane().add(panel);
tableModel = new DefaultTableModel(variabl2197, variabl2517);
table = new JTable(tableModel);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane.getViewport().add(table, null);
scrollPane.setBounds(30, 50, variabl2483 - 100, variabl2503 - 150);
panel.add(scrollPane);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
variabl2593 = table.getSelectedRow();
}
});
variabl2339 = (variabl2483 - 100) / variabl2851;
int variabl2337 = 30;
final JButton previewButton1 = new JButton(variabl2405[0]);
previewButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (variabl2593 < 0) {
JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");
return;
} else {
final PrinterJob job = PrinterJob.getPrinterJob();
if (!job.printDialog())
return;
job.setPrintable(new Printable() {
public int print(Graphics graphics,
PageFormat pageFormat, int pageIndex)
throws PrinterException {
dataPrint2.g = graphics;
if (pageIndex < 1) {
g3 = (Graphics2D) g;
g3.setStroke(new BasicStroke(1f));
print1();
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
});
try {
job.print();
} catch (Exception e1) {
e1.printStackTrace();
}
previewButton2.setEnabled(true);
}
}
});
previewButton1.setBounds(variabl2337, 20, variabl2339, 20);
if (variabl1187.indexOf(",0,") >= 0) {
variabl2337 = variabl2337 + variabl2339;
panel.add(previewButton1);
}
previewButton2 = new JButton(variabl2405[1]);
previewButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (variabl1853 > variabl2593) {
final PrinterJob job = PrinterJob.getPrinterJob();
if (!job.printDialog())
return;
job.setPrintable(new Printable() {
public int print(Graphics graphics,
PageFormat pageFormat, int pageIndex)
throws PrinterException {
dataPrint2.g = graphics;
if (pageIndex < 1) {
g3 = (Graphics2D) g;
g3.setStroke(new BasicStroke(1f));
print1();
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
});
try {
job.print();
} catch (Exception e1) {
e1.printStackTrace();
}
previewButton2.setEnabled(true);
}
}
});
previewButton2.setBounds(variabl2337, 20, variabl2339, 20);
if (variabl1187.indexOf(",1,") >= 0) {
variabl2337 = variabl2337 + variabl2339;
panel.add(previewButton2);
}
previewButton2.setEnabled(false);
final JButton exitButton = new JButton(variabl240501[2]);
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ((sw[2].length() > 0) && (sw[3].length() > 0)
&& (sw[4].length() > 0))
WorkflowDrivek1.means(sw);
panel.setVisible(false);
frame.setVisible(false);
frame.dispose();
}
});
exitButton.setBounds(variabl2337, 20, variabl2339, 20);
if (variabl1187.indexOf(",2,") >= 0) {
variabl2337 = variabl2337 + variabl2339;
panel.add(exitButton);
}
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
static void 数据表查询结构(String variabl2217) {
String[] s10 = null;
String[] sk = new String[300];
int n1 = 0, n2 = 0;
variabl2049 = "";
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);
rsmd4 = rs.getMetaData();
variabl2651 = rsmd4.getColumnCount();
variabl2517 = new String[variabl2651];
variabl1501 = new String[variabl2651];
variabl1489 = new int[variabl2651];
for (int i = 0; i < variabl2651; i++) {
variabl2517[i] = rsmd4.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);
rsmd4 = rs.getMetaData();
variabl2651 = rsmd4.getColumnCount();
for (int j = 0; j < variabl2651; j++) {
s2 = rsmd4.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;
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select " + variabl1633 + " from " + variabl2217 + variabl2049;
rs = stat4.executeQuery(s1);
rsmd4 = rs.getMetaData();
variabl2651 = rsmd4.getColumnCount();
variabl2517 = new String[variabl2651];
variabl1501 = new String[variabl2651];
variabl1489 = new int[variabl2651];
for (int i1 = 0; i1 < variabl2651; i1++) {
variabl2517[i1] = rsmd4.getColumnName(i1 + 1);
variabl1501[i1] = rsmd4.getColumnTypeName(i1 + 1);
variabl1489[i1] = rsmd4.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, "读取数据库数据出错!");
}
}
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 19:26
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社