基于java+mysql的swing+mysql进销存系统(java+gui)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java+mysql的Swing+MySQL进销存系统(java+gui)
功能介绍:
基本信息管理、库存管理、销售管理、订单管理、日志管理、供应商基本信息、员工基本信息、商品信息、入库管理、出库管理、剩余库存
System.out.println(sql_e);
}
}
}
}
});
button_2.setBounds(83, 338, 106, 27);
add(button_2);
JButton btnNewButton_2 = new JButton("\u67E5\u8BE2");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(panel2.isVisible()==false)panel2.setVisible(true);
else panel2.setVisible(false);
panel1.setVisible(false);
panel.setVisible(false);
}
});
btnNewButton_2.setBounds(487, 338, 106, 27);
add(btnNewButton_2);
JButton btnNewButton_1 = new JButton("\u786E\u5B9A");//确定查询
btnNewButton_1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String a=search_textField1.getText();
String b=search_textField2.getText();
if(a.equals(""))a="any(select lei from goods)";
else a="'"+a+"'";
if(b.equals(""))b="any(select name from goods)";
else b="'"+b+"'";
table.removeAll();
tableValueV.removeAllElements();
try {//插入
Connection con = DriverManager.getConnection(conURL, StartApplication.mysqlname, StartApplication.mysqlpassword); // 连接数据库
Statement s = con.createStatement(); // Statement类用来提交SQL语句
String select="select * from goods where lei="+a+" and name ="+b;
ResultSet rs = s.executeQuery(select); // 提交查询,返回的表格保存在rs中
while(rs.next()) { // ResultSet指针指向下一个“行”
Vector<String> rowV = new Vector<String>();
rowV.add(rs.getString("lei"));
rowV.add(rs.getString("name"));
});
button_2.addMouseListener(new Buttonmouse(button_2));
if(Login.limite.getSelectedItem().equals("管理员"))toolBar.add(button_2);
JButton button_3 = new JButton("\u8BA2\u5355\u7BA1\u7406");
button_3.setBackground(Color.WHITE);
button_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
panel1.setVisible(false);
panel2.setVisible(false);
panel3.setVisible(false);
panel4.setVisible(true);
}
});
button_3.addMouseListener(new Buttonmouse(button_3));
toolBar.add(button_3);
JButton btnNewButton = new JButton("\u65E5\u5FD7");
btnNewButton.setBackground(Color.WHITE);
btnNewButton.addMouseListener(new Buttonmouse(btnNewButton));
toolBar.add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
panel1.setVisible(false);
panel2.setVisible(false);
panel3.setVisible(false);
panel4.setVisible(false);
lblNewLabel_3.setVisible(false);
panel_4.remove(log);
log=new Log();
panel_4.add(log);
log.setVisible(true);
if(Main.message_goods!=null)Main.message_goods.setVisible(false);
if(Main.kucun_chuku!=null)Main.kucun_chuku.setVisible(false);
if(Main.kucun_sykucun!=null)Main.kucun_sykucun.setVisible(false);
if(Main.xiaoshou_day!=null)Main.xiaoshou_day.setVisible(false);
if(Main.xiaoshou_mounth!=null)Main.xiaoshou_mounth.setVisible(false);
if(Main.xiaoshou_lirun!=null)Main.xiaoshou_lirun.setVisible(false);
if(Main.xiaoshou_num!=null)Main.xiaoshou_num.setVisible(false);
if(Main.dingdan_ruku!=null)Main.dingdan_ruku.setVisible(false);
if(Main.dingdan_chuku!=null)Main.dingdan_chuku.setVisible(false);
if(Main.message_sponsor!=null)Main.message_sponsor.setVisible(false);
if(Main.dingdan_chaxun!=null)Main.dingdan_chaxun.setVisible(false);
if(Main.message_employee!=null)Main.message_employee.setVisible(false);
}
});
if(mounth.charAt(0)=='0')mounth=mounth.substring(1, 2);
dataset.addValue(Integer.parseInt(rs.getString("money")), "销售额", mounth);
System.out.println(rs.getString("time")+"haha");
}
s.close(); // 释放Statement对象
con.close(); // 关闭到MySQL服务器的连接
}
catch(SQLException sql_e) { // 都是SQLException
System.out.println("xiaoshoumounth"+sql_e);
}
// 添加数据
JFreeChart chart = ChartFactory.createLineChart("食品公司年销售额", // 主标题的名称
"",// X轴的标签
"金额",// Y轴的标签
dataset, // 图标显示的数据集合
PlotOrientation.VERTICAL, // 图像的显示形式(水平或者垂直)
true,// 是否显示子标题
true,// 是否生成提示的标签
false); // 是否生成URL链接
// 处理图形上的乱码
// 处理主标题的乱码
chart.getTitle().setFont(new Font("宋体", Font.BOLD, 18));
// 处理子标题乱码
chart.getLegend().setItemFont(new Font("宋体", Font.BOLD, 15));
// 获取图表区域对象
CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
// 获取X轴的对象
CategoryAxis categoryAxis = (CategoryAxis) categoryPlot.getDomainAxis();
// 获取Y轴的对象
NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
// 处理X轴上的乱码
categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 15));
// 处理X轴外的乱码
categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 15));
// 处理Y轴上的乱码
numberAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 15));
// 处理Y轴外的乱码
gbc_jingshouren.gridy = 1;
panel.add(jingshouren, gbc_jingshouren);
jingshouren.setColumns(10);
JLabel label_2 = new JLabel("\u64CD\u4F5C\u5458\uFF1A");
GridBagConstraints gbc_label_2 = new GridBagConstraints();
gbc_label_2.anchor = GridBagConstraints.EAST;
gbc_label_2.insets = new Insets(0, 0, 5, 5);
gbc_label_2.gridx = 3;
gbc_label_2.gridy = 1;
panel.add(label_2, gbc_label_2);
operator = new JTextField();
GridBagConstraints gbc_operator = new GridBagConstraints();
gbc_operator.insets = new Insets(0, 0, 5, 5);
gbc_operator.fill = GridBagConstraints.HORIZONTAL;
gbc_operator.gridx = 4;
gbc_operator.gridy = 1;
panel.add(operator, gbc_operator);
operator.setColumns(10);
operator.setText(Testmysql.Name);
JButton button = new JButton("\u786E\u5B9A");//确定
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
chukudanhao.setEditable(false);
time.setEditable(false);
jingshouren.setEditable(false);
operator.setEditable(false);
}
});
GridBagConstraints gbc_button = new GridBagConstraints();
gbc_button.anchor = GridBagConstraints.EAST;
gbc_button.insets = new Insets(0, 0, 0, 5);
gbc_button.gridx = 1;
gbc_button.gridy = 2;
panel.add(button, gbc_button);
JButton btnNewButton = new JButton("\u91CD\u7F6E");
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
gbc_btnNewButton.gridx = 3;
gbc_btnNewButton.gridy = 2;
panel.add(btnNewButton, gbc_btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
ResultSet rs = s.executeQuery("select * from sponsor"); // 提交查询,返回的表格保存在rs中
while(rs.next()) { // ResultSet指针指向下一个“行”
Vector<String> rowV = new Vector<String>();
rowV.add(rs.getString("lei"));
rowV.add(rs.getString("name"));
rowV.add(rs.getString("tel"));
tableValueV.add(rowV);
System.out.println(rs.getString("lei"));
}
tableModel.setDataVector(tableValueV,columnNameV);
int rowCount = table.getRowCount();
table.getSelectionModel().setSelectionInterval(rowCount-1 , rowCount- 1 );
Rectangle rect = table.getCellRect(rowCount-1 , 0 , true );
table.scrollRectToVisible(rect);
s.close(); // 释放Statement对象
con.close(); // 关闭到MySQL服务器的连接
TableColumnModel cm = table.getColumnModel();
TableColumn column = cm.getColumn(0);//得到第i个列对象
column.setPreferredWidth(140);//将此列的首选宽度设置为 preferredWidth。
TableColumn column1 = cm.getColumn(1);//得到第i个列对象
column1.setPreferredWidth(140);//将此列的首选宽度设置为 preferredWidth。
TableColumn column2 = cm.getColumn(2);
column2.setPreferredWidth(140);
}
catch(SQLException sql_e) { // 都是SQLExceptionss
System.out.println(sql_e);
}
}
});
panel2.add(canel);
}
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
int selectedRow = table.getSelectedRow();//获得选中行的索引
if(selectedRow!= -1) //是否存在选中行
{
Object oa = tableModel.getValueAt(selectedRow, 0);
Object ob = tableModel.getValueAt(selectedRow, 1);
Object oc =tableModel.getValueAt(selectedRow, 2);
textField1.setText(oa.toString()); //给文本框赋值
textField2.setText(ob.toString());
textField3.setText(oc.toString());
}
else{
textField1.setText(""); //给文本框赋值
textField2.setText("");
textField3.setText("");
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public class Message_sponsor extends JPanel {
s2.close(); // 释放Statement对象
}
s.close(); // 释放Statement对象
con.close(); // 关闭到MySQL服务器的连接
}
catch(SQLException sql_e) { // 都是SQLException
System.out.println(sql_e);
}
}
}
}
});
button_2.setBounds(83, 338, 106, 27);
add(button_2);
JButton btnNewButton_2 = new JButton("\u67E5\u8BE2");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(panel2.isVisible()==false)panel2.setVisible(true);
else panel2.setVisible(false);
panel1.setVisible(false);
panel.setVisible(false);
}
});
btnNewButton_2.setBounds(487, 338, 106, 27);
add(btnNewButton_2);
JButton btnNewButton_1 = new JButton("\u786E\u5B9A");//确定查询
btnNewButton_1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String a=search_textField1.getText();
String b=search_textField2.getText();
if(a.equals(""))a="any(select lei from goods)";
else a="'"+a+"'";
if(b.equals(""))b="any(select name from goods)";
else b="'"+b+"'";
table.removeAll();
tableValueV.removeAllElements();
try {//插入
Connection con = DriverManager.getConnection(conURL, StartApplication.mysqlname, StartApplication.mysqlpassword); // 连接数据库
try {//插入
Connection con = DriverManager.getConnection(conURL, StartApplication.mysqlname, StartApplication.mysqlpassword); // 连接数据库
Statement s = con.createStatement(); // Statement类用来提交SQL语句
String insert = "insert into employee(name,position,sex,born,tel,school,time,addr) values('"+a+"','"+b+"','"+c+"','"+d+"','"+e+"','"+f+"','"+g+"','"+h+"')";
s.executeUpdate(insert);
Vector<String> rowV = new Vector<String>();
rowV.add(a);
rowV.add(b);
rowV.add(c);
rowV.add(d);
rowV.add(e);
rowV.add(f);
rowV.add(g);
rowV.add(h);
tableValueV.add(rowV);
tableModel.setDataVector(tableValueV,columnNameV);
int rowCount = table.getRowCount();
table.getSelectionModel().setSelectionInterval(rowCount-1 , rowCount- 1 );
Rectangle rect = table.getCellRect(rowCount-1 , 0 , true );
table.scrollRectToVisible(rect);
TableColumnModel cm = table.getColumnModel();
for(int i=0;i<8;i++){
TableColumn column = cm.getColumn(i);//得到第i个列对象
column.setPreferredWidth(61);//将此列的首选宽度设置为 preferredWidth。
}
Statement s2 = con.createStatement(); // Statement类用来提交SQL语句
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
//System.out.println("insert into news(time,news,limit) values('"+df.format(new Date())+"','"+Name+"登入系统"+"','"+limite+"')");
String insert1 = "insert into news(time,news,limite) values('"+df.format(new Date())+"','"+Testmysql.limite+Testmysql.Name+"添加员工"+a+"成功"+"','"+Testmysql.limite+"')";
s2.executeUpdate(insert1);
s2.close(); // 释放Statement对象
s.close(); // 释放Statement对象
con.close(); // 关闭到MySQL服务器的连接
}
catch(SQLException sql_e) { // 都是SQLExceptionss
System.out.println(sql_e);
}
}
});
add_button.setBounds(226, 140, 93, 28);
panel.add(add_button);
gbc_rukudanhao.gridy = 0;
panel.add(rukudanhao, gbc_rukudanhao);
rukudanhao.setColumns(10);
JLabel label_1 = new JLabel("\u5165\u5E93\u65E5\u671F\uFF1A");
GridBagConstraints gbc_label_1 = new GridBagConstraints();
gbc_label_1.anchor = GridBagConstraints.EAST;
gbc_label_1.insets = new Insets(0, 0, 5, 5);
gbc_label_1.gridx = 3;
gbc_label_1.gridy = 0;
panel.add(label_1, gbc_label_1);
rukutime = new JTextField();
GridBagConstraints gbc_rukutime = new GridBagConstraints();
gbc_rukutime.insets = new Insets(0, 0, 5, 5);
gbc_rukutime.fill = GridBagConstraints.HORIZONTAL;
gbc_rukutime.gridx = 4;
gbc_rukutime.gridy = 0;
panel.add(rukutime, gbc_rukutime);
rukutime.setColumns(10);
rukutime.setText(df.format(new Date()));
//textField_1.setEditable(false);
JLabel lblNewLabel = new JLabel("\u91C7\u8D2D\u8BA2\u5355\u53F7\uFF1A");
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
gbc_lblNewLabel.gridx = 6;
gbc_lblNewLabel.gridy = 0;
panel.add(lblNewLabel, gbc_lblNewLabel);
caigouhao = new JTextField();
GridBagConstraints gbc_caigouhao = new GridBagConstraints();
gbc_caigouhao.insets = new Insets(0, 0, 5, 0);
gbc_caigouhao.fill = GridBagConstraints.HORIZONTAL;
gbc_caigouhao.gridx = 7;
gbc_caigouhao.gridy = 0;
panel.add(caigouhao, gbc_caigouhao);
caigouhao.setColumns(10);
label_1.setFont(new Font("宋体", Font.PLAIN, 15));
label_1.setBounds(19, 30, 80, 15);
panel2.add(label_1);
JLabel label_3 = new JLabel("\u5546\u54C1\u540D\u79F0\uFF1A");
label_3.setFont(new Font("宋体", Font.PLAIN, 15));
label_3.setBounds(19, 52, 80, 30);
panel2.add(label_3);
table = new JTable();
table.setBounds(0, 0, 438, 250);
JScrollPane scrollPane1=new JScrollPane();
String[] columnNames = { "商品类型","商品名称" };
columnNameV = new Vector<String>();
for (int column = 0; column < columnNames.length; column++) {
columnNameV.add(columnNames[column]);
}
HashSet set1=new HashSet();
tableValueV = new Vector<Vector<String>>();
try {
Connection con = DriverManager.getConnection(conURL, StartApplication.mysqlname, StartApplication.mysqlpassword); // 连接数据库
Statement s = con.createStatement(); // Statement类用来提交SQL语句
ResultSet rs = s.executeQuery("select * from goods;"); // 提交查询,返回的表格保存在rs中
while(rs.next()) { // ResultSet指针指向下一个“行”
if(set1.contains(rs.getString("lei")+rs.getString("name"))==false){
Vector<String> rowV = new Vector<String>();
rowV.add(rs.getString("lei"));
rowV.add(rs.getString("name"));
tableValueV.add(rowV);
set1.add(rs.getString("lei")+rs.getString("name"));
}
}
s.close(); // 释放Statement对象
con.close(); // 关闭到MySQL服务器的连接
}
catch(SQLException sql_e) { // 都是SQLExceptionss
System.out.println(sql_e);
}
JComboBox comboBox_1 = new JComboBox();
rowV.add(rs.getString("lei"));
rowV.add(rs.getString("name"));
rowV.add(rs.getString("jingshouren"));
rowV.add(rs.getString("operator"));
rowV.add(rs.getString("time"));
rowV.add(rs.getString("price"));
rowV.add(rs.getString("num"));
tableValueV.add(rowV);
System.out.println("yes");
}
s.close(); // 释放Statement对象
con.close(); // 关闭到MySQL服务器的连接
}
catch(SQLException sql_e) { // 都是SQLExceptionss
System.out.println(sql_e);
}
tableModel.setDataVector(tableValueV,columnNameV);
int rowCount = table.getRowCount();
table.getSelectionModel().setSelectionInterval(rowCount-1 , rowCount- 1 );
Rectangle rect = table.getCellRect(rowCount-1 , 0 , true );
table.scrollRectToVisible(rect);
TableColumnModel cm = table.getColumnModel();
for(int i=0;i<8;i++){
TableColumn column = cm.getColumn(i);//得到第i个列对象
column.setPreferredWidth(67);//将此列的首选宽度设置为 preferredWidth。
}
}
}
panel1.add(modify_sex);
modify_sex.setColumns(10);
JLabel modify_label_2 = new JLabel("\u8054\u7CFB\u65B9\u5F0F\uFF1A");
modify_label_2.setFont(new Font("宋体", Font.PLAIN, 15));
modify_label_2.setBounds(203, 63, 79, 23);
panel1.add(modify_label_2);
modify_tel = new JTextField();
modify_tel.setBounds(271, 64, 112, 21);
panel1.add(modify_tel);
modify_tel.setColumns(10);
JLabel modify_lblNewLabel_4 = new JLabel("\u5B66\u5386\uFF1A");
modify_lblNewLabel_4.setFont(new Font("宋体", Font.PLAIN, 15));
modify_lblNewLabel_4.setBounds(400, 64, 54, 21);
panel1.add(modify_lblNewLabel_4);
modify_school = new JTextField();
modify_school.setBounds(451, 64, 93, 21);
panel1.add(modify_school);
modify_school.setColumns(10);
JLabel modify_label_6 = new JLabel("\u5165\u804C\u65F6\u95F4\uFF1A");
modify_label_6.setFont(new Font("宋体", Font.PLAIN, 15));
modify_label_6.setBounds(19, 102, 82, 26);
panel1.add(modify_label_6);
modify_time = new JTextField();
modify_time.setBounds(100, 102, 93, 21);
panel1.add(modify_time);
modify_time.setColumns(10);
JLabel search_label = new JLabel("\u59D3\u540D\uFF1A");
search_label.setFont(new Font("宋体", Font.PLAIN, 15));
search_label.setBounds(19, 24, 71, 21);
panel2.add(search_label);
search_name = new JTextField();
search_name.setBounds(100, 24, 93, 21);
panel2.add(search_name);
search_name.setColumns(10);
JLabel search_label_1 = new JLabel("\u5BB6\u5EAD\u4F4F\u5740\uFF1A");
search_label_1.setFont(new Font("宋体", Font.PLAIN, 15));
search_label_1.setBounds(203, 100, 82, 30);
public class Kucun_ruku extends JFrame {
});
button_1.setFont(new Font("宋体", Font.PLAIN, 15));
button_1.setBounds(197, 321, 106, 27);
add(button_1);
JButton button = new JButton("\u786E\u5B9A");//添加
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String a=(String) add_comboBox.getSelectedItem(),b=add_textField.getText(),c=add_textField_1.getText();
//txtOut.append(a+" "+b+"\n");
if(set1.contains(a+b+c)==false){
set1.add(a+b+c);
try {//插入
Connection con = DriverManager.getConnection(conURL, StartApplication.mysqlname, StartApplication.mysqlpassword); // 连接数据库
Statement s = con.createStatement(); // Statement类用来提交SQL语句
String insert = "insert into sponsor(lei,name,tel) values('"+a+"','"+b+"','"+c+"')";
s.executeUpdate(insert);
Vector<String> rowV = new Vector<String>();
rowV.add(a);
rowV.add(b);
rowV.add(c);
tableValueV.add(rowV);
tableModel.setDataVector(tableValueV,columnNameV);
int rowCount = table.getRowCount();
table.getSelectionModel().setSelectionInterval(rowCount-1 , rowCount- 1 );
Rectangle rect = table.getCellRect(rowCount-1 , 0 , true );
table.scrollRectToVisible(rect);
s.close(); // 释放Statement对象
// 关闭到MySQL服务器的连接
TableColumnModel cm = table.getColumnModel();
TableColumn column = cm.getColumn(0);//得到第i个列对象
column.setPreferredWidth(140);//将此列的首选宽度设置为 preferredWidth。
TableColumn column1 = cm.getColumn(1);//得到第i个列对象
column1.setPreferredWidth(140);//将此列的首选宽度设置为 preferredWidth。
TableColumn column2 = cm.getColumn(2);
column2.setPreferredWidth(140);
Statement s2 = con.createStatement(); // Statement类用来提交SQL语句
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
//System.out.println("insert into news(time,news,limit) values('"+df.format(new Date())+"','"+Name+"登入系统"+"','"+limite+"')");
String insert1 = "insert into news(time,news,limite) values('"+df.format(new Date())+"','"+Testmysql.limite+Testmysql.Name+"添加供应商"+a+":"+b+"成功"+"','"+Testmysql.limite+"')";
s2.executeUpdate(insert1);
s2.close(); // 释放Statement对象
con.close();
}
catch(SQLException sql_e) { // 都是SQLExceptionss
System.out.println(sql_e);
}
}
label_1.setFont(new Font("宋体", Font.PLAIN, 15));
fangshi = new JComboBox();
fangshi.setBounds(108, 104, 129, 21);
panel.add(fangshi);
fangshi.setModel(new DefaultComboBoxModel(new String[] {"\u7CBE\u786E\u67E5\u8BE2", "\u6A21\u7CCA\u67E5\u8BE2"}));
JLabel label_2 = new JLabel("\u503C\uFF1A");
label_2.setBounds(44, 135, 54, 18);
panel.add(label_2);
label_2.setFont(new Font("宋体", Font.PLAIN, 15));
message = new JTextField();
message.setBounds(108, 134, 129, 21);
panel.add(message);
message.setColumns(10);
JButton button = new JButton("\u786E\u5B9A");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
getmessage();
repaint();
}
});
button.setBounds(264, 72, 93, 39);
panel.add(button);
JScrollPane scrollPane1=new JScrollPane();
String[] columnNames = {"订单号" ,"商品类型","商品名称","经手人","操作员","时间","价格","数量" };
columnNameV = new Vector<String>();
for (int column = 0; column < columnNames.length; column++) {
columnNameV.add(columnNames[column]);
}
tableValueV = new Vector<Vector<String>>();
tableModel = new DefaultTableModel(tableValueV,
columnNameV);
table = new JTable(tableModel);
table.setRowSorter(new TableRowSorter<DefaultTableModel>(tableModel));
scrollPane1.setViewportView(table);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
TableColumnModel tableColumnModel = table.getColumnModel();
ListSelectionModel listSelectionModel = tableColumnModel
.getSelectionModel();
JButton button_2 = new JButton("\u5220\u9664");//删除
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object [] options ={"确定","取消"};
int flag=JOptionPane.showOptionDialog(StartApplication.zhu, "确定删除该供应商信息?","删除",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
if(flag==0){
int selectedRow = table.getSelectedRow();//获得选中行的索引
int rowcount=table.getRowCount();
if(selectedRow!=-1&&!set1.isEmpty()&&selectedRow!=rowcount) //存在选中行
{
Object oa = tableModel.getValueAt(selectedRow, 0);
Object ob = tableModel.getValueAt(selectedRow, 1);
set1.remove(oa.toString()+ob.toString());
tableModel.removeRow(selectedRow); //删除行
table.getSelectionModel().setSelectionInterval(selectedRow , selectedRow );
Rectangle rect = table.getCellRect(selectedRow , 0 , true );
table.scrollRectToVisible(rect);
try {
Connection con = DriverManager.getConnection(conURL, StartApplication.mysqlname, StartApplication.mysqlpassword); // 连接数据库
Statement s = con.createStatement(); // Statement类用来提交
String delete = "Delete From goods Where lei='"+oa.toString()+"' and name='"+ob.toString()+"'";
s.executeUpdate(delete);
ResultSet rs = s.executeQuery("select * from goods;"); // 提交查询,返回的表格保存在rs中
boolean flag1=false;
while(rs.next()) { // ResultSet指针指向下一个“行”
if(rs.getString("lei").equals(oa.toString())) {flag1=true;break;}
}
if(!flag1){
Main.leiset.remove(oa.toString());
String delete1 = "Delete From fenlei Where lei='"+oa.toString()+"'";
s.executeUpdate(delete1);
comboBox.removeItem(oa.toString());
Statement s2 = con.createStatement(); // Statement类用来提交SQL语句
public class Xiaoshou_day extends JPanel {
int day;
int mounth;
int year;
ChartPanel panel;
String now;