// 客户增加事件处理
Zengjia1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Zengjia1) {
new Kehutianjia(table1);
}
}
});
// 客户删除事件处理
Shanchu1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Shanchu1) {
int i = 0;
i = table1.getSelectedRow();
if (i < 0) {
JOptionPane.showMessageDialog(null, "请选择表数据后再执行此操作!",
"系统提示", JOptionPane.WARNING_MESSAGE);
} else {
String NO = (String) table1.getValueAt(i, 0);
int n = JOptionPane.showConfirmDialog(null, "确认删除吗?",
"确认删除框", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
String sqlStr = null;
sqlStr = "DELETE FROM jj2 WHERE id='" + NO
+ "'";
new JdbcAdapter().AdapterObject(sqlStr);
table1.setModel(new JdbcAdapter().buildTablekehu());
JOptionPane.showMessageDialog(null, "删除客户信息成功",
"系统提示", JOptionPane.INFORMATION_MESSAGE);
} else {
if (n == JOptionPane.NO_OPTION) {
return;
}
}
}
}
}
});
// 客户修改事件处理
Xiugai1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Xiugai1) {
int i = table1.getSelectedRow();
if (i < 0) {
JOptionPane.showMessageDialog(null, "请选择表数据后再执行此操作!",
"系统提示", JOptionPane.WARNING_MESSAGE);
} else {
new KeHuXiuGai(i, table1);
}
}
}
});
// 客户查找事件处理
Chaxun1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Chaxun1) {
String sql = "SELECT * FROM jj2 WHERE id= '" + ChaxunText.getText() + "'";
con = CommonJdbc.getCon();
table1.setModel(new JdbcAdapter().buildTablekehu(sql));
table1(table1);
}
}
});
// 汽车增加事件处理
Zengjia2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Zengjia2) {
new CheliangZengJia(table2);
}
}
});
// 汽车删除事件处理
Shanchu2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Shanchu2) {
int i = 0;
i = table2.getSelectedRow();
if (i < 0) {
JOptionPane.showMessageDialog(null, "请选择表数据后再执行此操作!",
"系统提示", JOptionPane.WARNING_MESSAGE);
} else {
String NO = (String) table2.getValueAt(i, 0);
int n = JOptionPane.showConfirmDialog(null, "确认删除吗?",
"确认删除框", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
String sqlStr = null;
sqlStr = "DELETE FROM jj3 WHERE id='" + NO
+ "'";
new JdbcAdapter().AdapterObject(sqlStr);
table2.setModel(new JdbcAdapter().buildTablecheliang());
JOptionPane.showMessageDialog(null, "删除汽车信息成功",
"系统提示", JOptionPane.INFORMATION_MESSAGE);
} else {
if (n == JOptionPane.NO_OPTION) {
return;
}
}
}
}
}
});
// 汽车修改事件处理
Xiugai2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Xiugai2) {
int i = table2.getSelectedRow();
if (i < 0) {
JOptionPane.showMessageDialog(null, "请选择表数据后再执行此操作!",
"系统提示", JOptionPane.WARNING_MESSAGE);
} else {
new CheliangXiuGai(i, table2);
}
}
}
});
// 汽车查找事件处理
Chaxun2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Chaxun2) {
String sql = "SELECT * FROM jj3 WHERE id= '" + ChaxunText2.getText() + "'";
con = CommonJdbc.getCon();
table2.setModel(new JdbcAdapter().buildTablecheliang(sql));
table2(table2);
}
}
});
// 管理员增加事件处理
Zengjia3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Zengjia3) {
new Guanliyuantianjia(table3);
}
}
});
// 管理员删除事件处理
Shanchu3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Shanchu3) {
int i = 0;
i = table3.getSelectedRow();
if (i < 0) {
JOptionPane.showMessageDialog(null, "请选择表数据后再执行此操作!",
"系统提示", JOptionPane.WARNING_MESSAGE);
} else {
String NO = (String) table3.getValueAt(i, 0);
int n = JOptionPane.showConfirmDialog(null, "确认删除吗?",
"确认删除框", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
String sqlStr = null;
sqlStr = "DELETE FROM jj4 WHERE id='" + NO
+ "'";
new JdbcAdapter().AdapterObject(sqlStr);
table3.setModel(new JdbcAdapter().buildTableguanliyuan());
JOptionPane.showMessageDialog(null, "删除商品信息成功",
"系统提示", JOptionPane.INFORMATION_MESSAGE);
} else {
if (n == JOptionPane.NO_OPTION) {
return;
}
}
}
}
}
});
// 管理员修改事件处理
Xiugai3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Xiugai3) {
int i = table3.getSelectedRow();
if (i < 0) {
JOptionPane.showMessageDialog(null, "请选择表数据后再执行此操作!",
"系统提示", JOptionPane.WARNING_MESSAGE);
} else {
new CheliangXiuGai(i, table3);
}
}
}
});
// 管理员查找事件处理
Chaxun3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Chaxun3) {
String sql = "SELECT * FROM jj4 WHERE id= '" + ChaxunText3.getText() + "'";
con = CommonJdbc.getCon();
table3.setModel(new JdbcAdapter().buildTableguanliyuan(sql));
table3(table3);
}
}
});
// 系统退出
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
pan1.add(scr1);
pan2.add(scr2);
pan3.add(scr3);
cont.add(tab);
tab.setBounds(0, 0, 80, 700);
frame.setSize(980, 700);
frame.setLocation(200, 30);
frame.setVisible(true);
frame.setResizable(false); // 禁止改变窗体大小
}
// 客户资料表格
public void table1(JTable table1) {
table1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumnModel cm = table1.getColumnModel(); // 表格的列模型
TableColumn column = cm.getColumn(0); // 得到第i个列对象
TableColumn column1 = cm.getColumn(1);
TableColumn column2 = cm.getColumn(2);
TableColumn column3 = cm.getColumn(3);
TableColumn column4 = cm.getColumn(4);
TableColumn column5 = cm.getColumn(5);
column.setPreferredWidth(80); // 将此列的首选宽度设置为 preferredWidth。如果
// preferredWidth
// 超出最小或最大宽度,则将其调整为合适的界限值。
column1.setPreferredWidth(100);
column2.setPreferredWidth(150);
column3.setPreferredWidth(150);
column4.setPreferredWidth(150);
column5.setPreferredWidth(100);
table1.getTableHeader().setReorderingAllowed(false); // 设置表的列不可拖动
}
// 汽车信息表格
public void table2(JTable table2) {
table2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumnModel cm = table2.getColumnModel(); // 表格的列模型
TableColumn column = cm.getColumn(0); // 得到第i个列对象
TableColumn column1 = cm.getColumn(1);
TableColumn column2 = cm.getColumn(2);
TableColumn column3 = cm.getColumn(3);
TableColumn column4 = cm.getColumn(4);
TableColumn column5 = cm.getColumn(5);
column.setPreferredWidth(80); // 将此列的首选宽度设置为 preferredWidth。如果
// preferredWidth
// 超出最小或最大宽度,则将其调整为合适的界限值。
column1.setPreferredWidth(100);
column2.setPreferredWidth(100);
column3.setPreferredWidth(100);
column4.setPreferredWidth(100);
column5.setPreferredWidth(150);
table2.getTableHeader().setReorderingAllowed(false); // 设置表的列不可拖动
}
// 管理员信息表格
public void table3(JTable table3) {
table3.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumnModel cm = table3.getColumnModel(); // 表格的列模型
TableColumn column = cm.getColumn(0); // 得到第i个列对象
TableColumn column1 = cm.getColumn(1);
TableColumn column2 = cm.getColumn(2);
TableColumn column3 = cm.getColumn(3);
TableColumn column4 = cm.getColumn(4);
TableColumn column5 = cm.getColumn(5);
column.setPreferredWidth(80); // 将此列的首选宽度设置为 preferredWidth。如果
// preferredWidth
// 超出最小或最大宽度,则将其调整为合适的界限值。
column1.setPreferredWidth(100);
column2.setPreferredWidth(100);
column3.setPreferredWidth(100);
column4.setPreferredWidth(100);
column5.setPreferredWidth(100);
table3.getTableHeader().setReorderingAllowed(false); // 设置表的列不可拖动
}
// 设置Timer 1000ms实现一次动作 实际是一个线程 自动获取系统事件
private void setTimer(JTextField time) {
final JTextField varTime = time;
Timer timeAction = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
long timemillis = System.currentTimeMillis();
// 转换日期显示格式
SimpleDateFormat df = new SimpleDateFormat(
" yyyy-MM-dd HH:mm:ss ");
varTime.setText(df.format(new Date(timemillis)));
}
});
timeAction.start();
}
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
new zhuchuangti();
}
}