|||
版本1
84.源码84,部件程序,表格式报表格式文件设计程序,生成打印数据库中单或多数据表的表格式报表格式文件。
/*
* 程序文件名:printFormat1.java
* 作者:程学先
* 功能:表格式报表格式文件设计程序,生成打印数据库中单或多数据表的表格式报表格式文件。
* 要求输入的参数:表名,可以为一个表的表名,也可以是多表,表名间用逗号分隔。
* 操作者对所有参数以字符个数为单位输入位置、大小数据,包括宽度、高度、左边距、到顶距等。
* 点击“辅助计算”后可自动根据字号变换为象素单位。
* 所有数据保存在一个文件中,数据共分为5组进行设置,程序共分为5页分别组织设计。
* 第一组标题页(全表打印一次),可以输入标题内容及副标题、作者……等
* 输入时先输入内容,输入以字符个数为单位的宽度、高度、左边距、到顶距、字体、字号等
* 每输入一行内容点击添加到表格中按钮。
* 全部输入完成后,点击“辅助计算”按钮。标题分常量与变量二类,常量照原样打印,变量选字段名。
* 第2组为表头部分,每页打印一次内容相同,可以为字段名,也可以变换为其他标签文字。(每页打印一次)
* 输入时可先选字段名,修改内容后,点击“添加到表格中”按钮,再输入下一个标签。
* 第3组为表格表体内容,选字段名,点击“添加到表格中”按钮,再输入下一个字段名。
* 表格内容来自对数据表的查询程序,每行对应一条记录部分字段的数据,
* 第4组为页尾内容分常量与变量二类,常量照原样打印,变量的打印内容在调用程序中设置。(每页打印一次)
* 目前程序中设置页高600个象素点,可以根据实际情况修改,每到页高值将换页并重打印表头。
* 第5组为表尾内容(全表打印一次)分常量与变量二类,常量照原样打印,变量的打印内容在调用程序中设置。
* 总标题、页尾、表尾部分属性包括:内容、变量名、行号、列号、宽度、高度、左边距、到顶距、
* 字体、字号等10个参数
* 表头部分属性包括:字段标签名称、行号、列号、宽度、高度、左边距、字体、字号、
* 有无下表格线、有无右表格线等10个参数
* 表体部分属性包括:字段名称、宽度、字体、字号、有无下表格线、有无右表格线等6个参数
* 辅助计算前,请一定检查上述内容(特别是字号)都已经输入后再点击“辅助计算”。
* 所生成格式文件分组存放数据,第一个数据标志组类型,1表示总标题(全表一次);
* 2表示表头(每页一次);3表示表格内容(根据记录情况重复)。
* 4表示页尾内容(每页一次)
* 5表示表尾内容(全表一次)
*/
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 printFormat1 extends JFrame {
private static printFormat1 frame1 = new printFormat1(); // 定义窗口
private static printFormat1 frame2 = new printFormat1();
private static printFormat1 frame3 = new printFormat1();
private static printFormat1 frame4 = new printFormat1();
private static printFormat1 frame5 = new printFormat1();
private static JPanel panel1 = new JPanel(); // 定义面板
private static JPanel panel2 = new JPanel();
private static JPanel panel3 = new JPanel();
private static JPanel panel4 = new JPanel();
private static JPanel panel5 = new JPanel();
private static DefaultTableModel 表格模型1; // 定义表格模型对象
private static DefaultTableModel 表格模型2;
private static DefaultTableModel 表格模型3;
private static DefaultTableModel 表格模型4;
private static DefaultTableModel 表格模型5;
private static JTable 表格1; // 定义表格对象
private static JTable 表格2;
private static JTable 表格3;
private static JTable 表格4;
private static JTable 表格5;
private static JScrollPane scrollPane1 = new JScrollPane(); // 定义表格滚动条
private static JScrollPane scrollPane2 = new JScrollPane();
private static JScrollPane scrollPane3 = new JScrollPane();
private static JScrollPane scrollPane4 = new JScrollPane();
private static JScrollPane scrollPane5 = new JScrollPane();
private static List list1 = new List();
private static List list2 = new List();
private static List list3 = new List();
private static List list4 = new List();
private static List list5 = 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, fa9,
fa10, fa11, fa12;
private static JLabel fla1, fla2, fla3, fla4, fla5, fla6, fla7, fla8,
fla11, fla12;
private static JTextField faa1, faa2, faa3, faa4, faa5, faa6, faa7,
faa8, faa11, faa12;
private static JLabel flb1, flb2, flb3, flb4, flb5, flb6, flb7;
private static JTextField fab1, fab2, fab3, fab4, fab5, fab6, fab7;
private static JLabel flc1, flc2, flc3, flc4, flc5, flc6, flc7, flc8,flc11,flc12;
private static JTextField fac1, fac2, fac3, fac4, fac5, fac6, fac7,
fac8, fac9, fac11, fac12;
private static JLabel fld1, fld2, fld3, fld4, fld5, fld6, fld7, fld8,fld11, fld12;
private static JTextField fad1, fad2, fad3, fad4, fad5, fad6, fad7,
fad8, fad9,fad11, fad12;
private static String 当前值;
private static int 当前列号 = 0, 列数 = 0;
private static int 字段序号 = 0;
private static String [] 表名1=null;
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) {
String 表名 = parameter[4]; // 数据表名
frame1 = new printFormat1(); // 定义窗口
frame2 = new printFormat1();
frame3 = new printFormat1();
frame4 = new printFormat1();
frame5 = new printFormat1();
panel1 = new JPanel(); // 定义面板
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
panel5 = new JPanel();
scrollPane1 = new JScrollPane(); // 定义表格滚动条
scrollPane2 = new JScrollPane();
scrollPane3 = new JScrollPane();
scrollPane4 = new JScrollPane();
scrollPane5 = new JScrollPane();
list1 = new List();
list2 = new List();
list3 = new List();
list4 = new List();
list5 = 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("报表表体内容设计页,每条记录打印一次。");
frame4.setTitle("打印报表页尾设计页,每页打印一次。");
frame5.setTitle("打印报表表尾设计页,每表打印一次。");
frame1.setBounds(10, 10, 1000, 660); // 窗口位置大小
frame2.setBounds(100, 10, 1000, 660);
frame3.setBounds(200, 10, 1000, 660);
frame4.setBounds(10, 120, 1000, 600);
frame5.setBounds(200, 120, 1000, 600);
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 设置窗体的默认关闭模式
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame4.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame5.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
panel1.setBounds(10, 10, 1000, 660); // 定义面板大小与位置
panel2.setBounds(100, 10, 1000, 660);
panel3.setBounds(200, 10, 1000, 660);
panel4.setBounds(10, 120, 1000, 600);
panel5.setBounds(200, 120, 1000, 600);
panel1.setLayout(null); // 关闭面板布局管理器
panel2.setLayout(null);
panel3.setLayout(null);
panel4.setLayout(null);
panel5.setLayout(null);
String[] 列名01 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度", "左边距", "到顶距",
"字体", "字号" };
String[] 列名02 = { "字段标签", "行号", "列号", "宽度", "高度", "左边距", "字体", "字号",
"有无下表格线", "有无右表格线" };
String[] 列名03 = { "字段名称", "字段宽度", "每行高度", "字体", "字号", "有无下表格线",
"有无右表格线" };
String[] 列名04 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度", "左边距", "到顶距",
"字体", "字号" };
String[] 列名05 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度", "左边距", "到顶距",
"字体", "字号" };
main1.driver1();
String 表名表 = parameter[0];
表名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]);
}
});
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("。"));
} else if (tempStr.substring(0, 2).equals(
"4,")) {
表格模型4.addRow(tempStr.substring(2,
tempStr.length()).split("。"));
} else if (tempStr.substring(0, 2).equals(
"5,")) {
表格模型5.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);
表格模型4 = new DefaultTableModel(表格数据, 列名04);
表格模型5 = new DefaultTableModel(表格数据, 列名05);
表格1 = new JTable(表格模型1); // 创建指定表格模型的表格
表格2 = new JTable(表格模型2);
表格3 = new JTable(表格模型3);
表格4 = new JTable(表格模型4);
表格5 = new JTable(表格模型5);
表格1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);// 设置表格的选择模式为单选
表格2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
表格3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
表格4.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
表格5.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;
case 10:
fa9.setText(当前值.toString());
break;
}
}
}
});
scrollPane1.setBounds(10, 40, 800, 400);
scrollPane2.setBounds(10, 40, 800, 400);
scrollPane3.setBounds(10, 40, 800, 400);
scrollPane4.setBounds(10, 40, 800, 300);
scrollPane5.setBounds(10, 40, 800, 300);
scrollPane1.setViewportView(表格1); // 表格滚动条加到表格中
scrollPane2.setViewportView(表格2);
scrollPane3.setViewportView(表格3);
scrollPane4.setViewportView(表格4);
scrollPane5.setViewportView(表格5);
panel1.add(scrollPane1, BorderLayout.CENTER);// 面板中加入表格滚动条
panel2.add(scrollPane2, BorderLayout.CENTER);
panel3.add(scrollPane3, BorderLayout.CENTER);
panel4.add(scrollPane4, BorderLayout.CENTER);
panel5.add(scrollPane5, 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();
}
});
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();
}
});
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.3);
数据[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 < 10; 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 < 7; 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());
}
for (int i = 0; i < 表格模型4.getRowCount(); i++) {
String s3 = "4,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((表格模型4.getValueAt(i, j) != null)
&& (表格模型4.getValueAt(i, j).toString().length() > 0))
s3 = s3 + 表格模型4.getValueAt(i, j).toString()+ "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
for (int i = 0; i < 表格模型5.getRowCount(); i++) {
String s3 = "5,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((表格模型5.getValueAt(i, j) != null)
&& (表格模型5.getValueAt(i, j).toString().length() > 0))
s3 = s3 + 表格模型5.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();
frame4.setVisible(false);
frame4.dispose();
frame5.setVisible(false);
frame5.dispose();
}
});
panel1.add(exitButton);
fla1 = new JLabel("标签名称");
fla1.setBounds(50, 460, 60, 20);
panel2.add(fla1);
faa1 = new JTextField("", 20);
faa1.setBounds(110, 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]);
}
}
});
fla11 = new JLabel("行号");
fla11.setBounds(240, 460, 40, 20);
panel2.add(fla11);
faa11 = new JTextField("", 20);
faa11.setBounds(280, 460, 60, 20);
panel2.add(faa11);
faa11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 11;
list2.removeAll();
}
});
fla12 = new JLabel("列号");
fla12.setBounds(370, 460, 40, 20);
panel2.add(fla12);
faa12 = new JTextField("", 20);
faa12.setBounds(410, 460, 60, 20);
panel2.add(faa12);
faa12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 12;
list2.removeAll();
}
});
fla2 = new JLabel("宽度");
fla2.setBounds(500, 460, 40, 20);
panel2.add(fla2);
faa2 = new JTextField("", 20);
faa2.setBounds(540, 460, 60, 20);
panel2.add(faa2);
faa2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 2;
list2.removeAll();
}
});
fla3 = new JLabel("高度");
fla3.setBounds(630, 460, 40, 20);
panel2.add(fla3);
faa3 = new JTextField("", 20);
faa3.setBounds(670, 460, 60, 20);
panel2.add(faa3);
faa3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 3;
list2.removeAll();
}
});
fla4 = new JLabel("左边距");
fla4.setBounds(750, 460, 50, 20);
panel2.add(fla4);
faa4 = new JTextField("", 20);
faa4.setBounds(800, 460, 60, 20);
panel2.add(faa4);
faa4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 4;
list2.removeAll();
}
});
fla5 = new JLabel("字体");
fla5.setBounds(70, 500, 40, 20);
panel2.add(fla5);
faa5 = new JTextField("", 20);
faa5.setBounds(110, 500, 100, 20);
panel2.add(faa5);
faa5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 5;
list2.removeAll();
for (int i = 0; i < 字体.length; i++) {
list2.add(字体[i]);
}
}
});
fla6 = new JLabel("字号");
panel2.add(fla6);
faa6 = new JTextField("", 20);
panel2.add(faa6);
fla6.setBounds(240, 500, 40, 20);
faa6.setBounds(280, 500, 60, 20);
faa6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 6;
list2.removeAll();
for (int i = 0; i < 字号.length; i++) {
list2.add(字号[i]);
}
}
});
fla7 = new JLabel("有无下表格线");
panel2.add(fla7);
faa7 = new JTextField("", 20);
panel2.add(faa7);
fla7.setBounds(350, 500, 80, 20);
faa7.setBounds(430, 500, 120, 20);
faa7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 7;
list2.removeAll();
list2.add("有");
list2.add("无");
}
});
fla8 = new JLabel("有无右表格线");
panel2.add(fla8);
faa8 = new JTextField("", 20);
panel2.add(faa8);
fla8.setBounds(560, 500, 80, 20);
faa8.setBounds(640, 500, 100, 20);
faa8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 8;
list2.removeAll();
list2.add("有");
list2.add("无");
}
});
faa1.setText("");
faa2.setText("0");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("");
faa8.setText("0");
faa11.setText("1");
faa12.setText("1");
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());
字段序号 = list2.getSelectedIndex();
if (((main1.文本数据类型+main1.图形数据类型).lastIndexOf("," + 列数据类型[字段序号])) < 0) {
if (列数据宽度[字段序号] > 列名1[字段序号].length())
faa2.setText("" + 列数据宽度[字段序号]);
else
faa2.setText("" + 列名1[字段序号].length());
faa3.setText("1");
}
faa5.setText("宋体");
faa6.setText("12");
faa7.setText("有");
faa8.setText("有");
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 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 1:
faa11.setText(当前值.toString());
break;
case 2:
faa12.setText(当前值.toString());
break;
case 3:
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;
}
}
}
});
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(), faa11.getText(),
faa12.getText(), faa2.getText(), faa3.getText(),
faa4.getText(), faa5.getText(), faa6.getText(),
faa7.getText(), faa8.getText() };
表格模型2.addRow(rowValues);
int rowCount = 表格2.getRowCount() + 1;
faa1.setText("");
faa2.setText("0");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("");
faa8.setText("0");
faa11.setText("1");
faa12.setText("1");
} 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(), 选中行号, 1);
表格模型2.setValueAt(faa12.getText(), 选中行号, 2);
表格模型2.setValueAt(faa2.getText(), 选中行号, 3);
表格模型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);
} 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) {
int 数据条数 = 表格模型2.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] = 表格模型2.getValueAt(i, j).toString().trim();
for (int j = 3; j < 8; j++) {
if (j != 6) {
if (数据[i][j].length() > 0)
数据1[i][j] = Integer.valueOf(数据[i][j]);
else
数据1[i][j] = 0;
}
}
for (int j = 3; j < 6; j++) {
if (j == 4)
数据1[i][j] = (int) (数据1[i][j] * 数据1[i][7] * 1.3);
else
数据1[i][j] = 数据1[i][j] * 数据1[i][7];
数据[i][j] = "" + 数据1[i][j];
}
}
表格模型2.setRowCount(0);
for (int i = 0; i < 数据条数; i++)
表格模型2.addRow(数据[i]);
}
});
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("0");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("");
faa8.setText("0");
faa11.setText("1");
faa12.setText("1");
}
});
panel2.add(clearButton1);
flb1 = new JLabel("字段名称");
flb1.setBounds(10, 460, 60, 20);
panel3.add(flb1);
fab1 = new JTextField("", 20);
fab1.setBounds(70, 460, 100, 20);
panel3.add(fab1);
fab1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 1;
list3.removeAll();
for (int i = 0; i < 列数; i++) {
list3.add(列名1[i]);
}
}
});
flb2 = new JLabel("宽度");
flb2.setBounds(170, 460, 40, 20);
panel3.add(flb2);
fab2 = new JTextField("", 20);
fab2.setBounds(210, 460, 60, 20);
panel3.add(fab2);
fab2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 2;
list3.removeAll();
}
});
flb3 = new JLabel("每行高度");
flb3.setBounds(270, 460, 60, 20);
panel3.add(flb3);
fab3 = new JTextField("", 20);
fab3.setBounds(330, 460, 60, 20);
panel3.add(fab3);
fab3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 3;
list3.removeAll();
}
});
flb4 = new JLabel("字体");
flb4.setBounds(390, 460, 40, 20);
panel3.add(flb4);
fab4 = new JTextField("", 20);
fab4.setBounds(430, 460, 100, 20);
panel3.add(fab4);
fab4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 4;
list3.removeAll();
for (int i = 0; i < 字体.length; i++) {
list3.add(字体[i]);
}
}
});
flb5 = new JLabel("字号");
panel3.add(flb5);
fab5 = new JTextField("", 20);
panel3.add(fab5);
flb5.setBounds(530, 460, 40, 20);
fab5.setBounds(570, 460, 60, 20);
fab5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 5;
list3.removeAll();
for (int i = 0; i < 字号.length; i++) {
list3.add(字号[i]);
}
}
});
flb6 = new JLabel("有无下表格线");
panel3.add(flb6);
fab6 = new JTextField("", 20);
panel3.add(fab6);
flb6.setBounds(630, 460, 80, 20);
fab6.setBounds(710, 460, 60, 20);
fab6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 6;
list3.removeAll();
list3.add("有");
list3.add("无");
}
});
flb7 = new JLabel("有无右表格线");
panel3.add(flb7);
fab7 = new JTextField("", 20);
panel3.add(fab7);
flb7.setBounds(770, 460, 80, 20);
fab7.setBounds(850, 460, 60, 20);
fab7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 7;
list3.removeAll();
list3.add("有");
list3.add("无");
}
});
list3.setBounds(840, 10, 120, 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());
字段序号 = list3.getSelectedIndex();
if (((main1.文本数据类型+main1.图形数据类型).lastIndexOf("," + 列数据类型[字段序号])) < 0) {
if (列数据宽度[字段序号] > 列名1[字段序号].length())
fab2.setText("" + 列数据宽度[字段序号]);
else
fab2.setText("" + 列名1[字段序号].length());
}
fab3.setText("1");
fab4.setText("宋体");
fab5.setText("12");
fab6.setText("有");
fab7.setText("有");
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;
}
}
}
});
表格3.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int 选中行号 = 表格3.getSelectedRow();
for (int j = 0; j < 7; 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:
fab3.setText(当前值.toString());
break;
case 3:
fab4.setText(当前值.toString());
break;
case 4:
fab5.setText(当前值.toString());
break;
case 5:
fab6.setText(当前值.toString());
break;
case 6:
fab7.setText(当前值.toString());
break;
}
}
}
});
final JButton addButton2 = new JButton("添加到表格中");
addButton2.setBounds(50, 540, 170, 20);
addButton2.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(),
fab3.getText(), fab4.getText(), fab5.getText(),
fab6.getText(), fab7.getText() };
表格模型3.addRow(rowValues);
int rowCount = 表格3.getRowCount() + 1;
fab1.setText("");
fab2.setText("0");
fab3.setText("1");
fab4.setText("宋体");
fab5.setText("0");
fab6.setText("有");
fab7.setText("有");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel3.add(addButton2);
final JButton updButton2 = new JButton("修改表格数据");
updButton2.setBounds(220, 540, 170, 20);
updButton2.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(fab3.getText(), 选中行号, 2);
表格模型3.setValueAt(fab4.getText(), 选中行号, 3);
表格模型3.setValueAt(fab5.getText(), 选中行号, 4);
表格模型3.setValueAt(fab6.getText(), 选中行号, 5);
表格模型3.setValueAt(fab7.getText(), 选中行号, 6);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel3.add(updButton2);
final JButton delButton2 = new JButton("从表格中删除");
delButton2.setBounds(390, 540, 170, 20);
delButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = 表格3.getSelectedRow();
if (选中行号 != -1)
表格模型3.removeRow(选中行号);
}
});
panel3.add(delButton2);
final JButton countButton2 = new JButton("辅助计算");
countButton2.setBounds(560, 540, 170, 20);
countButton2.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 < 7; j++) {
数据[i][j] = 表格模型3.getValueAt(i, j).toString().trim();
}
for (int j = 1; j < 5; j++) {
if (j != 3) {
if (数据[i][j].length() > 0)
数据1[i][j] = Integer.valueOf(数据[i][j]);
else
数据1[i][j] = 0;
}
}
数据1[i][1] = 数据1[i][1] * 数据1[i][4];
数据[i][1] = "" + 数据1[i][1];
数据1[i][2] = 数据1[i][2] * 数据1[i][4];
数据[i][2] = "" + 数据1[i][2];
}
表格模型3.setRowCount(0);
for (int i = 0; i < 数据条数; i++)
表格模型3.addRow(数据[i]);
}
});
panel3.add(countButton2);
final JButton clearButton2 = new JButton("清参数文本框");
clearButton2.setBounds(730, 540, 170, 20);
clearButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fab1.setText("");
fab2.setText("0");
fab3.setText("1");
fab4.setText("宋体");
fab5.setText("0");
fab6.setText("有");
fab7.setText("有");
}
});
panel3.add(clearButton2);
flc1 = new JLabel("内容");
flc1.setBounds(70, 360, 40, 20);
panel4.add(flc1);
fac1 = new JTextField("", 20);
fac1.setBounds(110, 360, 100, 20);
panel4.add(fac1);
fac1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 1;
list4.removeAll();
}
});
flc2 = new JLabel("变量名");
flc2.setBounds(230, 360, 50, 20);
panel4.add(flc2);
fac2 = new JTextField("", 20);
fac2.setBounds(280, 360, 60, 20);
panel4.add(fac2);
fac2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 2;
list4.removeAll();
}
});
flc11 = new JLabel("行号");
flc11.setBounds(370, 360, 40, 20);
panel4.add(flc11);
fac11 = new JTextField("", 20);
fac11.setBounds(410, 360, 60, 20);
panel4.add(fac11);
fac11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 11;
list4.removeAll();
}
});
flc12 = new JLabel("列号");
flc12.setBounds(500, 360, 40, 20);
panel4.add(flc12);
fac12 = new JTextField("", 20);
fac12.setBounds(540, 360, 60, 20);
panel4.add(fac12);
fac12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 12;
list4.removeAll();
}
});
flc3 = new JLabel("宽度");
flc3.setBounds(630, 360, 40, 20);
panel4.add(flc3);
fac3 = new JTextField("", 20);
fac3.setBounds(670, 360, 60, 20);
panel4.add(fac3);
fac3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 3;
list4.removeAll();
}
});
flc4 = new JLabel("高度");
flc4.setBounds(760, 360, 40, 20);
panel4.add(flc4);
fac4 = new JTextField("", 20);
fac4.setBounds(800, 360, 60, 20);
panel4.add(fac4);
fac4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 4;
list4.removeAll();
}
});
flc5 = new JLabel("左边距");
flc5.setBounds(60, 400, 50, 20);
panel4.add(flc5);
fac5 = new JTextField("", 20);
fac5.setBounds(110, 400, 100, 20);
panel4.add(fac5);
fac5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 5;
list4.removeAll();
}
});
flc6 = new JLabel("到顶距");
panel4.add(flc6);
fac6 = new JTextField("", 20);
panel4.add(fac6);
flc6.setBounds(220, 400, 60, 20);
fac6.setBounds(280, 400, 60, 20);
fac6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 6;
list4.removeAll();
}
});
flc7 = new JLabel("字体");
panel4.add(flc7);
fac7 = new JTextField("", 20);
panel4.add(fac7);
flc7.setBounds(370, 400, 40, 20);
fac7.setBounds(410, 400, 120, 20);
fac7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 7;
list4.removeAll();
for (int i = 0; i < 字体.length; i++) {
list4.add(字体[i]);
}
}
});
flc8 = new JLabel("字号");
panel4.add(flc8);
fac8 = new JTextField("", 20);
panel4.add(fac8);
flc8.setBounds(560, 400, 40, 20);
fac8.setBounds(600, 400, 100, 20);
fac8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 8;
list4.removeAll();
for (int i = 0; i < 字号.length; i++) {
list4.add(字号[i]);
}
}
});
list4.setBounds(840, 10, 120, 330);
panel4.add(list4);
list4.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list4.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (当前列号) {
case 1:
fac1.setText(list4.getSelectedItem());
break;
case 2:
fac2.setText(list4.getSelectedItem());
break;
case 3:
fac3.setText(list4.getSelectedItem());
break;
case 4:
fac4.setText(list4.getSelectedItem());
break;
case 5:
fac5.setText(list4.getSelectedItem());
break;
case 6:
fac6.setText(list4.getSelectedItem());
break;
case 7:
fac7.setText(list4.getSelectedItem());
break;
case 8:
fac8.setText(list4.getSelectedItem());
break;
case 11:
fac11.setText(list4.getSelectedItem());
break;
case 12:
fac12.setText(list4.getSelectedItem());
break;
}
}
}
});
表格4.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int 选中行号 = 表格4.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (表格模型4.getValueAt(选中行号, j) != null)
当前值 = 表格模型4.getValueAt(选中行号, j).toString();
else
当前值 = "";
switch (j) {
case 0:
fac1.setText(当前值.toString());
break;
case 1:
fac2.setText(当前值.toString());
break;
case 2:
fac11.setText(当前值.toString());
break;
case 3:
fac12.setText(当前值.toString());
break;
case 4:
fac3.setText(当前值.toString());
break;
case 5:
fac4.setText(当前值.toString());
break;
case 6:
fac5.setText(当前值.toString());
break;
case 7:
fac6.setText(当前值.toString());
break;
case 8:
fac7.setText(当前值.toString());
break;
case 9:
fac8.setText(当前值.toString());
break;
}
}
}
});
final JButton addButton4 = new JButton("添加到表格中");
addButton4.setBounds(50, 440, 170, 20);
addButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < 表格模型4.getRowCount(); i++) {
if ((表格模型4.getValueAt(i, 0) != null)
&& (表格模型4.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fac1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 < 0) {
String[] rowValues = { fac1.getText(), fac2.getText(),
fac11.getText(), fac12.getText(), fac3.getText(),
fac4.getText(), fac5.getText(), fac6.getText(),
fac7.getText(), fac8.getText() };
表格模型4.addRow(rowValues);
int rowCount = 表格4.getRowCount() + 1;
fac1.setText("");
fac2.setText("0");
fac3.setText("0");
fac4.setText("0");
fac5.setText("0");
fac6.setText("0");
fac7.setText("");
fac8.setText("0");
fac11.setText("0");
fac12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel4.add(addButton4);
final JButton updButton4 = new JButton("修改表格数据");
updButton4.setBounds(220, 440, 170, 20);
updButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1;
for (int i = 0; i < 表格模型4.getRowCount(); i++) {
if ((表格模型4.getValueAt(i, 0) != null)
&& (表格模型4.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fac1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 >= 0) {
表格模型4.setValueAt(fac1.getText(), 选中行号, 0);
表格模型4.setValueAt(fac2.getText(), 选中行号, 1);
表格模型4.setValueAt(fac11.getText(), 选中行号, 2);
表格模型4.setValueAt(fac12.getText(), 选中行号, 3);
表格模型4.setValueAt(fac3.getText(), 选中行号, 4);
表格模型4.setValueAt(fac4.getText(), 选中行号, 5);
表格模型4.setValueAt(fac5.getText(), 选中行号, 6);
表格模型4.setValueAt(fac6.getText(), 选中行号, 7);
表格模型4.setValueAt(fac7.getText(), 选中行号, 8);
表格模型4.setValueAt(fac8.getText(), 选中行号, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel4.add(updButton4);
final JButton delButton4 = new JButton("从表格中删除");
delButton4.setBounds(390, 440, 170, 20);
delButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = 表格4.getSelectedRow();
if (选中行号 != -1)
表格模型4.removeRow(选中行号);
}
});
panel4.add(delButton4);
final JButton countButton4 = new JButton("辅助计算");
countButton4.setBounds(560, 440, 170, 20);
countButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 数据条数 = 表格模型4.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] = 表格模型4.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.3); // 高度
数据[i][j] = "" + 数据1[i][j];
}
}
表格模型4.setRowCount(0);
for (int i = 0; i < 数据条数; i++)
表格模型4.addRow(数据[i]);
}
});
panel4.add(countButton4);
final JButton clearButton4 = new JButton("清参数文本框");
clearButton4.setBounds(730, 440, 170, 20);
clearButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fac1.setText("");
fac2.setText("0");
fac3.setText("0");
fac4.setText("0");
fac5.setText("0");
fac6.setText("0");
fac7.setText("");
fac8.setText("0");
fac11.setText("0");
fac12.setText("0");
}
});
panel4.add(clearButton4);
/* 表尾页 */
fld1 = new JLabel("内容");
fld1.setBounds(70, 360, 40, 20);
panel5.add(fld1);
fad1 = new JTextField("", 20);
fad1.setBounds(110, 360, 100, 20);
panel5.add(fad1);
fad1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 1;
list5.removeAll();
}
});
fld2 = new JLabel("变量名");
fld2.setBounds(230, 360, 50, 20);
panel5.add(fld2);
fad2 = new JTextField("", 20);
fad2.setBounds(280, 360, 60, 20);
panel5.add(fad2);
fad2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 2;
list5.removeAll();
}
});
fld11 = new JLabel("行号");
fld11.setBounds(370, 360, 40, 20);
panel5.add(fld11);
fad11 = new JTextField("", 20);
fad11.setBounds(410, 360, 60, 20);
panel5.add(fad11);
fad11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 11;
list5.removeAll();
}
});
fld12 = new JLabel("列号");
fld12.setBounds(500, 360, 40, 20);
panel5.add(fld12);
fad12 = new JTextField("", 20);
fad12.setBounds(540, 360, 60, 20);
panel5.add(fad12);
fad12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 12;
list5.removeAll();
}
});
fld3 = new JLabel("宽度");
fld3.setBounds(630, 360, 40, 20);
panel5.add(fld3);
fad3 = new JTextField("", 20);
fad3.setBounds(670, 360, 60, 20);
panel5.add(fad3);
fad3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 3;
list5.removeAll();
}
});
fld4 = new JLabel("高度");
fld4.setBounds(760, 360, 40, 20);
panel5.add(fld4);
fad4 = new JTextField("", 20);
fad4.setBounds(800, 360, 60, 20);
panel5.add(fad4);
fad4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 4;
list5.removeAll();
}
});
fld5 = new JLabel("左边距");
fld5.setBounds(60, 400, 50, 20);
panel5.add(fld5);
fad5 = new JTextField("", 20);
fad5.setBounds(110, 400, 100, 20);
panel5.add(fad5);
fad5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 5;
list5.removeAll();
}
});
fld6 = new JLabel("到顶距");
panel5.add(fld6);
fad6 = new JTextField("", 20);
panel5.add(fad6);
fld6.setBounds(220, 400, 60, 20);
fad6.setBounds(280, 400, 60, 20);
fad6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 6;
list5.removeAll();
}
});
fld7 = new JLabel("字体");
panel5.add(fld7);
fad7 = new JTextField("", 20);
panel5.add(fad7);
fld7.setBounds(370, 400, 40, 20);
fad7.setBounds(410, 400, 120, 20);
fad7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 7;
list5.removeAll();
for (int i = 0; i < 字体.length; i++) {
list5.add(字体[i]);
}
}
});
fld8 = new JLabel("字号");
panel5.add(fld8);
fad8 = new JTextField("", 20);
panel5.add(fad8);
fld8.setBounds(560, 400, 40, 20);
fad8.setBounds(600, 400, 100, 20);
fad8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
当前列号 = 8;
list5.removeAll();
for (int i = 0; i < 字号.length; i++) {
list5.add(字号[i]);
}
}
});
list5.setBounds(840, 10, 170, 330);
panel5.add(list5);
list5.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list5.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (当前列号) {
case 1:
fad1.setText(list5.getSelectedItem());
break;
case 2:
fad2.setText(list5.getSelectedItem());
break;
case 3:
fad3.setText(list5.getSelectedItem());
break;
case 4:
fad4.setText(list5.getSelectedItem());
break;
case 5:
fad5.setText(list5.getSelectedItem());
break;
case 6:
fad6.setText(list5.getSelectedItem());
break;
case 7:
fad7.setText(list5.getSelectedItem());
break;
case 8:
fad8.setText(list5.getSelectedItem());
break;
case 11:
fad11.setText(list5.getSelectedItem());
break;
case 12:
fad12.setText(list5.getSelectedItem());
break;
}
}
}
});
表格5.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int 选中行号 = 表格5.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (表格模型5.getValueAt(选中行号, j) != null)
当前值 = 表格模型5.getValueAt(选中行号, j).toString();
else
当前值 = "";
switch (j) {
case 0:
fad1.setText(当前值.toString());
break;
case 1:
fad2.setText(当前值.toString());
break;
case 2:
fad11.setText(当前值.toString());
break;
case 3:
fad12.setText(当前值.toString());
break;
case 4:
fad3.setText(当前值.toString());
break;
case 5:
fad4.setText(当前值.toString());
break;
case 6:
fad5.setText(当前值.toString());
break;
case 7:
fad6.setText(当前值.toString());
break;
case 8:
fad7.setText(当前值.toString());
break;
case 9:
fad8.setText(当前值.toString());
break;
}
}
}
});
final JButton addButton5 = new JButton("添加到表格中");
addButton5.setBounds(50, 440, 170, 20);
addButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < 表格模型5.getRowCount(); i++) {
if ((表格模型5.getValueAt(i, 0) != null)
&& (表格模型5.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fad1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 < 0) {
String[] rowValues = { fad1.getText(), fad2.getText(),
fad11.getText(), fad12.getText(), fad3.getText(),
fad4.getText(), fad5.getText(), fad6.getText(),
fad7.getText(), fad8.getText() };
表格模型5.addRow(rowValues);
int rowCount = 表格5.getRowCount() + 1;
fad1.setText("");
fad2.setText("0");
fad3.setText("0");
fad4.setText("0");
fad5.setText("0");
fad6.setText("0");
fad7.setText("");
fad8.setText("0");
fad11.setText("0");
fad12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel5.add(addButton5);
final JButton updButton5 = new JButton("修改表格数据");
updButton5.setBounds(220, 440, 170, 20);
updButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = -1;
for (int i = 0; i < 表格模型5.getRowCount(); i++) {
if ((表格模型5.getValueAt(i, 0) != null)
&& (表格模型5.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fad1.getText().trim()))) {
选中行号 = i;
break;
}
}
if (选中行号 >= 0) {
表格模型5.setValueAt(fad1.getText(), 选中行号, 0);
表格模型5.setValueAt(fad2.getText(), 选中行号, 1);
表格模型5.setValueAt(fad11.getText(), 选中行号, 2);
表格模型5.setValueAt(fad12.getText(), 选中行号, 3);
表格模型5.setValueAt(fad3.getText(), 选中行号, 4);
表格模型5.setValueAt(fad4.getText(), 选中行号, 5);
表格模型5.setValueAt(fad5.getText(), 选中行号, 6);
表格模型5.setValueAt(fad6.getText(), 选中行号, 7);
表格模型5.setValueAt(fad7.getText(), 选中行号, 8);
表格模型5.setValueAt(fad8.getText(), 选中行号, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel5.add(updButton5);
final JButton delButton5 = new JButton("从表格中删除");
delButton5.setBounds(390, 440, 170, 20);
delButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 选中行号 = 表格5.getSelectedRow();
if (选中行号 != -1)
表格模型5.removeRow(选中行号);
}
});
panel5.add(delButton5);
final JButton countButton5 = new JButton("辅助计算");
countButton5.setBounds(560, 440, 170, 20);
countButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int 数据条数 = 表格模型5.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] = 表格模型5.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];
}
}
表格模型5.setRowCount(0);
for (int i = 0; i < 数据条数; i++)
表格模型5.addRow(数据[i]);
}
});
panel5.add(countButton5);
final JButton clearButton5 = new JButton("清参数文本框");
clearButton5.setBounds(730, 440, 170, 20);
clearButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fad1.setText("");
fad2.setText("0");
fad3.setText("0");
fad4.setText("0");
fad5.setText("0");
fad6.setText("0");
fad7.setText("");
fad8.setText("0");
fad11.setText("0");
fad12.setText("0");
}
});
panel5.add(clearButton5);
frame5.add(panel5);
frame4.add(panel4);
frame3.add(panel3);
frame2.add(panel2);
frame1.add(panel1);
frame5.setVisible(true); // 安装窗口
frame4.setVisible(true);
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, "读取数据库数据出错!");
}
}
}
85.源码85,部件程序,表格式报表打印预览程序。用于单或多数据表的表格式报表打印预览,根据表格式报表格式文件设计程序打印预览。
/*
* 程序文件名:dataPreview.java
* 作者:程学先
* 功能:表格式报表打印预览程序。用于单或多数据表的表格式报表打印预览,根据表格式报表格式文件设计程序打印预览。
* 要求先利用程序printFormat1.java生成格式文件。
* 要求输入的参数:数据表名,打印格式文件名。
* 调用命令:dataPreview.means(parameter)
* 就可根据格式文件预览打印结构与内容。
*/
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
public class dataPreview extends JComponent{
private static JFrame frame1;
private static Connection cont4; // 连接数据库
private static Statement stat4; //连接数据库
private static ResultSetMetaData rsmdt4;
private static ResultSet rs; //数据库数据集
private static String 表名 ; // 数据表名
private static String 接口文件名;
private static String s1="",s2="";
private static int 记录条数 = 0,列数 = 0;
private static String [] 列名; // 定义列名数组
private static String [] 列数据类型; // 定义列字段类型数组
private static int [] 列数据宽度; // 定义列数据宽度
private 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>();
private static ArrayList<struct4> table2=new ArrayList<struct4>();
private static ArrayList<struct5> table3=new ArrayList<struct5>();
private static int 页高=600;
private static int x1=0,y1=0,w1=0,h1=0,左边=0,到顶=0;
private static Graphics2D g3;
private static Graphics g;
private static HashSet set01 = new HashSet();
private static String 连接条件="";
private static String 字段名表="";
private static String[][] 表格数据0=null;
static void title(){
struct2 [] 标签=new struct2[tableTitle.size()];
左边=Integer.valueOf(tableTitle.get(0).tableTitle[3]);
左边=左边/2;
for(int i=0;i<tableTitle.size();i++) {
标签[i]=tableTitle.get(i);
}
try {
g3.setFont(new Font(标签[0].tableTitle[6],Font.PLAIN,Integer.valueOf(标签[0].tableTitle[7])));// 设置字体
for(int i=0;i<tableTitle.size();i++){
x1=左边;
y1=到顶;
w1=Integer.valueOf(标签[i].tableTitle[3]);
h1=Integer.valueOf(标签[i].tableTitle[4]);
g3.drawLine(x1, y1, x1 + w1, y1);
g3.drawLine(x1, y1, x1, y1+h1);
g3.drawString(标签[i].tableTitle[0],左边+2, 到顶+h1);
if (标签[i].tableTitle[8].equals("有"))
g3.drawLine(x1, y1+h1, x1+ w1, y1+h1);
if (标签[i].tableTitle[9].equals("有"))
g3.drawLine(x1+ w1, y1, x1+ w1, y1+h1);
左边=左边+w1;
if ((i<tableTitle.size()-1)&&(Integer.valueOf(标签[i].tableTitle[1])<Integer.valueOf(标签[i+1].tableTitle[1])))
到顶=到顶+h1;
}
到顶=到顶+h1;
}catch(Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog( null, "打印失败,请检查有关位置数据是否短缺?");
}
}
protected void paintComponent(Graphics g1) {
g=g1;
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[4]);
y1=Integer.valueOf(标题[i].title[5]);
g3.drawString(标题[i].title[0], x1 , y1);
到顶=y1+Integer.valueOf(标题[i].title[5]);
}
title();
try {
struct3 [] 表体=new struct3[table1.size()];
int [] w10=new int[table1.size()];
int [] h10=new int[table1.size()];
int [] h20=new int[table1.size()];
for(int i=0;i<table1.size();i++){
表体[i]=table1.get(i);
w10[i]=Integer.valueOf(表体[i].table1[1]);
h10[i]=Integer.valueOf(表体[i].table1[2]);
h20[i]=Integer.valueOf(表体[i].table1[4]);
}
y1=到顶;
g3.setFont(new Font(表体[0].table1[3],Font.PLAIN,Integer.valueOf(表体[0].table1[4])));// 设置字体
for(int j=0;j<记录条数;j++){
x1=Integer.valueOf(tableTitle.get(0).tableTitle[3])/2;
g3.drawLine(x1, y1, x1, y1+h1);
for(int i=0;i<table1.size();i++){
if (表格数据[j][i]==null) 表格数据[j][i]=" ";
g3.drawString(表格数据[j][i],x1+2, y1+h20[i]);
if (表体[i].table1[5].equals("有"))
g3.drawLine(x1, y1+h10[i], x1+ w10[i], y1+h10[i]);
if (表体[i].table1[6].equals("有"))
g3.drawLine(x1+ w10[i], y1, x1+ w10[i], y1+h10[i]);
x1=x1+w10[i];
}
y1=y1+h10[table1.size()-1];
if ((y1>=页高)||(j==记录条数-1)){
struct4 [] 页尾=new struct4[table2.size()];
for(int i1=0;i1<table2.size();i1++){
页尾[i1]=table2.get(i1);
g3.setFont(new Font(页尾[i1].table2[8],Font.PLAIN,Integer.valueOf(页尾[i1].table2[9])));// 设置字体
x1=Integer.valueOf(页尾[i1].table2[6]);
y1=Integer.valueOf(页尾[i1].table2[7])+y1;
g3.drawString(页尾[i1].table2[0], x1 , y1);
到顶=y1+Integer.valueOf(页尾[i1].table2[5]);
}
y1=640;
break;
}
}
y1=y1+h10[table1.size()-1];
struct5 [] 表尾=new struct5[table3.size()];
for(int i=0;i<table3.size();i++){
表尾[i]=table3.get(i);
g3.setFont(new Font(表尾[i].table3[8],Font.PLAIN,Integer.valueOf(表尾[i].table3[9])));// 设置字体
x1=Integer.valueOf(表尾[i].table3[6]);
y1=y1+Integer.valueOf(表尾[i].table3[5])/2;
g3.drawString(表尾[i].table3[0], x1 , y1);
}
} catch (Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog(null, "打印失败,请检查有关位置数据是否短缺?");
}
}
static void means(String [] parameter){
s1="";s2="";
记录条数 = 0;列数 = 0;
title=new ArrayList<struct1>();
tableTitle=new ArrayList<struct2>();
table1=new ArrayList<struct3>();
table2=new ArrayList<struct4>();
table3=new ArrayList<struct5>();
页高=600;
x1=0;y1=0;w1=0;h1=0;左边=0;到顶=0;
表名=parameter[4];
接口文件名=parameter[15];
frame1 = new JFrame("报表预览程序 作者:程学先");
frame1.setBounds(10,10,1000, 1000);
frame1.add(new dataPreview());
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame1.setVisible(true);
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("。")));
}
else if (tempStr.substring(0,2).equals("4,")){
table2.add(new struct4(tempStr.substring(2,tempStr.length()).split("。")));
}
else if (tempStr.substring(0,2).equals("5,")){
table3.add(new struct5(tempStr.substring(2,tempStr.length()).split("。")));
}
}
}
}catch(IOException e2) {
JOptionPane.showMessageDialog( null, "打开文件错!");
}
字段名表="";
for (int i=0;i<table1.size();i++){
if (字段名表.length()==0) 字段名表=table1.get(i).table1[0];
else
字段名表=字段名表+","+table1.get(i).table1[0];
}
数据表查询结构(表名);
数据表查询数据(表名);
}
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);
rsmdt4 = rs.getMetaData();
列数 = rsmdt4.getColumnCount();
列名 = new String[列数];
列数据类型= new String[列数];
列数据宽度= new int[列数];
for (int i = 0; i < 列数; i++) {
列名[i] = rsmdt4.getColumnName(i + 1);
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
else { //多表
s10=数据表名.split(",");
String s0="",s1="",s2="";
int k=0;
for (int i=0;i<s10.length;i++){
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select * from " + s10[i];
rs = stat4.executeQuery(s1);
rsmdt4 = rs.getMetaData();
列数 = rsmdt4.getColumnCount();
for (int j = 0; j < 列数; j++) { //读取所有表的列名,同名的加表名
s2 = rsmdt4.getColumnName(j + 1).toLowerCase(); //列名
n2=n1;
if (i>0){ //加入第2个表之后字段出现同名字段
k=0;
for (int j1=0;j1<n2;j1++){
if (sk[j1].equals(s2)){
sk[j1]=s10[i-1]+"."+sk[j1];
if (连接条件.length()==0) //连接条件
连接条件=" where "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;
else 连接条件=连接条件+" and "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;
sk[n1]=s10[i]+"."+s2+" as "+(s2+i);
n1++;
k=1;
break;
}
}
if (k==0) {
sk[n1]=s2;
n1++;
}
}
else {
sk[n1]=s2;
n1++;
}
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
列名 = new String[n1];
列数据类型= new String[n1];
列数据宽度= new int[n1];
for (int i1=0;i1<n1;i1++)
列名[i1]=sk[i1];
}
}
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);
rsmdt4 = rs.getMetaData();
列数 = rsmdt4.getColumnCount();
for (int i1=0;i1<列数;i1++){
列数据类型[i1] = rsmdt4.getColumnTypeName(i1+1);
列数据宽度[i1] = rsmdt4.getColumnDisplaySize(i1+1);
}
rs.last();
记录条数=rs.getRow();
表格数据=new String[记录条数][列数];
表格数据0=new String[记录条数][列数];
while (c < 记录条数) {
rs.absolute(c + 1);
while (b < 列数) {
表格数据0[c][b] = rs.getString(b + 1);
if ((main1.数字数据类型.lastIndexOf("," + 列数据类型[b] + ",")) > 0)
if ((表格数据0[c][b] == null)
|| (表格数据0[c][b].trim().length() == 0))
表格数据0[c][b] = "0";
else if (表格数据0[c][b] == null)
表格数据0[c][b] = "";
表格数据[c][b] = 表格数据0[c][b];
b++;
}
c++;
b = 0;
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
}
86.源码86,部件程序,表格式报表打印程序。用于单或多数据表的表格式报表打印,根据表格式报表格式文件设计程序打印。
/*
* 程序文件名:dataPrint.java
* 作者:程学先
* 功能:表格式报表打印程序。用于单或多数据表的表格式报表打印,根据表格式报表格式文件设计程序打印。
* 要求先利用程序printFormat1.java生成格式文件。
* 要求输入的参数:数据表名,打印格式文件名。
* 调用命令:dataPrint.means(parameter)
*/
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class dataPrint extends JFrame {
private static JFrame frame1;
private static Connection cont4;
private static Statement stat4;
private static ResultSetMetaData rsmdt4;
private static ResultSet rs;
private static String 表名;
private static String 格式文件名;
private static String s1 = "", s2 = "";
private static int 记录条数 = 0, 列数 = 0;
private static String[] 列名;
private static String[] 列数据类型;
private static int[] 列数据宽度;
private 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>();
private static ArrayList<struct4> table2 = new ArrayList<struct4>();
private static ArrayList<struct5> table3 = new ArrayList<struct5>();
private static int 页高 = 600;
private static int x1 = 0, y1 = 0, w1 = 0, h1 = 0, 左边 = 0, 到顶 = 0;
private PageFormat pf;
private static Graphics2D g2;
private static String[][] 表格数据0;
private static String 连接条件 = "";
private static String 字段名表 = "";
private static HashSet set01 = new HashSet();
static void title() {
struct2[] 标签 = new struct2[tableTitle.size()];
左边 = Integer.valueOf(tableTitle.get(0).tableTitle[3]);
左边 = 左边 / 2;
for (int i = 0; i < tableTitle.size(); i++)
标签[i] = tableTitle.get(i);
try {
g2.setFont(new Font(标签[0].tableTitle[6], Font.PLAIN, Integer
.valueOf(标签[0].tableTitle[7])));// 设置字体
for (int i = 0; i < tableTitle.size(); i++) {
x1 = 左边;
y1 = 到顶;
w1 = Integer.valueOf(标签[i].tableTitle[3]);
h1 = Integer.valueOf(标签[i].tableTitle[4]);
g2.drawLine(x1, y1, x1 + w1, y1);
g2.drawLine(x1, y1, x1, y1 + h1);
g2.drawString(标签[i].tableTitle[0], 左边 + 2, 到顶 + h1);
if (标签[i].tableTitle[8].equals("有"))
g2.drawLine(x1, y1 + h1, x1 + w1, y1 + h1);
if (标签[i].tableTitle[9].equals("有"))
g2.drawLine(x1 + w1, y1, x1 + w1, y1 + h1);
左边 = 左边 + w1;
if ((i < tableTitle.size() - 1)
&& (Integer.valueOf(标签[i].tableTitle[1]) < Integer
.valueOf(标签[i + 1].tableTitle[1])))
到顶 = 到顶 + h1;
}
到顶 = 到顶 + h1;
} catch (Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog(null, "打印失败,请检查有关位置数据是否短缺?");
}
}
public static void means(String[] parameter) {
s1 = "";
s2 = "";
记录条数 = 0;
列数 = 0;
title = new ArrayList<struct1>();
tableTitle = new ArrayList<struct2>();
table1 = new ArrayList<struct3>();
table2 = new ArrayList<struct4>();
table3 = new ArrayList<struct5>();
页高 = 600;
x1 = 0;
y1 = 0;
w1 = 0;
h1 = 0;
左边 = 0;
到顶 = 0;
表名 = parameter[4];
格式文件名 = parameter[15];
dataPrint frame = new dataPrint();
frame.setTitle("单记录式报表打印程序 作者:程学先");
frame.pf = new PageFormat();
frame.pf.setOrientation(PageFormat.LANDSCAPE);
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("。")));
} else if (tempStr.substring(0, 2).equals("4,")) {
table2.add(new struct4(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("5,")) {
table3.add(new struct5(tempStr.substring(2,
tempStr.length()).split("。")));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
字段名表="";
for (int i=0;i<table1.size();i++){
if (字段名表.length()==0) 字段名表=table1.get(i).table1[0];
else
字段名表=字段名表+","+table1.get(i).table1[0];
}
数据表查询结构(表名);
数据表查询数据(表名);
final PrinterJob job = PrinterJob.getPrinterJob();
if (!job.printDialog())
return;
job.setPrintable(new Printable() {
public int print(Graphics graphics, PageFormat pageFormat,
int pageIndex) throws PrinterException {
if (pageIndex < 1) {
g2 = (Graphics2D) graphics;
g2.setStroke(new BasicStroke(1f));
try {
struct1[] 标题 = new struct1[title.size()];
到顶 = 0;
左边 = 0;
for (int i = 0; i < title.size(); i++) {
标题[i] = title.get(i);
g2.setFont(new Font(标题[i].title[8], Font.PLAIN,
Integer.valueOf(标题[i].title[9])));
x1 = Integer.valueOf(标题[i].title[4]);
y1 = Integer.valueOf(标题[i].title[5]);
g2.drawString(标题[i].title[0], x1, y1);
到顶 = y1 + Integer.valueOf(标题[i].title[5]);
}
title(); // 打印内容
struct3[] 表体 = new struct3[table1.size()];
int[] w10 = new int[table1.size()];
int[] h10 = new int[table1.size()];
int[] h20 = new int[table1.size()];
for (int i = 0; i < table1.size(); i++) {
表体[i] = table1.get(i);
w10[i] = Integer.valueOf(表体[i].table1[1]);
h10[i] = Integer.valueOf(表体[i].table1[2]);
h20[i] = Integer.valueOf(表体[i].table1[4]);
}
y1 = 到顶;
for (int j = 0; j < 记录条数; j++) {
x1 = Integer.valueOf(tableTitle.get(0).tableTitle[3]) / 2;
g2.drawLine(x1, y1, x1, y1 + h1);
for (int i = 0; i < table1.size(); i++) {
if (表格数据[j][i] == null)
表格数据[j][i] = " ";
g2.drawString(表格数据[j][i], x1 + 2, y1 + h20[i]);
if (表体[i].table1[5].equals("有"))
g2.drawLine(x1, y1 + h10[i], x1 + w10[i],
y1 + h10[i]);
if (表体[i].table1[6].equals("有"))
g2.drawLine(x1 + w10[i], y1, x1 + w10[i],
y1 + h10[i]);
x1 = x1 + w10[i];
}
y1 = y1 + h10[table1.size() - 1];
if (y1 >= 页高) {
struct4[] 页尾 = new struct4[table2.size()];
for (int i1 = 0; i1 < table2.size(); i1++) {
页尾[i1] = table2.get(i1);
g2.setFont(new Font(页尾[i1].table2[8],
Font.PLAIN, Integer
.valueOf(页尾[i1].table2[9])));
x1 = Integer.valueOf(页尾[i1].table2[6]);
y1 = Integer.valueOf(页尾[i1].table2[7]);
g2.drawString(页尾[i1].table2[0], x1, y1);
到顶 = y1 + Integer.valueOf(页尾[i1].table2[5]);
}
y1 = 640;
break;
}
}
y1 = y1 + h10[table1.size() - 1];
struct5[] 表尾 = new struct5[table3.size()];
for (int i = 0; i < table3.size(); i++) {
表尾[i] = table3.get(i);
g2.setFont(new Font(表尾[i].table3[8], Font.PLAIN,
Integer.valueOf(表尾[i].table3[9])));// 设置字体
x1 = Integer.valueOf(表尾[i].table3[6]);
y1 = y1 + Integer.valueOf(表尾[i].table3[5]) / 2;
g2.drawString(表尾[i].table3[0], x1, y1);
}
} catch (Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog(null,
"打印失败,请检查有关位置数据是否短缺?");
}
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
});
try {
job.print();
} catch (Exception e1) {
e1.printStackTrace();
}
frame.dispose(); // 结束
}
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);
rsmdt4 = rs.getMetaData();
列数 = rsmdt4.getColumnCount();
列名 = new String[列数];
列数据类型= new String[列数];
列数据宽度= new int[列数];
for (int i = 0; i < 列数; i++) {
列名[i] = rsmdt4.getColumnName(i + 1);
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
else { //多表
s10=数据表名.split(",");
String s0="",s1="",s2="";
int k=0;
for (int i=0;i<s10.length;i++){
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select * from " + s10[i];
rs = stat4.executeQuery(s1);
rsmdt4 = rs.getMetaData();
列数 = rsmdt4.getColumnCount();
for (int j = 0; j < 列数; j++) { //读取所有表的列名,同名的加表名
s2 = rsmdt4.getColumnName(j + 1).toLowerCase(); //列名
n2=n1;
if (i>0){ //加入第2个表之后字段出现同名字段
k=0;
for (int j1=0;j1<n2;j1++){
if (sk[j1].equals(s2)){
sk[j1]=s10[i-1]+"."+sk[j1];
if (连接条件.length()==0) //连接条件
连接条件=" where "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;
else 连接条件=连接条件+" and "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;
sk[n1]=s10[i]+"."+s2+" as "+(s2+i);
n1++;
k=1;
break;
}
}
if (k==0) {
sk[n1]=s2;
n1++;
}
}
else {
sk[n1]=s2;
n1++;
}
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
列名 = new String[n1];
列数据类型= new String[n1];
列数据宽度= new int[n1];
for (int i1=0;i1<n1;i1++)
列名[i1]=sk[i1];
}
}
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);
rsmdt4 = rs.getMetaData();
列数 = rsmdt4.getColumnCount();
for (int i1=0;i1<列数;i1++){
列数据类型[i1] = rsmdt4.getColumnTypeName(i1+1);
列数据宽度[i1] = rsmdt4.getColumnDisplaySize(i1+1);
}
rs.last();
记录条数=rs.getRow();
表格数据=new String[记录条数][列数];
表格数据0=new String[记录条数][列数];
while (c < 记录条数) {
rs.absolute(c + 1);
while (b < 列数) {
表格数据0[c][b] = rs.getString(b + 1);
if ((main1.数字数据类型.lastIndexOf("," + 列数据类型[b] + ",")) > 0)
if ((表格数据0[c][b] == null)
|| (表格数据0[c][b].trim().length() == 0))
表格数据0[c][b] = "0";
else if (表格数据0[c][b] == null)
表格数据0[c][b] = "";
表格数据[c][b] = 表格数据0[c][b];
b++;
}
c++;
b = 0;
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
}
版本2
84.源码84,部件程序,表格式报表格式文件设计程序,生成打印数据库中单或多数据表的表格式报表格式文件。
/*
* 程序文件名:printFormat1.java
* 作者:程学先
* 功能:生成打印数据库中单或多数据表的表格式报表格式文件。
* 要求输入的参数:表名,可以为一个表的表名,也可以是多表,表名间用逗号分隔。
* 操作者对所有参数以字符个数为单位输入位置、大小数据,包括宽度、高度、左边距、到顶距等。
* 点击“辅助计算”后可自动根据字号变换为象素单位。
* 所有数据保存在一个文件中,数据共分为5组进行设置,程序共分为5页分别组织设计。
* 第一组标题页(全表打印一次),可以输入标题内容及副标题、作者……等
* 输入时先输入内容,输入以字符个数为单位的宽度、高度、左边距、到顶距、字体、字号等
* 每输入一行内容点击添加到表格中按钮。
* 全部输入完成后,点击“辅助计算”按钮。标题分常量与变量二类,常量照原样打印,变量选字段名。
* 第2组为表头部分,每页打印一次内容相同,可以为字段名,也可以变换为其他标签文字。(每页打印一次)
* 输入时可先选字段名,修改内容后,点击“添加到表格中”按钮,再输入下一个标签。
* 第3组为表格表体内容,选字段名,点击“添加到表格中”按钮,再输入下一个字段名。
* 表格内容来自对数据表的查询程序,每行对应一条记录部分字段的数据,
* 第4组为页尾内容分常量与变量二类,常量照原样打印,变量的打印内容在调用程序中设置。(每页打印一次)
* 目前程序中设置页高600个象素点,可以根据实际情况修改,每到页高值将换页并重打印表头。
* 第5组为表尾内容(全表打印一次)分常量与变量二类,常量照原样打印,变量的打印内容在调用程序中设置。
* 总标题、页尾、表尾部分属性包括:内容、变量名、行号、列号、宽度、高度、左边距、到顶距、
* 字体、字号等10个参数
* 表头部分属性包括:字段标签名称、行号、列号、宽度、高度、左边距、字体、字号、
* 有无下表格线、有无右表格线等10个参数
* 表体部分属性包括:字段名称、宽度、字体、字号、有无下表格线、有无右表格线等6个参数
* 辅助计算前,请一定检查上述内容(特别是字号)都已经输入后再点击“辅助计算”。
* 所生成格式文件分组存放数据,第一个数据标志组类型,1表示总标题(全表一次);
* 2表示表头(每页一次);3表示表格内容(根据记录情况重复)。
* 4表示页尾内容(每页一次)
* 5表示表尾内容(全表一次)
*/
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 printFormat1 extends JFrame {
private static printFormat1 frame1 = new printFormat1();
private static printFormat1 frame2 = new printFormat1();
private static printFormat1 frame3 = new printFormat1();
private static printFormat1 frame4 = new printFormat1();
private static printFormat1 frame5 = new printFormat1();
private static JPanel panel1 = new JPanel();
private static JPanel panel2 = new JPanel();
private static JPanel panel3 = new JPanel();
private static JPanel panel4 = new JPanel();
private static JPanel panel5 = new JPanel();
private static DefaultTableModel variabl19651;
private static DefaultTableModel variabl19652;
private static DefaultTableModel variabl19653;
private static DefaultTableModel variabl19654;
private static DefaultTableModel variabl19655;
private static JTable variabl26551;
private static JTable variabl26552;
private static JTable variabl26553;
private static JTable variabl26554;
private static JTable variabl26555;
private static JScrollPane scrollPane1 = new JScrollPane();
private static JScrollPane scrollPane2 = new JScrollPane();
private static JScrollPane scrollPane3 = new JScrollPane();
private static JScrollPane scrollPane4 = new JScrollPane();
private static JScrollPane scrollPane5 = new JScrollPane();
private static List list1 = new List();
private static List list2 = new List();
private static List list3 = new List();
private static List list4 = new List();
private static List list5 = 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, fa9,
fa10, fa11, fa12;
private static JLabel fla1, fla2, fla3, fla4, fla5, fla6, fla7, fla8,
fla11, fla12;
private static JTextField faa1, faa2, faa3, faa4, faa5, faa6, faa7, faa8,
faa11, faa12;
private static JLabel flb1, flb2, flb3, flb4, flb5, flb6, flb7;
private static JTextField fab1, fab2, fab3, fab4, fab5, fab6, fab7;
private static JLabel flc1, flc2, flc3, flc4, flc5, flc6, flc7, flc8,
flc11, flc12;
private static JTextField fac1, fac2, fac3, fac4, fac5, fac6, fac7, fac8,
fac9, fac11, fac12;
private static JLabel fld1, fld2, fld3, fld4, fld5, fld6, fld7, fld8,
fld11, fld12;
private static JTextField fad1, fad2, fad3, fad4, fad5, fad6, fad7, fad8,
fad9, fad11, fad12;
private static String variabl2327;
private static int variabl1739 = 0, variabl2651 = 0;
private static int variabl2127 = 0;
private static String[] variabl26031 = null;
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) {
String variabl2603 = parameter[4];
frame1 = new printFormat1();
frame2 = new printFormat1();
frame3 = new printFormat1();
frame4 = new printFormat1();
frame5 = new printFormat1();
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
panel5 = new JPanel();
scrollPane1 = new JScrollPane();
scrollPane2 = new JScrollPane();
scrollPane3 = new JScrollPane();
scrollPane4 = new JScrollPane();
scrollPane5 = new JScrollPane();
list1 = new List();
list2 = new List();
list3 = new List();
list4 = new List();
list5 = 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("报表表体内容设计页,每条记录打印一次。");
frame4.setTitle("打印报表页尾设计页,每页打印一次。");
frame5.setTitle("打印报表表尾设计页,每表打印一次。");
frame1.setBounds(10, 10, 1000, 660);
frame2.setBounds(100, 10, 1000, 660);
frame3.setBounds(200, 10, 1000, 660);
frame4.setBounds(10, 120, 1000, 600);
frame5.setBounds(200, 120, 1000, 600);
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame4.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame5.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
panel1.setBounds(10, 10, 1000, 660);
panel2.setBounds(100, 10, 1000, 660);
panel3.setBounds(200, 10, 1000, 660);
panel4.setBounds(10, 120, 1000, 600);
panel5.setBounds(200, 120, 1000, 600);
panel1.setLayout(null);
panel2.setLayout(null);
panel3.setLayout(null);
panel4.setLayout(null);
panel5.setLayout(null);
String[] variabl251701 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度",
"左边距", "到顶距", "字体", "字号" };
String[] variabl251702 = { "字段标签", "行号", "列号", "宽度", "高度", "左边距", "字体",
"字号", "有无下表格线", "有无右表格线" };
String[] variabl251703 = { "字段名称", "字段宽度", "每行高度", "字体", "字号",
"有无下表格线", "有无右表格线" };
String[] variabl251704 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度",
"左边距", "到顶距", "字体", "字号" };
String[] variabl251705 = { "内容或变量", "变量名", "行号", "列号", "宽度", "高度",
"左边距", "到顶距", "字体", "字号" };
main1.driver1();
String variabl2429 = parameter[0];
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]);
}
});
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("。"));
} else if (tempStr.substring(0, 2).equals(
"4,")) {
variabl19654.addRow(tempStr.substring(
2, tempStr.length()).split("。"));
} else if (tempStr.substring(0, 2).equals(
"5,")) {
variabl19655.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);
variabl19654 = new DefaultTableModel(variabl2197, variabl251704);
variabl19655 = new DefaultTableModel(variabl2197, variabl251705);
variabl26551 = new JTable(variabl19651);
variabl26552 = new JTable(variabl19652);
variabl26553 = new JTable(variabl19653);
variabl26554 = new JTable(variabl19654);
variabl26555 = new JTable(variabl19655);
variabl26551.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
variabl26552.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
variabl26553.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
variabl26554.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
variabl26555.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;
case 10:
fa9.setText(variabl2327.toString());
break;
}
}
}
});
scrollPane1.setBounds(10, 40, 800, 400);
scrollPane2.setBounds(10, 40, 800, 400);
scrollPane3.setBounds(10, 40, 800, 400);
scrollPane4.setBounds(10, 40, 800, 300);
scrollPane5.setBounds(10, 40, 800, 300);
scrollPane1.setViewportView(variabl26551);
scrollPane2.setViewportView(variabl26552);
scrollPane3.setViewportView(variabl26553);
scrollPane4.setViewportView(variabl26554);
scrollPane5.setViewportView(variabl26555);
panel1.add(scrollPane1, BorderLayout.CENTER);
panel2.add(scrollPane2, BorderLayout.CENTER);
panel3.add(scrollPane3, BorderLayout.CENTER);
panel4.add(scrollPane4, BorderLayout.CENTER);
panel5.add(scrollPane5, 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();
}
});
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();
}
});
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.3);
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 < 10; 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 < 7; 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());
}
for (int i = 0; i < variabl19654.getRowCount(); i++) {
String s3 = "4,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((variabl19654.getValueAt(i, j) != null)
&& (variabl19654.getValueAt(i, j)
.toString().length() > 0))
s3 = s3
+ variabl19654.getValueAt(i, j)
.toString() + "。";
else
s3 = s3 + " 。";
}
fs.write((s3 + x1).getBytes());
}
for (int i = 0; i < variabl19655.getRowCount(); i++) {
String s3 = "5,", s4 = "";
for (int j = 0; j < 10; j++) {
if ((variabl19655.getValueAt(i, j) != null)
&& (variabl19655.getValueAt(i, j)
.toString().length() > 0))
s3 = s3
+ variabl19655.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();
frame4.setVisible(false);
frame4.dispose();
frame5.setVisible(false);
frame5.dispose();
}
});
panel1.add(exitButton);
fla1 = new JLabel("标签名称");
fla1.setBounds(50, 460, 60, 20);
panel2.add(fla1);
faa1 = new JTextField("", 20);
faa1.setBounds(110, 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]);
}
}
});
fla11 = new JLabel("行号");
fla11.setBounds(240, 460, 40, 20);
panel2.add(fla11);
faa11 = new JTextField("", 20);
faa11.setBounds(280, 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(370, 460, 40, 20);
panel2.add(fla12);
faa12 = new JTextField("", 20);
faa12.setBounds(410, 460, 60, 20);
panel2.add(faa12);
faa12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 12;
list2.removeAll();
}
});
fla2 = new JLabel("宽度");
fla2.setBounds(500, 460, 40, 20);
panel2.add(fla2);
faa2 = new JTextField("", 20);
faa2.setBounds(540, 460, 60, 20);
panel2.add(faa2);
faa2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 2;
list2.removeAll();
}
});
fla3 = new JLabel("高度");
fla3.setBounds(630, 460, 40, 20);
panel2.add(fla3);
faa3 = new JTextField("", 20);
faa3.setBounds(670, 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(750, 460, 50, 20);
panel2.add(fla4);
faa4 = new JTextField("", 20);
faa4.setBounds(800, 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(70, 500, 40, 20);
panel2.add(fla5);
faa5 = new JTextField("", 20);
faa5.setBounds(110, 500, 100, 20);
panel2.add(faa5);
faa5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 5;
list2.removeAll();
for (int i = 0; i < variabl2629.length; i++) {
list2.add(variabl2629[i]);
}
}
});
fla6 = new JLabel("字号");
panel2.add(fla6);
faa6 = new JTextField("", 20);
panel2.add(faa6);
fla6.setBounds(240, 500, 40, 20);
faa6.setBounds(280, 500, 60, 20);
faa6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 6;
list2.removeAll();
for (int i = 0; i < variabl2607.length; i++) {
list2.add(variabl2607[i]);
}
}
});
fla7 = new JLabel("有无下表格线");
panel2.add(fla7);
faa7 = new JTextField("", 20);
panel2.add(faa7);
fla7.setBounds(350, 500, 80, 20);
faa7.setBounds(430, 500, 120, 20);
faa7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 7;
list2.removeAll();
list2.add("有");
list2.add("无");
}
});
fla8 = new JLabel("有无右表格线");
panel2.add(fla8);
faa8 = new JTextField("", 20);
panel2.add(faa8);
fla8.setBounds(560, 500, 80, 20);
faa8.setBounds(640, 500, 100, 20);
faa8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 8;
list2.removeAll();
list2.add("有");
list2.add("无");
}
});
faa1.setText("");
faa2.setText("0");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("");
faa8.setText("0");
faa11.setText("1");
faa12.setText("1");
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());
variabl2127 = list2.getSelectedIndex();
if (((main1.variabl1537 + main1.variabl1539)
.lastIndexOf("," + variabl1501[variabl2127])) < 0) {
if (variabl1489[variabl2127] > variabl25171[variabl2127]
.length())
faa2.setText("" + variabl1489[variabl2127]);
else
faa2.setText(""
+ variabl25171[variabl2127].length());
faa3.setText("1");
}
faa5.setText("宋体");
faa6.setText("12");
faa7.setText("有");
faa8.setText("有");
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 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 1:
faa11.setText(variabl2327.toString());
break;
case 2:
faa12.setText(variabl2327.toString());
break;
case 3:
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;
}
}
}
});
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(), faa11.getText(),
faa12.getText(), faa2.getText(), faa3.getText(),
faa4.getText(), faa5.getText(), faa6.getText(),
faa7.getText(), faa8.getText() };
variabl19652.addRow(rowValues);
int rowCount = variabl26552.getRowCount() + 1;
faa1.setText("");
faa2.setText("0");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("");
faa8.setText("0");
faa11.setText("1");
faa12.setText("1");
} 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, 1);
variabl19652.setValueAt(faa12.getText(), variabl1823, 2);
variabl19652.setValueAt(faa2.getText(), variabl1823, 3);
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);
} 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) {
int variabl2059 = variabl19652.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] = variabl19652.getValueAt(i, j)
.toString().trim();
for (int j = 3; j < 8; j++) {
if (j != 6) {
if (variabl2649[i][j].length() > 0)
variabl26491[i][j] = Integer
.valueOf(variabl2649[i][j]);
else
variabl26491[i][j] = 0;
}
}
for (int j = 3; j < 6; j++) {
if (j == 4)
variabl26491[i][j] = (int) (variabl26491[i][j]
* variabl26491[i][7] * 1.3);
else
variabl26491[i][j] = variabl26491[i][j]
* variabl26491[i][7];
variabl2649[i][j] = "" + variabl26491[i][j];
}
}
variabl19652.setRowCount(0);
for (int i = 0; i < variabl2059; i++)
variabl19652.addRow(variabl2649[i]);
}
});
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("0");
faa3.setText("0");
faa4.setText("0");
faa5.setText("0");
faa6.setText("0");
faa7.setText("");
faa8.setText("0");
faa11.setText("1");
faa12.setText("1");
}
});
panel2.add(clearButton1);
flb1 = new JLabel("字段名称");
flb1.setBounds(10, 460, 60, 20);
panel3.add(flb1);
fab1 = new JTextField("", 20);
fab1.setBounds(70, 460, 100, 20);
panel3.add(fab1);
fab1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 1;
list3.removeAll();
for (int i = 0; i < variabl2651; i++) {
list3.add(variabl25171[i]);
}
}
});
flb2 = new JLabel("宽度");
flb2.setBounds(170, 460, 40, 20);
panel3.add(flb2);
fab2 = new JTextField("", 20);
fab2.setBounds(210, 460, 60, 20);
panel3.add(fab2);
fab2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 2;
list3.removeAll();
}
});
flb3 = new JLabel("每行高度");
flb3.setBounds(270, 460, 60, 20);
panel3.add(flb3);
fab3 = new JTextField("", 20);
fab3.setBounds(330, 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(390, 460, 40, 20);
panel3.add(flb4);
fab4 = new JTextField("", 20);
fab4.setBounds(430, 460, 100, 20);
panel3.add(fab4);
fab4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 4;
list3.removeAll();
for (int i = 0; i < variabl2629.length; i++) {
list3.add(variabl2629[i]);
}
}
});
flb5 = new JLabel("字号");
panel3.add(flb5);
fab5 = new JTextField("", 20);
panel3.add(fab5);
flb5.setBounds(530, 460, 40, 20);
fab5.setBounds(570, 460, 60, 20);
fab5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 5;
list3.removeAll();
for (int i = 0; i < variabl2607.length; i++) {
list3.add(variabl2607[i]);
}
}
});
flb6 = new JLabel("有无下表格线");
panel3.add(flb6);
fab6 = new JTextField("", 20);
panel3.add(fab6);
flb6.setBounds(630, 460, 80, 20);
fab6.setBounds(710, 460, 60, 20);
fab6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 6;
list3.removeAll();
list3.add("有");
list3.add("无");
}
});
flb7 = new JLabel("有无右表格线");
panel3.add(flb7);
fab7 = new JTextField("", 20);
panel3.add(fab7);
flb7.setBounds(770, 460, 80, 20);
fab7.setBounds(850, 460, 60, 20);
fab7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 7;
list3.removeAll();
list3.add("有");
list3.add("无");
}
});
list3.setBounds(840, 10, 120, 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());
variabl2127 = list3.getSelectedIndex();
if (((main1.variabl1537 + main1.variabl1539)
.lastIndexOf("," + variabl1501[variabl2127])) < 0) {
if (variabl1489[variabl2127] > variabl25171[variabl2127]
.length())
fab2.setText("" + variabl1489[variabl2127]);
else
fab2.setText(""
+ variabl25171[variabl2127].length());
}
fab3.setText("1");
fab4.setText("宋体");
fab5.setText("12");
fab6.setText("有");
fab7.setText("有");
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;
}
}
}
});
variabl26553.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int variabl1823 = variabl26553.getSelectedRow();
for (int j = 0; j < 7; 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:
fab3.setText(variabl2327.toString());
break;
case 3:
fab4.setText(variabl2327.toString());
break;
case 4:
fab5.setText(variabl2327.toString());
break;
case 5:
fab6.setText(variabl2327.toString());
break;
case 6:
fab7.setText(variabl2327.toString());
break;
}
}
}
});
final JButton addButton2 = new JButton("添加到表格中");
addButton2.setBounds(50, 540, 170, 20);
addButton2.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(),
fab3.getText(), fab4.getText(), fab5.getText(),
fab6.getText(), fab7.getText() };
variabl19653.addRow(rowValues);
int rowCount = variabl26553.getRowCount() + 1;
fab1.setText("");
fab2.setText("0");
fab3.setText("1");
fab4.setText("宋体");
fab5.setText("0");
fab6.setText("有");
fab7.setText("有");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel3.add(addButton2);
final JButton updButton2 = new JButton("修改表格数据");
updButton2.setBounds(220, 540, 170, 20);
updButton2.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(fab3.getText(), variabl1823, 2);
variabl19653.setValueAt(fab4.getText(), variabl1823, 3);
variabl19653.setValueAt(fab5.getText(), variabl1823, 4);
variabl19653.setValueAt(fab6.getText(), variabl1823, 5);
variabl19653.setValueAt(fab7.getText(), variabl1823, 6);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel3.add(updButton2);
final JButton delButton2 = new JButton("从表格中删除");
delButton2.setBounds(390, 540, 170, 20);
delButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = variabl26553.getSelectedRow();
if (variabl1823 != -1)
variabl19653.removeRow(variabl1823);
}
});
panel3.add(delButton2);
final JButton countButton2 = new JButton("辅助计算");
countButton2.setBounds(560, 540, 170, 20);
countButton2.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 < 7; j++) {
variabl2649[i][j] = variabl19653.getValueAt(i, j)
.toString().trim();
}
for (int j = 1; j < 5; j++) {
if (j != 3) {
if (variabl2649[i][j].length() > 0)
variabl26491[i][j] = Integer
.valueOf(variabl2649[i][j]);
else
variabl26491[i][j] = 0;
}
}
variabl26491[i][1] = variabl26491[i][1]
* variabl26491[i][4];
variabl2649[i][1] = "" + variabl26491[i][1];
variabl26491[i][2] = variabl26491[i][2]
* variabl26491[i][4];
variabl2649[i][2] = "" + variabl26491[i][2];
}
variabl19653.setRowCount(0);
for (int i = 0; i < variabl2059; i++)
variabl19653.addRow(variabl2649[i]);
}
});
panel3.add(countButton2);
final JButton clearButton2 = new JButton("清参数文本框");
clearButton2.setBounds(730, 540, 170, 20);
clearButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fab1.setText("");
fab2.setText("0");
fab3.setText("1");
fab4.setText("宋体");
fab5.setText("0");
fab6.setText("有");
fab7.setText("有");
}
});
panel3.add(clearButton2);
flc1 = new JLabel("内容");
flc1.setBounds(70, 360, 40, 20);
panel4.add(flc1);
fac1 = new JTextField("", 20);
fac1.setBounds(110, 360, 100, 20);
panel4.add(fac1);
fac1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 1;
list4.removeAll();
}
});
flc2 = new JLabel("变量名");
flc2.setBounds(230, 360, 50, 20);
panel4.add(flc2);
fac2 = new JTextField("", 20);
fac2.setBounds(280, 360, 60, 20);
panel4.add(fac2);
fac2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 2;
list4.removeAll();
}
});
flc11 = new JLabel("行号");
flc11.setBounds(370, 360, 40, 20);
panel4.add(flc11);
fac11 = new JTextField("", 20);
fac11.setBounds(410, 360, 60, 20);
panel4.add(fac11);
fac11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 11;
list4.removeAll();
}
});
flc12 = new JLabel("列号");
flc12.setBounds(500, 360, 40, 20);
panel4.add(flc12);
fac12 = new JTextField("", 20);
fac12.setBounds(540, 360, 60, 20);
panel4.add(fac12);
fac12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 12;
list4.removeAll();
}
});
flc3 = new JLabel("宽度");
flc3.setBounds(630, 360, 40, 20);
panel4.add(flc3);
fac3 = new JTextField("", 20);
fac3.setBounds(670, 360, 60, 20);
panel4.add(fac3);
fac3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 3;
list4.removeAll();
}
});
flc4 = new JLabel("高度");
flc4.setBounds(760, 360, 40, 20);
panel4.add(flc4);
fac4 = new JTextField("", 20);
fac4.setBounds(800, 360, 60, 20);
panel4.add(fac4);
fac4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 4;
list4.removeAll();
}
});
flc5 = new JLabel("左边距");
flc5.setBounds(60, 400, 50, 20);
panel4.add(flc5);
fac5 = new JTextField("", 20);
fac5.setBounds(110, 400, 100, 20);
panel4.add(fac5);
fac5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 5;
list4.removeAll();
}
});
flc6 = new JLabel("到顶距");
panel4.add(flc6);
fac6 = new JTextField("", 20);
panel4.add(fac6);
flc6.setBounds(220, 400, 60, 20);
fac6.setBounds(280, 400, 60, 20);
fac6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 6;
list4.removeAll();
}
});
flc7 = new JLabel("字体");
panel4.add(flc7);
fac7 = new JTextField("", 20);
panel4.add(fac7);
flc7.setBounds(370, 400, 40, 20);
fac7.setBounds(410, 400, 120, 20);
fac7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 7;
list4.removeAll();
for (int i = 0; i < variabl2629.length; i++) {
list4.add(variabl2629[i]);
}
}
});
flc8 = new JLabel("字号");
panel4.add(flc8);
fac8 = new JTextField("", 20);
panel4.add(fac8);
flc8.setBounds(560, 400, 40, 20);
fac8.setBounds(600, 400, 100, 20);
fac8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 8;
list4.removeAll();
for (int i = 0; i < variabl2607.length; i++) {
list4.add(variabl2607[i]);
}
}
});
list4.setBounds(840, 10, 120, 330);
panel4.add(list4);
list4.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list4.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (variabl1739) {
case 1:
fac1.setText(list4.getSelectedItem());
break;
case 2:
fac2.setText(list4.getSelectedItem());
break;
case 3:
fac3.setText(list4.getSelectedItem());
break;
case 4:
fac4.setText(list4.getSelectedItem());
break;
case 5:
fac5.setText(list4.getSelectedItem());
break;
case 6:
fac6.setText(list4.getSelectedItem());
break;
case 7:
fac7.setText(list4.getSelectedItem());
break;
case 8:
fac8.setText(list4.getSelectedItem());
break;
case 11:
fac11.setText(list4.getSelectedItem());
break;
case 12:
fac12.setText(list4.getSelectedItem());
break;
}
}
}
});
variabl26554.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int variabl1823 = variabl26554.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (variabl19654.getValueAt(variabl1823, j) != null)
variabl2327 = variabl19654.getValueAt(variabl1823, j)
.toString();
else
variabl2327 = "";
switch (j) {
case 0:
fac1.setText(variabl2327.toString());
break;
case 1:
fac2.setText(variabl2327.toString());
break;
case 2:
fac11.setText(variabl2327.toString());
break;
case 3:
fac12.setText(variabl2327.toString());
break;
case 4:
fac3.setText(variabl2327.toString());
break;
case 5:
fac4.setText(variabl2327.toString());
break;
case 6:
fac5.setText(variabl2327.toString());
break;
case 7:
fac6.setText(variabl2327.toString());
break;
case 8:
fac7.setText(variabl2327.toString());
break;
case 9:
fac8.setText(variabl2327.toString());
break;
}
}
}
});
final JButton addButton4 = new JButton("添加到表格中");
addButton4.setBounds(50, 440, 170, 20);
addButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < variabl19654.getRowCount(); i++) {
if ((variabl19654.getValueAt(i, 0) != null)
&& (variabl19654.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fac1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 < 0) {
String[] rowValues = { fac1.getText(), fac2.getText(),
fac11.getText(), fac12.getText(), fac3.getText(),
fac4.getText(), fac5.getText(), fac6.getText(),
fac7.getText(), fac8.getText() };
variabl19654.addRow(rowValues);
int rowCount = variabl26554.getRowCount() + 1;
fac1.setText("");
fac2.setText("0");
fac3.setText("0");
fac4.setText("0");
fac5.setText("0");
fac6.setText("0");
fac7.setText("");
fac8.setText("0");
fac11.setText("0");
fac12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel4.add(addButton4);
final JButton updButton4 = new JButton("修改表格数据");
updButton4.setBounds(220, 440, 170, 20);
updButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1;
for (int i = 0; i < variabl19654.getRowCount(); i++) {
if ((variabl19654.getValueAt(i, 0) != null)
&& (variabl19654.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fac1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 >= 0) {
variabl19654.setValueAt(fac1.getText(), variabl1823, 0);
variabl19654.setValueAt(fac2.getText(), variabl1823, 1);
variabl19654.setValueAt(fac11.getText(), variabl1823, 2);
variabl19654.setValueAt(fac12.getText(), variabl1823, 3);
variabl19654.setValueAt(fac3.getText(), variabl1823, 4);
variabl19654.setValueAt(fac4.getText(), variabl1823, 5);
variabl19654.setValueAt(fac5.getText(), variabl1823, 6);
variabl19654.setValueAt(fac6.getText(), variabl1823, 7);
variabl19654.setValueAt(fac7.getText(), variabl1823, 8);
variabl19654.setValueAt(fac8.getText(), variabl1823, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel4.add(updButton4);
final JButton delButton4 = new JButton("从表格中删除");
delButton4.setBounds(390, 440, 170, 20);
delButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = variabl26554.getSelectedRow();
if (variabl1823 != -1)
variabl19654.removeRow(variabl1823);
}
});
panel4.add(delButton4);
final JButton countButton4 = new JButton("辅助计算");
countButton4.setBounds(560, 440, 170, 20);
countButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl2059 = variabl19654.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] = variabl19654.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.3);
variabl2649[i][j] = "" + variabl26491[i][j];
}
}
variabl19654.setRowCount(0);
for (int i = 0; i < variabl2059; i++)
variabl19654.addRow(variabl2649[i]);
}
});
panel4.add(countButton4);
final JButton clearButton4 = new JButton("清参数文本框");
clearButton4.setBounds(730, 440, 170, 20);
clearButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fac1.setText("");
fac2.setText("0");
fac3.setText("0");
fac4.setText("0");
fac5.setText("0");
fac6.setText("0");
fac7.setText("");
fac8.setText("0");
fac11.setText("0");
fac12.setText("0");
}
});
panel4.add(clearButton4);
/* 表尾页 */
fld1 = new JLabel("内容");
fld1.setBounds(70, 360, 40, 20);
panel5.add(fld1);
fad1 = new JTextField("", 20);
fad1.setBounds(110, 360, 100, 20);
panel5.add(fad1);
fad1.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 1;
list5.removeAll();
}
});
fld2 = new JLabel("变量名");
fld2.setBounds(230, 360, 50, 20);
panel5.add(fld2);
fad2 = new JTextField("", 20);
fad2.setBounds(280, 360, 60, 20);
panel5.add(fad2);
fad2.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 2;
list5.removeAll();
}
});
fld11 = new JLabel("行号");
fld11.setBounds(370, 360, 40, 20);
panel5.add(fld11);
fad11 = new JTextField("", 20);
fad11.setBounds(410, 360, 60, 20);
panel5.add(fad11);
fad11.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 11;
list5.removeAll();
}
});
fld12 = new JLabel("列号");
fld12.setBounds(500, 360, 40, 20);
panel5.add(fld12);
fad12 = new JTextField("", 20);
fad12.setBounds(540, 360, 60, 20);
panel5.add(fad12);
fad12.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 12;
list5.removeAll();
}
});
fld3 = new JLabel("宽度");
fld3.setBounds(630, 360, 40, 20);
panel5.add(fld3);
fad3 = new JTextField("", 20);
fad3.setBounds(670, 360, 60, 20);
panel5.add(fad3);
fad3.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 3;
list5.removeAll();
}
});
fld4 = new JLabel("高度");
fld4.setBounds(760, 360, 40, 20);
panel5.add(fld4);
fad4 = new JTextField("", 20);
fad4.setBounds(800, 360, 60, 20);
panel5.add(fad4);
fad4.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 4;
list5.removeAll();
}
});
fld5 = new JLabel("左边距");
fld5.setBounds(60, 400, 50, 20);
panel5.add(fld5);
fad5 = new JTextField("", 20);
fad5.setBounds(110, 400, 100, 20);
panel5.add(fad5);
fad5.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 5;
list5.removeAll();
}
});
fld6 = new JLabel("到顶距");
panel5.add(fld6);
fad6 = new JTextField("", 20);
panel5.add(fad6);
fld6.setBounds(220, 400, 60, 20);
fad6.setBounds(280, 400, 60, 20);
fad6.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 6;
list5.removeAll();
}
});
fld7 = new JLabel("字体");
panel5.add(fld7);
fad7 = new JTextField("", 20);
panel5.add(fad7);
fld7.setBounds(370, 400, 40, 20);
fad7.setBounds(410, 400, 120, 20);
fad7.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 7;
list5.removeAll();
for (int i = 0; i < variabl2629.length; i++) {
list5.add(variabl2629[i]);
}
}
});
fld8 = new JLabel("字号");
panel5.add(fld8);
fad8 = new JTextField("", 20);
panel5.add(fad8);
fld8.setBounds(560, 400, 40, 20);
fad8.setBounds(600, 400, 100, 20);
fad8.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent arg0) {
variabl1739 = 8;
list5.removeAll();
for (int i = 0; i < variabl2607.length; i++) {
list5.add(variabl2607[i]);
}
}
});
list5.setBounds(840, 10, 170, 330);
panel5.add(list5);
list5.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (list5.getSelectedIndex() >= 0) {
int w1, w2, h1, h2;
switch (variabl1739) {
case 1:
fad1.setText(list5.getSelectedItem());
break;
case 2:
fad2.setText(list5.getSelectedItem());
break;
case 3:
fad3.setText(list5.getSelectedItem());
break;
case 4:
fad4.setText(list5.getSelectedItem());
break;
case 5:
fad5.setText(list5.getSelectedItem());
break;
case 6:
fad6.setText(list5.getSelectedItem());
break;
case 7:
fad7.setText(list5.getSelectedItem());
break;
case 8:
fad8.setText(list5.getSelectedItem());
break;
case 11:
fad11.setText(list5.getSelectedItem());
break;
case 12:
fad12.setText(list5.getSelectedItem());
break;
}
}
}
});
variabl26555.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int variabl1823 = variabl26555.getSelectedRow();
for (int j = 0; j < 10; j++) {
if (variabl19655.getValueAt(variabl1823, j) != null)
variabl2327 = variabl19655.getValueAt(variabl1823, j)
.toString();
else
variabl2327 = "";
switch (j) {
case 0:
fad1.setText(variabl2327.toString());
break;
case 1:
fad2.setText(variabl2327.toString());
break;
case 2:
fad11.setText(variabl2327.toString());
break;
case 3:
fad12.setText(variabl2327.toString());
break;
case 4:
fad3.setText(variabl2327.toString());
break;
case 5:
fad4.setText(variabl2327.toString());
break;
case 6:
fad5.setText(variabl2327.toString());
break;
case 7:
fad6.setText(variabl2327.toString());
break;
case 8:
fad7.setText(variabl2327.toString());
break;
case 9:
fad8.setText(variabl2327.toString());
break;
}
}
}
});
final JButton addButton5 = new JButton("添加到表格中");
addButton5.setBounds(50, 440, 170, 20);
addButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < variabl19655.getRowCount(); i++) {
if ((variabl19655.getValueAt(i, 0) != null)
&& (variabl19655.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fad1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 < 0) {
String[] rowValues = { fad1.getText(), fad2.getText(),
fad11.getText(), fad12.getText(), fad3.getText(),
fad4.getText(), fad5.getText(), fad6.getText(),
fad7.getText(), fad8.getText() };
variabl19655.addRow(rowValues);
int rowCount = variabl26555.getRowCount() + 1;
fad1.setText("");
fad2.setText("0");
fad3.setText("0");
fad4.setText("0");
fad5.setText("0");
fad6.setText("0");
fad7.setText("");
fad8.setText("0");
fad11.setText("0");
fad12.setText("0");
} else
JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");
}
});
panel5.add(addButton5);
final JButton updButton5 = new JButton("修改表格数据");
updButton5.setBounds(220, 440, 170, 20);
updButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = -1;
for (int i = 0; i < variabl19655.getRowCount(); i++) {
if ((variabl19655.getValueAt(i, 0) != null)
&& (variabl19655.getValueAt(i, 0).toString().trim()
.equalsIgnoreCase(fad1.getText().trim()))) {
variabl1823 = i;
break;
}
}
if (variabl1823 >= 0) {
variabl19655.setValueAt(fad1.getText(), variabl1823, 0);
variabl19655.setValueAt(fad2.getText(), variabl1823, 1);
variabl19655.setValueAt(fad11.getText(), variabl1823, 2);
variabl19655.setValueAt(fad12.getText(), variabl1823, 3);
variabl19655.setValueAt(fad3.getText(), variabl1823, 4);
variabl19655.setValueAt(fad4.getText(), variabl1823, 5);
variabl19655.setValueAt(fad5.getText(), variabl1823, 6);
variabl19655.setValueAt(fad6.getText(), variabl1823, 7);
variabl19655.setValueAt(fad7.getText(), variabl1823, 8);
variabl19655.setValueAt(fad8.getText(), variabl1823, 9);
} else
JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");
}
});
panel5.add(updButton5);
final JButton delButton5 = new JButton("从表格中删除");
delButton5.setBounds(390, 440, 170, 20);
delButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl1823 = variabl26555.getSelectedRow();
if (variabl1823 != -1)
variabl19655.removeRow(variabl1823);
}
});
panel5.add(delButton5);
final JButton countButton5 = new JButton("辅助计算");
countButton5.setBounds(560, 440, 170, 20);
countButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int variabl2059 = variabl19655.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] = variabl19655.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];
}
}
variabl19655.setRowCount(0);
for (int i = 0; i < variabl2059; i++)
variabl19655.addRow(variabl2649[i]);
}
});
panel5.add(countButton5);
final JButton clearButton5 = new JButton("清参数文本框");
clearButton5.setBounds(730, 440, 170, 20);
clearButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fad1.setText("");
fad2.setText("0");
fad3.setText("0");
fad4.setText("0");
fad5.setText("0");
fad6.setText("0");
fad7.setText("");
fad8.setText("0");
fad11.setText("0");
fad12.setText("0");
}
});
panel5.add(clearButton5);
frame5.add(panel5);
frame4.add(panel4);
frame3.add(panel3);
frame2.add(panel2);
frame1.add(panel1);
frame5.setVisible(true);
frame4.setVisible(true);
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, "读取数据库数据出错!");
}
}
}
85.源码85,部件程序,表格式报表打印预览程序。用于单或多数据表的表格式报表打印预览,根据表格式报表格式文件设计程序打印预览。
/*
* 程序文件名:dataPreview.java
* 作者:程学先
* 本程序用于单或多数据表的表格式报表打印预览,内容只限数据表中数据。
* 要求先利用程序printFormat1.java生成格式文件。
* 要求输入的参数:数据表名,打印格式文件名。
* 调用命令:dataPreview.means(parameter)
* 就可根据格式文件预览打印结构与内容。
*/
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
public class dataPreview extends JComponent {
private static JFrame frame1;
private static Connection cont4;
private static Statement stat4;
private static ResultSetMetaData rsmdt4;
private static ResultSet rs;
private static String variabl2603;
private static String variabl3645;
private static String s1 = "", s2 = "";
private static int variabl1853 = 0, variabl2651 = 0;
private static String[] variabl2517;
private static String[] variabl1501;
private static int[] variabl1489;
private static String[][] variabl2197;
private static ArrayList<struct1> title = new ArrayList<struct1>();
private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();
private static ArrayList<struct3> table1 = new ArrayList<struct3>();
private static ArrayList<struct4> table2 = new ArrayList<struct4>();
private static ArrayList<struct5> table3 = new ArrayList<struct5>();
private static int variabl2681 = 600;
private static int x1 = 0, y1 = 0, w1 = 0, h1 = 0, variabl2661 = 0,
variabl2657 = 0;
private static Graphics2D g3;
private static Graphics g;
private static HashSet set01 = new HashSet();
private static String variabl2049 = "";
private static String variabl1633 = "";
private static String[][] variabl21970 = null;
static void title() {
struct2[] variabl2533 = new struct2[tableTitle.size()];
variabl2661 = Integer.valueOf(tableTitle.get(0).tableTitle[3]);
variabl2661 = variabl2661 / 2;
for (int i = 0; i < tableTitle.size(); i++) {
variabl2533[i] = tableTitle.get(i);
}
try {
g3.setFont(new Font(variabl2533[0].tableTitle[6], Font.PLAIN,
Integer.valueOf(variabl2533[0].tableTitle[7])));
for (int i = 0; i < tableTitle.size(); i++) {
x1 = variabl2661;
y1 = variabl2657;
w1 = Integer.valueOf(variabl2533[i].tableTitle[3]);
h1 = Integer.valueOf(variabl2533[i].tableTitle[4]);
g3.drawLine(x1, y1, x1 + w1, y1);
g3.drawLine(x1, y1, x1, y1 + h1);
g3.drawString(variabl2533[i].tableTitle[0], variabl2661 + 2,
variabl2657 + h1);
if (variabl2533[i].tableTitle[8].equals("有"))
g3.drawLine(x1, y1 + h1, x1 + w1, y1 + h1);
if (variabl2533[i].tableTitle[9].equals("有"))
g3.drawLine(x1 + w1, y1, x1 + w1, y1 + h1);
variabl2661 = variabl2661 + w1;
if ((i < tableTitle.size() - 1)
&& (Integer.valueOf(variabl2533[i].tableTitle[1]) < Integer
.valueOf(variabl2533[i + 1].tableTitle[1])))
variabl2657 = variabl2657 + h1;
}
variabl2657 = variabl2657 + h1;
} catch (Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog(null, "打印失败,请检查有关位置数据是否短缺?");
}
}
protected void paintComponent(Graphics g1) {
g = g1;
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[4]);
y1 = Integer.valueOf(variabl2535[i].title[5]);
g3.drawString(variabl2535[i].title[0], x1, y1);
variabl2657 = y1 + Integer.valueOf(variabl2535[i].title[5]);
}
title();
try {
struct3[] variabl2685 = new struct3[table1.size()];
int[] w10 = new int[table1.size()];
int[] h10 = new int[table1.size()];
int[] h20 = new int[table1.size()];
for (int i = 0; i < table1.size(); i++) {
variabl2685[i] = table1.get(i);
w10[i] = Integer.valueOf(variabl2685[i].table1[1]);
h10[i] = Integer.valueOf(variabl2685[i].table1[2]);
h20[i] = Integer.valueOf(variabl2685[i].table1[4]);
}
y1 = variabl2657;
g3.setFont(new Font(variabl2685[0].table1[3], Font.PLAIN, Integer
.valueOf(variabl2685[0].table1[4])));
for (int j = 0; j < variabl1853; j++) {
x1 = Integer.valueOf(tableTitle.get(0).tableTitle[3]) / 2;
g3.drawLine(x1, y1, x1, y1 + h1);
for (int i = 0; i < table1.size(); i++) {
if (variabl2197[j][i] == null)
variabl2197[j][i] = " ";
g3.drawString(variabl2197[j][i], x1 + 2, y1 + h20[i]);
if (variabl2685[i].table1[5].equals("有"))
g3.drawLine(x1, y1 + h10[i], x1 + w10[i], y1 + h10[i]);
if (variabl2685[i].table1[6].equals("有"))
g3.drawLine(x1 + w10[i], y1, x1 + w10[i], y1 + h10[i]);
x1 = x1 + w10[i];
}
y1 = y1 + h10[table1.size() - 1];
if ((y1 >= variabl2681) || (j == variabl1853 - 1)) {
struct4[] variabl2653 = new struct4[table2.size()];
for (int i1 = 0; i1 < table2.size(); i1++) {
variabl2653[i1] = table2.get(i1);
g3.setFont(new Font(variabl2653[i1].table2[8],
Font.PLAIN, Integer
.valueOf(variabl2653[i1].table2[9])));
x1 = Integer.valueOf(variabl2653[i1].table2[6]);
y1 = Integer.valueOf(variabl2653[i1].table2[7]) + y1;
g3.drawString(variabl2653[i1].table2[0], x1, y1);
variabl2657 = y1
+ Integer.valueOf(variabl2653[i1].table2[5]);
}
y1 = 640;
break;
}
}
y1 = y1 + h10[table1.size() - 1];
struct5[] variabl2665 = new struct5[table3.size()];
for (int i = 0; i < table3.size(); i++) {
variabl2665[i] = table3.get(i);
g3.setFont(new Font(variabl2665[i].table3[8], Font.PLAIN,
Integer.valueOf(variabl2665[i].table3[9])));
x1 = Integer.valueOf(variabl2665[i].table3[6]);
y1 = y1 + Integer.valueOf(variabl2665[i].table3[5]) / 2;
g3.drawString(variabl2665[i].table3[0], x1, y1);
}
} catch (Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog(null, "打印失败,请检查有关位置数据是否短缺?");
}
}
static void means(String[] parameter) {
s1 = "";
s2 = "";
variabl1853 = 0;
variabl2651 = 0;
title = new ArrayList<struct1>();
tableTitle = new ArrayList<struct2>();
table1 = new ArrayList<struct3>();
table2 = new ArrayList<struct4>();
table3 = new ArrayList<struct5>();
variabl2681 = 600;
x1 = 0;
y1 = 0;
w1 = 0;
h1 = 0;
variabl2661 = 0;
variabl2657 = 0;
variabl2603 = parameter[4];
variabl3645 = parameter[15];
frame1 = new JFrame(
"报表预览程序 作者:程学先");
frame1.setBounds(10, 10, 1000, 1000);
frame1.add(new dataPreview());
frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame1.setVisible(true);
File file1 = new File(variabl3645);
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("。")));
} else if (tempStr.substring(0, 2).equals("4,")) {
table2.add(new struct4(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("5,")) {
table3.add(new struct5(tempStr.substring(2,
tempStr.length()).split("。")));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
variabl1633 = "";
for (int i = 0; i < table1.size(); i++) {
if (variabl1633.length() == 0)
variabl1633 = table1.get(i).table1[0];
else
variabl1633 = variabl1633 + "," + table1.get(i).table1[0];
}
数据表查询结构(variabl2603);
数据表查询数据(variabl2603);
}
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);
rsmdt4 = rs.getMetaData();
variabl2651 = rsmdt4.getColumnCount();
variabl2517 = new String[variabl2651];
variabl1501 = new String[variabl2651];
variabl1489 = new int[variabl2651];
for (int i = 0; i < variabl2651; i++) {
variabl2517[i] = rsmdt4.getColumnName(i + 1);
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
} else {
s10 = variabl2217.split(",");
String s0 = "", s1 = "", s2 = "";
int k = 0;
for (int i = 0; i < s10.length; i++) {
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select * from " + s10[i];
rs = stat4.executeQuery(s1);
rsmdt4 = rs.getMetaData();
variabl2651 = rsmdt4.getColumnCount();
for (int j = 0; j < variabl2651; j++) {
s2 = rsmdt4.getColumnName(j + 1).toLowerCase();
n2 = n1;
if (i > 0) {
k = 0;
for (int j1 = 0; j1 < n2; j1++) {
if (sk[j1].equals(s2)) {
sk[j1] = s10[i - 1] + "." + sk[j1];
if (variabl2049.length() == 0)
variabl2049 = " where " + s10[i - 1]
+ "." + s2 + " = " + s10[i]
+ "." + s2;
else
variabl2049 = variabl2049 + " and "
+ s10[i - 1] + "." + s2 + " = "
+ s10[i] + "." + s2;
sk[n1] = s10[i] + "." + s2 + " as "
+ (s2 + i);
n1++;
k = 1;
break;
}
}
if (k == 0) {
sk[n1] = s2;
n1++;
}
} else {
sk[n1] = s2;
n1++;
}
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
variabl2517 = new String[n1];
variabl1501 = new String[n1];
variabl1489 = new int[n1];
for (int i1 = 0; i1 < n1; i1++)
variabl2517[i1] = sk[i1];
}
}
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);
rsmdt4 = rs.getMetaData();
variabl2651 = rsmdt4.getColumnCount();
for (int i1 = 0; i1 < variabl2651; i1++) {
variabl1501[i1] = rsmdt4.getColumnTypeName(i1 + 1);
variabl1489[i1] = rsmdt4.getColumnDisplaySize(i1 + 1);
}
rs.last();
variabl1853 = rs.getRow();
variabl2197 = new String[variabl1853][variabl2651];
variabl21970 = new String[variabl1853][variabl2651];
while (c < variabl1853) {
rs.absolute(c + 1);
while (b < variabl2651) {
variabl21970[c][b] = rs.getString(b + 1);
if ((main1.variabl1545.lastIndexOf("," + variabl1501[b]
+ ",")) > 0)
if ((variabl21970[c][b] == null)
|| (variabl21970[c][b].trim().length() == 0))
variabl21970[c][b] = "0";
else if (variabl21970[c][b] == null)
variabl21970[c][b] = "";
variabl2197[c][b] = variabl21970[c][b];
b++;
}
c++;
b = 0;
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
}
86.源码86,部件程序,表格式报表打印程序。用于单或多数据表的表格式报表打印,根据表格式报表格式文件设计程序打印。
/*
* 程序文件名:dataPrint.java
* 作者:程学先
* 本程序用于单或多数据表的表格式报表打印,内容只限数据表中数据。
* 要求先利用程序printFormat1.java生成格式文件。
* 要求输入的参数:数据表名,打印格式文件名。
* 调用命令:dataPrint.means(parameter)
*/
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class dataPrint extends JFrame {
private static JFrame frame1;
private static Connection cont4;
private static Statement stat4;
private static ResultSetMetaData rsmdt4;
private static ResultSet rs;
private static String variabl2603;
private static String variabl3625;
private static String s1 = "", s2 = "";
private static int variabl1853 = 0, variabl2651 = 0;
private static String[] variabl2517;
private static String[] variabl1501;
private static int[] variabl1489;
private static String[][] variabl2197;
private static ArrayList<struct1> title = new ArrayList<struct1>();
private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();
private static ArrayList<struct3> table1 = new ArrayList<struct3>();
private static ArrayList<struct4> table2 = new ArrayList<struct4>();
private static ArrayList<struct5> table3 = new ArrayList<struct5>();
private static int variabl2681 = 600;
private static int x1 = 0, y1 = 0, w1 = 0, h1 = 0, variabl2661 = 0, variabl2657 = 0;
private PageFormat pf;
private static Graphics2D g2;
private static String[][] variabl21970;
private static String variabl2049 = "";
private static String variabl1633 = "";
private static HashSet set01 = new HashSet();
static void title() {
struct2[] variabl2533 = new struct2[tableTitle.size()];
variabl2661 = Integer.valueOf(tableTitle.get(0).tableTitle[3]);
variabl2661 = variabl2661 / 2;
for (int i = 0; i < tableTitle.size(); i++)
variabl2533[i] = tableTitle.get(i);
try {
g2.setFont(new Font(variabl2533[0].tableTitle[6], Font.PLAIN, Integer
.valueOf(variabl2533[0].tableTitle[7])));
for (int i = 0; i < tableTitle.size(); i++) {
x1 = variabl2661;
y1 = variabl2657;
w1 = Integer.valueOf(variabl2533[i].tableTitle[3]);
h1 = Integer.valueOf(variabl2533[i].tableTitle[4]);
g2.drawLine(x1, y1, x1 + w1, y1);
g2.drawLine(x1, y1, x1, y1 + h1);
g2.drawString(variabl2533[i].tableTitle[0], variabl2661 + 2, variabl2657 + h1);
if (variabl2533[i].tableTitle[8].equals("有"))
g2.drawLine(x1, y1 + h1, x1 + w1, y1 + h1);
if (variabl2533[i].tableTitle[9].equals("有"))
g2.drawLine(x1 + w1, y1, x1 + w1, y1 + h1);
variabl2661 = variabl2661 + w1;
if ((i < tableTitle.size() - 1)
&& (Integer.valueOf(variabl2533[i].tableTitle[1]) < Integer
.valueOf(variabl2533[i + 1].tableTitle[1])))
variabl2657 = variabl2657 + h1;
}
variabl2657 = variabl2657 + h1;
} catch (Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog(null, "打印失败,请检查有关位置数据是否短缺?");
}
}
public static void means(String[] parameter) {
s1 = "";
s2 = "";
variabl1853 = 0;
variabl2651 = 0;
title = new ArrayList<struct1>();
tableTitle = new ArrayList<struct2>();
table1 = new ArrayList<struct3>();
table2 = new ArrayList<struct4>();
table3 = new ArrayList<struct5>();
variabl2681 = 600;
x1 = 0;
y1 = 0;
w1 = 0;
h1 = 0;
variabl2661 = 0;
variabl2657 = 0;
variabl2603 = parameter[4];
variabl3625 = parameter[15];
dataPrint frame = new dataPrint();
frame.setTitle("单记录式报表打印程序 作者:程学先");
frame.pf = new PageFormat();
frame.pf.setOrientation(PageFormat.LANDSCAPE);
File file1 = new File(variabl3625);
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("。")));
} else if (tempStr.substring(0, 2).equals("4,")) {
table2.add(new struct4(tempStr.substring(2,
tempStr.length()).split("。")));
} else if (tempStr.substring(0, 2).equals("5,")) {
table3.add(new struct5(tempStr.substring(2,
tempStr.length()).split("。")));
}
}
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "打开文件错!");
}
variabl1633="";
for (int i=0;i<table1.size();i++){
if (variabl1633.length()==0) variabl1633=table1.get(i).table1[0];
else
variabl1633=variabl1633+","+table1.get(i).table1[0];
}
数据表查询结构(variabl2603);
数据表查询数据(variabl2603);
final PrinterJob job = PrinterJob.getPrinterJob();
if (!job.printDialog())
return;
job.setPrintable(new Printable() {
public int print(Graphics graphics, PageFormat pageFormat,
int pageIndex) throws PrinterException {
if (pageIndex < 1) {
g2 = (Graphics2D) graphics;
g2.setStroke(new BasicStroke(1f));
try {
struct1[] variabl2535 = new struct1[title.size()];
variabl2657 = 0;
variabl2661 = 0;
for (int i = 0; i < title.size(); i++) {
variabl2535[i] = title.get(i);
g2.setFont(new Font(variabl2535[i].title[8], Font.PLAIN,
Integer.valueOf(variabl2535[i].title[9])));
x1 = Integer.valueOf(variabl2535[i].title[4]);
y1 = Integer.valueOf(variabl2535[i].title[5]);
g2.drawString(variabl2535[i].title[0], x1, y1);
variabl2657 = y1 + Integer.valueOf(variabl2535[i].title[5]);
}
title();
struct3[] variabl2685 = new struct3[table1.size()];
int[] w10 = new int[table1.size()];
int[] h10 = new int[table1.size()];
int[] h20 = new int[table1.size()];
for (int i = 0; i < table1.size(); i++) {
variabl2685[i] = table1.get(i);
w10[i] = Integer.valueOf(variabl2685[i].table1[1]);
h10[i] = Integer.valueOf(variabl2685[i].table1[2]);
h20[i] = Integer.valueOf(variabl2685[i].table1[4]);
}
y1 = variabl2657;
for (int j = 0; j < variabl1853; j++) {
x1 = Integer.valueOf(tableTitle.get(0).tableTitle[3]) / 2;
g2.drawLine(x1, y1, x1, y1 + h1);
for (int i = 0; i < table1.size(); i++) {
if (variabl2197[j][i] == null)
variabl2197[j][i] = " ";
g2.drawString(variabl2197[j][i], x1 + 2, y1 + h20[i]);
if (variabl2685[i].table1[5].equals("有"))
g2.drawLine(x1, y1 + h10[i], x1 + w10[i],
y1 + h10[i]);
if (variabl2685[i].table1[6].equals("有"))
g2.drawLine(x1 + w10[i], y1, x1 + w10[i],
y1 + h10[i]);
x1 = x1 + w10[i];
}
y1 = y1 + h10[table1.size() - 1];
if (y1 >= variabl2681) {
struct4[] variabl2653 = new struct4[table2.size()];
for (int i1 = 0; i1 < table2.size(); i1++) {
variabl2653[i1] = table2.get(i1);
g2.setFont(new Font(variabl2653[i1].table2[8],
Font.PLAIN, Integer
.valueOf(variabl2653[i1].table2[9])));
x1 = Integer.valueOf(variabl2653[i1].table2[6]);
y1 = Integer.valueOf(variabl2653[i1].table2[7]);
g2.drawString(variabl2653[i1].table2[0], x1, y1);
variabl2657 = y1 + Integer.valueOf(variabl2653[i1].table2[5]);
}
y1 = 640;
break;
}
}
y1 = y1 + h10[table1.size() - 1];
struct5[] variabl2665 = new struct5[table3.size()];
for (int i = 0; i < table3.size(); i++) {
variabl2665[i] = table3.get(i);
g2.setFont(new Font(variabl2665[i].table3[8], Font.PLAIN,
Integer.valueOf(variabl2665[i].table3[9])));
x1 = Integer.valueOf(variabl2665[i].table3[6]);
y1 = y1 + Integer.valueOf(variabl2665[i].table3[5]) / 2;
g2.drawString(variabl2665[i].table3[0], x1, y1);
}
} catch (Exception e2) {
frame1.setVisible(false);
frame1.dispose();
JOptionPane.showMessageDialog(null,
"打印失败,请检查有关位置数据是否短缺?");
}
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
});
try {
job.print();
} catch (Exception e1) {
e1.printStackTrace();
}
frame.dispose();
}
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);
rsmdt4 = rs.getMetaData();
variabl2651 = rsmdt4.getColumnCount();
variabl2517 = new String[variabl2651];
variabl1501= new String[variabl2651];
variabl1489= new int[variabl2651];
for (int i = 0; i < variabl2651; i++) {
variabl2517[i] = rsmdt4.getColumnName(i + 1);
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
else {
s10=variabl2217.split(",");
String s0="",s1="",s2="";
int k=0;
for (int i=0;i<s10.length;i++){
try {
cont4 = main1.getConn();
stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s1 = "select * from " + s10[i];
rs = stat4.executeQuery(s1);
rsmdt4 = rs.getMetaData();
variabl2651 = rsmdt4.getColumnCount();
for (int j = 0; j < variabl2651; j++) {
s2 = rsmdt4.getColumnName(j + 1).toLowerCase();
n2=n1;
if (i>0){
k=0;
for (int j1=0;j1<n2;j1++){
if (sk[j1].equals(s2)){
sk[j1]=s10[i-1]+"."+sk[j1];
if (variabl2049.length()==0)
variabl2049=" where "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;
else variabl2049=variabl2049+" and "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;
sk[n1]=s10[i]+"."+s2+" as "+(s2+i);
n1++;
k=1;
break;
}
}
if (k==0) {
sk[n1]=s2;
n1++;
}
}
else {
sk[n1]=s2;
n1++;
}
}
rs.close();
stat4.close();
cont4.close();
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "读取数据库数据出错!");
}
}
variabl2517 = new String[n1];
variabl1501= new String[n1];
variabl1489= new int[n1];
for (int i1=0;i1<n1;i1++)
variabl2517[i1]=sk[i1];
}
}
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);
rsmdt4 = rs.getMetaData();
variabl2651 = rsmdt4.getColumnCount();
for (int i1=0;i1<variabl2651;i1++){
variabl1501[i1] = rsmdt4.getColumnTypeName(i1+1);
variabl1489[i1] = rsmdt4.getColumnDisplaySize(i1+1);
}
rs.last();
variabl1853=rs.getRow();
variabl2197=new String[variabl1853][variabl2651];
variabl21970=new String[variabl1853][variabl2651];
while (c < variabl1853) {
rs.absolute(c + 1);
while (b < variabl2651) {
variabl21970[c][b] = rs.getString(b + 1);
if ((main1.variabl1545.lastIndexOf("," + variabl1501[b] + ",")) > 0)
if ((variabl21970[c][b] == null)
|| (variabl21970[c][b].trim().length() == 0))
variabl21970[c][b] = "0";
else if (variabl21970[c][b] == null)
variabl21970[c][b] = "";
variabl2197[c][b] = variabl21970[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 17:24
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社