数据库课程设计:图书信息管理系统(Java+MySQL)(附程序)

数据库课程设计:图书信息管理系统(Java+MySQL)(附程序),第1张

期末数据库课程设计做了个图书信息管理系统,由于老师给的选题给得早,所以我在开学后的几周就开学搞了,删删改改整了好多,在此整理分享一下:

项目简介:

        随着社会的发展,人们对知识的需求也在不断增长。书籍作为人们获取并增长知识的只要途径,使得书城,书店在人们的生活中占有了一定的位置。但是近几年,随着书量的不断增长,造成了图书挤压,管理不善等等的问题。这就直接影响了图书管理员对书城或者书店图书的管理带来一定的难度。这时就需要开发一套图书管理系统,通过该系统提高书城或者书店的管理效率,从而减少管理方面的工作流程和成本。

        本次课程设计旨在加深对数据库系统,软件工程,程序设计语言的理论知识的理解和应用水平,同时在理论和实验教学基础上进一步巩固已学基本理论及应用知识并加以综合提高,并学会将知识应用于实际的方法,提高分析和解决问题的能力,增强动手能力,为毕业设计和以后工作打下必要的基础。

需求分析:

        当今图书作为一种信息资源已经相当丰富,面对庞大的书籍,特别是书城,书店一类的买卖平台,图书和用户购买资料繁多,包含很多的信息管理。图书管理系统是一个高度集成的图书信息管理系统,通过对图书管理的各种功能进行整合,从而达到可以方便进行信息检索,提高效率,降低管理成本等目的。图书信息管理系统的使用对象图书管理员,主要包含以下的功能:

图书管理员可以在对图书信息进行增加,删除,修改,查询等操作。系统有自动结算的功能,输入图书ISBN码,自动回填相关信息,包含价格,折扣等等,输入金额,自动计算找零。图书管理员可以在系统中设置图书的今日折扣信息,以及标价标准。图书查询,订单查询等等支持根据ISBN码,书名,模糊查询等多种方式。......................

用例图如下:

 系统总体功能图:

 数据库逻辑结构:

Manager(管理员信息表)

New_book_in(进书信息表)

Book_stack(库存信息表)

book_out(书籍销售表)

 参考程序:

Manager.java

package model;

public class Manager {
	private String userString;
	private String pswString;
	public String getUserString() {
		return userString;
	}
	public void setUserString(String userString) {
		this.userString = userString;
	}
	public String getPswString() {
		return pswString;
	}
	public void setPswString(String pswString) {
		this.pswString = pswString;
	}
	public Manager(String userString, String pswString) {
		super();
		this.userString = userString;
		this.pswString = pswString;
	}
	public Manager() {
		// TODO Auto-generated constructor stub
	}
	@Override
	public String toString() {
		return "Manager [userString=" + userString + ", pswString=" + pswString + "]";
	}

}

JDBC封装ConnectionManager.java

package jdbc;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.sql.*;
/**
 * 简述:
 *数据库管理类
 * @author:LiYansheng
 * @date:2021/04/26 19:31
 * @version:
 */
public class ConnectionManager {
    /**
     * 连接数据库的四大必需属性
     */
    private static final String driver = "com.mysql.cj.jdbc.Driver";
    private static final String url = "jdbc:mysql://localhost:3306/books?useSSL=false&serverTimezone=Asia/Shanghai";
    private static final String user = "root";
    private static final String psd = "root";
 
    /**
     * 静态块加载驱动
     */
    static {
        try {
            Class.forName(driver);
            System.out.println("加载驱动成功!");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("加载驱动失败!");
        }
    }
    /**
     * 返回一个连接对象
     * @return
     */
    public static Connection getConnection() {
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url, user, psd);
//            System.out.println("连接数据库ok");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }
    /**
     * 通用查询方法,返回结果集
     * @param sql
     * @param objects
     * @return
     * @throws SQLException
     */
    public static ResultSet query(String sql, Object[] objects) throws SQLException {
        Connection conn = ConnectionManager.getConnection();
        PreparedStatement pst = conn.prepareStatement(sql);
        ResultSet resultSet=null;
//        判断Object是否为空,为空直接执行sql语句
        if (objects == null) {
            resultSet = pst.executeQuery();
        } else {
            for (int i = 0; i < objects.length; i++) {
                pst.setObject(i+1,objects[i]);
            }
            resultSet = pst.executeQuery();
        }
        return resultSet;
    }
    /**
     * 通用增删改方法
     * @param sql
     * @param objects
     * @return
     * @throws SQLException
     */
    public static int Update(String sql,Object[] objects) throws SQLException {
        Connection conn = ConnectionManager.getConnection();
        PreparedStatement pst = conn.prepareStatement(sql);
//      判断数组是否为空
        try {
            if (objects == null || objects.equals("")) {
                return pst.executeUpdate();
            } else {
                for (int i = 0; i < objects.length; i++) {
                    pst.setObject(i + 1, objects[i]);
                }
                return pst.executeUpdate();
            }
        } finally {
            closeall(conn, pst);
        }
 
    }
    /**
     * 返回结果集的二维数组形式,这个在JavaGUI里创建了表格要调用显示数据库的数据时可以用到
     * @param set
     * @return
     * @throws SQLException
     */
    public static Object[][] getSetArrays(ResultSet set) throws SQLException {
        Object[][] objects;
        
        set.last();
        int rowcount = set.getRow();
        ResultSetMetaData rsm = set.getMetaData();
        int colcount = rsm.getColumnCount();//获取列数
//      创建二维数组
        objects = new Object[rowcount][colcount+1];
        set.first();
        for (int i = 0; i < rowcount; i++) {
            objects[i][0]=i+1;//给每一行的第一列添加序号
            for (int j = 1; j < colcount+1; j++) {
                objects[i][j] = set.getObject(j);
            }
            set.next();
        }
        return objects;
    }
 
    /**
     * 关闭资源
     * @param resultSet
     * @param statement
     * @param connection
     */
    public static void closeAll(ResultSet resultSet, Statement statement, Connection connection) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
 
        try {
            if (connection != null && (!connection.isClosed())) {
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static void closeAll(ResultSet resultSet, PreparedStatement preparedStatement, Connection connection) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if (preparedStatement != null) {
                preparedStatement.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
 
        try {
            if (connection != null && (!connection.isClosed())) {
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static void closeall(Connection c, PreparedStatement p) throws SQLException {
        c.close();
        p.close();
    }
    
//    获取时间
    public static String gettime() {
    	Calendar calendar = Calendar.getInstance();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return simpleDateFormat.format(calendar.getTime());
	}
    
    public static String getday() {
    	Calendar calendar = Calendar.getInstance();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        return simpleDateFormat.format(calendar.getTime());
	}

}
 

 Login.java

package frame;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;

import com.mysql.cj.protocol.Resultset;
import com.mysql.cj.xdevapi.Result;

import jdbc.ConnectionManager;
import model.Manager;

import java.awt.Toolkit;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import java.awt.SystemColor;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

public class Login extends JFrame {

	private JPanel contentPane;
	private JTextField jt_user;
	private JPasswordField jt_psw;
	public static Jrame2 jrame;
	/**
	 * @wbp.nonvisual location=1029,134
	 */
	private final JPanel panel_3 = new JPanel();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setBackground(new Color(224, 255, 255));
		setIconImage(Toolkit.getDefaultToolkit().getImage(Login.class.getResource("/img/线性图书 (1).png")));
		setTitle("图书信息管理系统v4.0by计算机181李延胜");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 610, 377);
		contentPane = new JPanel();
		contentPane.setBackground(SystemColor.menu);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBackground(SystemColor.menu);
		panel.setBounds(10, 25, 576, 81);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Welcome to use the System!");
		lblNewLabel.setIcon(new ImageIcon(Login.class.getResource("/img/welcome.png")));
		lblNewLabel.setBounds(73, 25, 435, 34);
		lblNewLabel.setForeground(new Color(0, 0, 0));
		lblNewLabel.setFont(new Font("宋体", Font.BOLD, 29));
		panel.add(lblNewLabel);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(SystemColor.menu);
		panel_1.setBounds(10, 116, 576, 60);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblNewLabel_1 = new JLabel("账号:");
		lblNewLabel_1.setBounds(96, 5, 98, 32);
		lblNewLabel_1.setIcon(new ImageIcon(Login.class.getResource("/img/账号 (1).png")));
		lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 20));
		panel_1.add(lblNewLabel_1);
		
		jt_user = new JTextField();
		jt_user.setBounds(199, 6, 281, 30);
		jt_user.setFont(new Font("宋体", Font.BOLD, 20));
		panel_1.add(jt_user);
		jt_user.setColumns(25);
		
		JLabel mess1 = new JLabel("");
		mess1.setFont(new Font("宋体", Font.PLAIN, 14));
		mess1.setForeground(Color.RED);
		mess1.setBounds(199, 38, 125, 24);
		panel_1.add(mess1);
		
		JPanel panel_1_1 = new JPanel();
		panel_1_1.setBackground(SystemColor.menu);
		panel_1_1.setBounds(10, 186, 576, 60);
		contentPane.add(panel_1_1);
		panel_1_1.setLayout(null);
		
		JLabel lblNewLabel_1_1 = new JLabel("密码:");
		lblNewLabel_1_1.setBounds(97, 10, 98, 32);
		lblNewLabel_1_1.setIcon(new ImageIcon(Login.class.getResource("/img/密码 (7).png")));
		lblNewLabel_1_1.setFont(new Font("宋体", Font.BOLD, 20));
		panel_1_1.add(lblNewLabel_1_1);
		
		jt_psw = new JPasswordField();
		jt_psw.setBounds(201, 5, 280, 32);
		jt_psw.setFont(new Font("宋体", Font.BOLD, 15));
		jt_psw.setColumns(25);
		panel_1_1.add(jt_psw);
		
		JLabel mess2 = new JLabel("");
		mess2.setForeground(Color.RED);
		mess2.setFont(new Font("宋体", Font.PLAIN, 14));
		mess2.setBounds(201, 36, 125, 24);
		panel_1_1.add(mess2);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBackground(SystemColor.menu);
		panel_2.setBounds(10, 270, 576, 60);
		contentPane.add(panel_2);
		panel_2.setLayout(null);
		
		JButton jb_reset = new JButton("重置");
		jb_reset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				重置输入框
				jt_user.setText("");
				jt_psw.setText("");
			}
		});
		jb_reset.setIcon(new ImageIcon(Login.class.getResource("/img/重置.png")));
		jb_reset.setFont(new Font("宋体", Font.BOLD, 17));
		jb_reset.setBounds(113, 10, 97, 23);
		panel_2.add(jb_reset);
		
		JButton jb_login = new JButton("登录");
		jb_login.setIcon(new ImageIcon(Login.class.getResource("/img/登录统计.png")));
		jb_login.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				获取账号和密码
				String userString=jt_user.getText();
				char[] a=jt_psw.getPassword();
				String pswString=String.valueOf(a);
//				查询是否匹配
				String sql="select * from manager where user=?";
				if (jt_user.getText().equals("")) {
					mess1.setText("请输入账号:");
				}else {
					try {
						ResultSet set=ConnectionManager.query(sql, new Object[] {userString});
						if(set.next()) {
//							找到用户
							String user=set.getString("user");
							String psw=set.getString("password");			
							System.out.println(user+psw);
//							判断密码
							if (pswString.equals("")) {
								mess2.setText("请输入密码!");
							}else if (psw.equals(pswString)) {
//								登录成功
								System.out.println("登录成功!");
//								打开新窗口
							    jrame=new Jrame2(new Manager(userString, pswString));
//								关闭当前
								dispose();
								jrame.setVisible(true);
							}else {
								System.out.println("密码输入错误!");
								mess2.setText("密码输入错误!");
							}
						}else {
							System.out.println("账号不存在!");
							mess1.setText("该账号不存在!");
						}
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				
			}
		});
		
//		动态清零
		Document dt=jt_user.getDocument();
		dt.addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				mess1.setText("");
				mess2.setText("");
				
			}
			
			@Override
			public void insertUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				mess1.setText("");
				mess2.setText("");
			}
			
			@Override
			public void changedUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				mess1.setText("");
				mess2.setText("");
			}
		});
		jb_login.setFont(new Font("宋体", Font.BOLD, 17));
		jb_login.setBounds(356, 10, 97, 23);
		panel_2.add(jb_login);
	}
}

 Jrame2.java


package frame;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Color;
import javax.swing.border.TitledBorder;

import jdbc.ConnectionManager;
import model.Manager;

import javax.swing.ImageIcon;
import java.awt.FlowLayout;
import javax.swing.UIManager;
import java.awt.Toolkit;
import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;

public class Jrame2 extends JFrame {
	
//	当前用户
	static Manager manager;
	private JPanel contentPane;
	CardLayout cardLayout=new CardLayout();
//	标价设置
	static double inprice_add=1.0;
//	折扣设置
	static double zhekou=1.00;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Jrame2 frame = new Jrame2(new Manager("test","123"));
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @throws SQLException 
	 */
	public Jrame2(Manager manager) throws SQLException {
		this.manager=manager;
		setIconImage(Toolkit.getDefaultToolkit().getImage("/img/线性图书 (1).png"));
		setFont(new Font("Courier New", Font.BOLD, 21));
		setTitle("图书信息管理系统v4.0-by计181李延胜");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 730, 596);
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setForeground(new Color(51, 51, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		
		JPanel panel = new JPanel();
		panel.setBackground(new Color(255, 255, 255));
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setHgap(15);
		panel.setBounds(5, 5, 710, 60);
		panel.setBorder(new TitledBorder(null, "\u529F\u80FD", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPane.add(panel);
//		内容显示面板,可切换,卡片布局
		
		JPanel main_panel = new JPanel();
		main_panel.setBounds(5, 77, 710, 460);
		contentPane.add(main_panel);
		main_panel.setLayout(new CardLayout(0, 0));
//		给内容面板设置卡片布局
		main_panel.setLayout(cardLayout);
//		添加图书面板
		Books_panel books_panel=new Books_panel();
		main_panel.add(books_panel,"book_panel");
//		添加信息查询面板
		New_find_panel new_find_panel=new New_find_panel();
		main_panel.add(new_find_panel,"New_find_panel");
//		添加图书销售模块
		Book_sele book_sele=new Book_sele();
		main_panel.add(book_sele,"book_sele");
//		添加系统设置面板
		System_setting_panel system_setting_panel=new System_setting_panel();
		main_panel.add(system_setting_panel,"4");
		
		JButton btnNewButton = new JButton("书库管理");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(main_panel, "book_panel");
			}
		});
		btnNewButton.setIcon(new ImageIcon(Jrame2.class.getResource("/img/书 (2).png")));
		btnNewButton.setForeground(new Color(51, 51, 255));
		btnNewButton.setBackground(new Color(175, 238, 238));
		btnNewButton.setFont(new Font("新宋体", Font.BOLD, 16));
		panel.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("信息查询");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(main_panel, "New_find_panel");
			}
			
		});
		btnNewButton_1.setIcon(new ImageIcon(Jrame2.class.getResource("/img/查询 (1).png")));
		btnNewButton_1.setForeground(new Color(51, 51, 255));
		btnNewButton_1.setBackground(new Color(255, 192, 203));
		btnNewButton_1.setFont(new Font("新宋体", Font.BOLD, 16));
		panel.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("图书销售");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(main_panel, "book_sele");
			
			}
		});
		btnNewButton_2.setIcon(new ImageIcon(Jrame2.class.getResource("/img/销售 (1).png")));
		btnNewButton_2.setForeground(new Color(51, 51, 255));
		btnNewButton_2.setBackground(new Color(152, 251, 152));
		btnNewButton_2.setFont(new Font("新宋体", Font.BOLD, 16));
		panel.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("系统设置");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cardLayout.show(main_panel, "4");
			}
		});
		btnNewButton_3.setIcon(new ImageIcon(Jrame2.class.getResource("/img/设置 (1).png")));
		btnNewButton_3.setForeground(new Color(51, 51, 255));
		btnNewButton_3.setBackground(new Color(176, 196, 222));
		btnNewButton_3.setFont(new Font("新宋体", Font.BOLD, 16));
		panel.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("退出系统");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton_4.setIcon(new ImageIcon(Jrame2.class.getResource("/img/退出 (1).png")));
		btnNewButton_4.setForeground(new Color(51, 51, 255));
		btnNewButton_4.setBackground(UIManager.getColor("Button.light"));
		btnNewButton_4.setFont(new Font("新宋体", Font.BOLD, 16));
		panel.add(btnNewButton_4);
		
		JLabel welcome_mess = new JLabel("");
		welcome_mess.setFont(new Font("宋体", Font.BOLD, 15));
		welcome_mess.setBounds(48, 543, 153, 20);
		contentPane.add(welcome_mess);
		welcome_mess.setText("你好!"+manager.getUserString());
		
		JLabel day_mess = new JLabel("");
		String string=ConnectionManager.getday();
		day_mess.setText(string);
		day_mess.setFont(new Font("宋体", Font.BOLD, 15));
		day_mess.setBounds(541, 543, 153, 20);
		contentPane.add(day_mess);
		
	}
}

 Books_panel.java

package frame;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import javax.swing.text.Document;


import com.mysql.cj.protocol.Resultset;


import jdbc.ConnectionManager;


import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Color;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;

public class Books_panel extends JPanel {
	private static JTextField jt_isbn;
	private static JTextField jt_name;
	private static JTextField jt_author;
	private static JTextField jt_inprice;
	private static JTextField jt_num;
	private JTextField textField_5;
	private static JTable table_bookstock;
	private static JTable table_in_book;
	private static JTextField jt_get_all = new JTextField();
	private static JTextField jt_get_sum = new JTextField();
	static JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
	/**
	 * Create the panel:图书信息管理模块,增删改查
	 * 
	 * @throws SQLException
	 */
	public Books_panel() throws SQLException {
		setBackground(new Color(175, 238, 238));
		setBorder(new TitledBorder(null, "\u56FE\u4E66\u7BA1\u7406\u6A21\u5757", TitledBorder.LEADING, TitledBorder.TOP,
				null, null));
		setLayout(null);

//		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(10, 24, 690, 426);
		add(tabbedPane);

		JPanel panel = new JPanel();
		tabbedPane.addTab("图书增删改", new ImageIcon(Books_panel.class.getResource("/img/管理.png")), panel, null);
		panel.setLayout(null);
		JPanel panel_3 = new JPanel();
		panel_3.setLayout(null);
		panel_3.setBounds(10, 72, 665, 44);
		panel.add(panel_3);

		JLabel lblNewLabel_1 = new JLabel("ISBN:");
		lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1.setBounds(68, 6, 91, 28);
		panel_3.add(lblNewLabel_1);

		jt_isbn = new JTextField();

//		动态监听文本款内容

		Document dt = jt_isbn.getDocument();
		dt.addDocumentListener(new DocumentListener() {

			@Override
			public void removeUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				getset();
			}

			@Override
			public void insertUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				getset();
			}

			@Override
			public void changedUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				getset();
			}
		});

		jt_isbn.setFont(new Font("宋体", Font.BOLD, 18));
		jt_isbn.setColumns(25);
		jt_isbn.setBounds(131, 10, 171, 21);
		panel_3.add(jt_isbn);

		JLabel lblNewLabel_1_1 = new JLabel("书名:");
		lblNewLabel_1_1.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1_1.setBounds(352, 6, 75, 28);
		panel_3.add(lblNewLabel_1_1);

		jt_name = new JTextField();
		jt_name.setFont(new Font("宋体", Font.BOLD, 18));
		jt_name.setColumns(25);
		jt_name.setBounds(420, 10, 171, 21);
		panel_3.add(jt_name);

		JPanel panel_3_1 = new JPanel();
		panel_3_1.setLayout(null);
		panel_3_1.setBounds(10, 140, 665, 44);
		panel.add(panel_3_1);

		JLabel lblNewLabel_2 = new JLabel("作者:");
		lblNewLabel_2.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_2.setBounds(70, 6, 89, 28);
		panel_3_1.add(lblNewLabel_2);

		jt_author = new JTextField();
		jt_author.setFont(new Font("宋体", Font.BOLD, 18));
		jt_author.setColumns(25);
		jt_author.setBounds(131, 10, 171, 21);
		panel_3_1.add(jt_author);

		JLabel lblNewLabel_1_1_1 = new JLabel("进价");
		lblNewLabel_1_1_1.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1_1_1.setBounds(352, 6, 75, 28);
		panel_3_1.add(lblNewLabel_1_1_1);

		jt_inprice = new JTextField();
		jt_inprice.setFont(new Font("宋体", Font.BOLD, 18));
		jt_inprice.setColumns(25);
		jt_inprice.setBounds(420, 10, 171, 21);
		panel_3_1.add(jt_inprice);

		JPanel panel_3_2 = new JPanel();
		panel_3_2.setLayout(null);
		panel_3_2.setBounds(10, 208, 665, 44);
		panel.add(panel_3_2);

		JLabel lblNewLabel_3 = new JLabel("数量:");
		lblNewLabel_3.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_3.setBounds(68, 6, 91, 28);
		panel_3_2.add(lblNewLabel_3);
		jt_num = new JTextField();
		jt_num.setFont(new Font("宋体", Font.BOLD, 18));
		jt_num.setColumns(25);
		jt_num.setBounds(131, 10, 171, 21);
		panel_3_2.add(jt_num);

		JLabel lblNewLabel_1_2 = new JLabel("时间:");
		lblNewLabel_1_2.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1_2.setBounds(352, 6, 75, 28);
		panel_3_2.add(lblNewLabel_1_2);
		textField_5 = new JTextField();
		textField_5.setEnabled(false);
		textField_5.setText("自动获取");
		textField_5.setFont(new Font("宋体", Font.BOLD, 19));
		textField_5.setColumns(25);
		textField_5.setBounds(419, 8, 171, 25);
		panel_3_2.add(textField_5);

		JButton btnNewButton = new JButton("重置");
		btnNewButton.setIcon(new ImageIcon(Books_panel.class.getResource("/img/重置.png")));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jt_author.setText("");
				jt_inprice.setText("");
				jt_isbn.setText("");
				jt_name.setText("");
				jt_num.setText("");
			}
		});
		btnNewButton.setFont(new Font("宋体", Font.BOLD, 18));
		btnNewButton.setBounds(31, 312, 113, 30);
		panel.add(btnNewButton);

		JButton btnNewButton_1 = new JButton("添加新书");
		btnNewButton_1.setIcon(new ImageIcon(Books_panel.class.getResource("/img/添加 (3).png")));
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				获取基本信息
				String bookname=jt_name.getText();
				String author=jt_author.getText();
				String price=jt_inprice.getText();
				String num=jt_num.getText();
				String isbn=jt_isbn.getText();
//				获取时间
				String time=ConnectionManager.gettime();
				
//				判断当前要添加的书籍是否存在书库中
				boolean exsit=false;
				int booknum1=0;
				String sqlString="select * from book_stack where ISBN=?";
				try {
					ResultSet set=ConnectionManager.query(sqlString, new Object[] {isbn});
					while (set.next()) {
//						书已经存在
						exsit=true;
						booknum1=set.getInt("num");
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
//				书已经存在
//				更新数量
				if (exsit) {
					int booknum2=booknum1+Integer.parseInt(jt_num.getText());
//					更新表数据
					String sql6="update book_stack set num=? where ISBN=?";
//					String sql7="insert to new_book_in set num=? where ISBN=?";
					try {
						int n=ConnectionManager.Update(sql6, new Object[] {booknum2,isbn});
						if (n>0) {
							System.out.println("图书已存在,更新数量成功!原有"+booknum1+",现有"+booknum2);
						}else {
							System.out.println("更新数量错误!");
						}

						String sql1="insert into new_book_in values(?,?,?,?,?,?,?);";
						try {
							int m=ConnectionManager.Update(sql1, new Object[] {null,isbn,bookname,author,Double.parseDouble(price),Integer.parseInt(num),time});
							if (n>0) {
								JOptionPane.showMessageDialog(null, "添加新书成功!","提示",JOptionPane.INFORMATION_MESSAGE);
								
							}
							
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						update_table_items();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
//					刷新表格数据
					
				}else {
//					插入新书表
					String sql1="insert into new_book_in values(?,?,?,?,?,?,?);";
					try {
						int n=ConnectionManager.Update(sql1, new Object[] {null,isbn,bookname,author,Double.parseDouble(price),Integer.parseInt(num),time});
						if (n>0) {
							JOptionPane.showMessageDialog(null, "添加新书成功!","提示",JOptionPane.INFORMATION_MESSAGE);
							
						}
						
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
//					计算标价
					double markprice=Double.parseDouble(price)*Jrame2.inprice_add;
//					插入库存表
					String sql2="insert into book_stack values(?,?,?,?,?)";
					try {
						int m=ConnectionManager.Update(sql2, new Object[] {isbn,bookname,author,num,markprice});
						if (m>0) {
							System.out.println("插入t2成功!");
						}else {
							System.out.println("插入t2发生错误!");
						}
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					update_table_items();
					
					
				}
//				
//				
			}
		});
		btnNewButton_1.setFont(new Font("宋体", Font.BOLD, 18));
		btnNewButton_1.setBounds(167, 312, 147, 30);
		panel.add(btnNewButton_1);

		JLabel lblNewLabel_4 = new JLabel("请输入相关信息:");
		lblNewLabel_4.setFont(new Font("宋体", Font.BOLD, 21));
		lblNewLabel_4.setBounds(256, 24, 203, 24);
		panel.add(lblNewLabel_4);
		JButton btnNewButton_1_1 = new JButton("删除图书");
		btnNewButton_1_1.setIcon(new ImageIcon(Books_panel.class.getResource("/img/删 除.png")));
		btnNewButton_1_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				根据ISBN码删除图书
				String isbnString = jt_isbn.getText();
				String sql = "delete from new_book_in where ISBN=?";
				String sql1="delete from book_stack where ISBN=?";
				try {
					int n = ConnectionManager.Update(sql, new Object[] { isbnString });
					if (n > 0) {
						JOptionPane.showInternalMessageDialog(null, isbnString + "图书已经删除!", "提示:",
								JOptionPane.INFORMATION_MESSAGE);
					} else {
						JOptionPane.showInternalMessageDialog(null, "操作不成功!", "提示:", JOptionPane.INFORMATION_MESSAGE);

					}
					int m=ConnectionManager.Update(sql1, new Object[] {isbnString});
					if (m>0) {
						System.out.println("从库存中已经删除!");
					}else {
						System.out.println("从库存中删除失败!");
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
//				刷新数据
				update_table_items();


			}
		});
		btnNewButton_1_1.setFont(new Font("宋体", Font.BOLD, 18));
		btnNewButton_1_1.setBounds(504, 312, 138, 30);
		panel.add(btnNewButton_1_1);

		JButton btnNewButton_2 = new JButton("修改图书");
		btnNewButton_2.setIcon(new ImageIcon(Books_panel.class.getResource("/img/修改 (2).png")));
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				获取要修改的信息
				String bookname=jt_name.getText();
				String author=jt_author.getText();
				String in_price=jt_inprice.getText();
				String num=jt_num.getText();
				String isbnString=jt_isbn.getText();
//				保存修改的信息根据
				String sql="UPDATE new_book_in SET bookname=?,author=?,price=?,num=? where ISBN=?";
//				执行
				try {
//					返回结果
					int n=ConnectionManager.Update(sql, new Object[] {bookname,author,in_price,num,isbnString});
					if (n>0) {
						JOptionPane.showMessageDialog(null, "t1图书信息修改成功!","提示",JOptionPane.INFORMATION_MESSAGE);
					}else {
						JOptionPane.showMessageDialog(null, "图书信息修改失败!","提示",JOptionPane.INFORMATION_MESSAGE);
					}
//					
					
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
//				修改库存表
				double markprice=Double.parseDouble(in_price)*Jrame2.inprice_add;//计算标价
				String sqlString="update book_stack set bookname=?,author=?,num=?,markprice=? where ISBN=?";
//				执行
				try {
					int m=ConnectionManager.Update(sqlString, new Object[] {bookname,author,num,markprice,isbnString});
					if (m>0) {
						System.out.println("t2信息修改成功!");
					}else {
						System.out.println("t2修改发生error!");
					}
//					刷新数据
					update_table_items();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			}
		});
		btnNewButton_2.setFont(new Font("宋体", Font.BOLD, 18));
		btnNewButton_2.setBounds(337, 312, 138, 30);
		panel.add(btnNewButton_2);

		JPanel panel_2 = new JPanel();
		tabbedPane.addTab("进书记录", new ImageIcon(Books_panel.class.getResource("/img/买入.png")), panel_2, null);
		panel_2.setLayout(null);

		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(0, 42, 685, 355);
		panel_2.add(scrollPane_1);
		Object[][] objects2 = null;
		Object[] objects = null;
		objects =new Object[] { "序号", "ISBN", "书名", "作者", "进价", "数量", "入库时间" }; String
		sql1 = "SELECT ISBN,bookname,author,price,num,time FROM new_book_in;";
		ResultSet set = ConnectionManager.query(sql1, new Object[] {}); // 计数 int
		int count=0;
		while (set.next()){ 
			count++; 
			}
		jt_get_all.setText(Integer.toString(count)); 
		objects2 =ConnectionManager.getSetArrays(set);
//		初始化
		table_in_book = new JTable(objects2,objects);
		table_in_book.setFont(new Font("宋体", Font.BOLD, 13));
		scrollPane_1.setViewportView(table_in_book);

		JLabel lblNewLabel_5 = new JLabel("总计:");
		lblNewLabel_5.setFont(new Font("宋体", Font.BOLD, 16));
		lblNewLabel_5.setBounds(536, 9, 58, 23);
		panel_2.add(lblNewLabel_5);

		jt_get_all.setEditable(false);
		jt_get_all.setBounds(578, 9, 97, 21);
		panel_2.add(jt_get_all);
		jt_get_all.setColumns(10);

		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("库存记录", new ImageIcon(Books_panel.class.getResource("/img/库存2.png")), panel_1, null);
		panel_1.setLayout(null);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 42, 685, 345);
		panel_1.add(scrollPane);
//		库存记录
		Object[] a = { "序号", "ISBN", "书名", "作者", "数量", "标价" };
		String sql2 = "select * from book_stack";
		ResultSet set1 = ConnectionManager.query(sql2, new Object[] {});
//		计数
		int count1 = 0;
		while (set1.next()) {
			count1++;
		}	
		jt_get_sum.setText(Integer.toString(count1));
		Object[][] objects3 = ConnectionManager.getSetArrays(set1);

		jt_get_sum.setEditable(false);
		jt_get_sum.setColumns(10);
		jt_get_sum.setBounds(578, 10, 97, 21);
		panel_1.add(jt_get_sum);

		table_bookstock = new JTable(objects3, a);
		table_bookstock.setFont(new Font("宋体", Font.BOLD, 13));
		scrollPane.setViewportView(table_bookstock);

		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setBounds(28, 14, 58, 15);
		panel_1.add(lblNewLabel);

		JLabel lblNewLabel_5_1 = new JLabel("总计:");
		lblNewLabel_5_1.setFont(new Font("宋体", Font.BOLD, 16));
		lblNewLabel_5_1.setBounds(536, 10, 58, 23);
		panel_1.add(lblNewLabel_5_1);
	}
	/**
	 * 获取ISBN框内容并查询
	 */
	public static void getset() {
//		获取ISBN框的内容
		String str_isbn = jt_isbn.getText();
//		查询该ISBN是否存在
		String sql = "select * from new_book_in where ISBN=?;";
		try {
			ResultSet set = ConnectionManager.query(sql, new Object[] { str_isbn });
			boolean a=false;
		
			while (set.next()) {
//					不为空,获取部分数据
					String name = set.getString("bookname");
					String author = set.getString("author");
					int num = set.getInt("num");
					double inprice = set.getDouble("price");
					System.out.println(name + author + num + inprice);
					jt_author.setText(author);
					jt_name.setText(name);
					jt_inprice.setText(Double.toString(inprice));
					jt_num.setText(Integer.toString(num));
					a=true;
				
			}
			if (a!=true) {
				jt_author.setText("");
				jt_inprice.setText("");
				jt_name.setText("");
				jt_num.setText("");
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

	}
	
	/**
	 * 刷新库存表格数据
	 */
	public static void UpdateBookStackTable() {
//		刷新库存
		Object[] a = { "序号", "ISBN", "书名", "作者", "数量", "标价" };
		String sql3 = "select * from book_stack";
		ResultSet set1 = null;
		try {
			set1 = ConnectionManager.query(sql3, new Object[] {});
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Object[][] objects3 = null;
		try {
			objects3 = ConnectionManager.getSetArrays(set1);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		TableModel dataModel1 = new DefaultTableModel(objects3,a);
		table_bookstock.setModel(dataModel1);
		System.out.println("库存表格刷新!");
	}
	
	/**
	 * 刷新进书表
	 */
	public static void UpdateNewBookInTable() {
		Object[] objects = { "序号", "ISBN", "书名", "作者", "进价", "数量", "入库时间" };
		String sql2 = "SELECT ISBN,bookname,author,price,num,time FROM new_book_in;";
		ResultSet set = null;
		try {
			set = ConnectionManager.query(sql2, new Object[] {});
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Object[][] objects2 = null;
		try {
			objects2 = ConnectionManager.getSetArrays(set);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
//		刷新新书表表格数据
		TableModel dataModel = new DefaultTableModel(objects2,objects);
		table_in_book.setModel(dataModel);
		System.out.println("进书表格刷新!");
	}
	/**
	 * 统计结果集数目
	 * @throws SQLException 
	 */
	public static int getItems(String sqlString) throws SQLException {
//		查询结果
		int count=0;
		ResultSet set=ConnectionManager.query(sqlString, new Object[] {});
		while (set.next()) {
			count++;
		}
		return count;
	}
	
	/**
	 *刷新表格并且更新统计
	 */
	public static void update_table_items() {
//		刷新新书表记录
		UpdateNewBookInTable();
		try {
			int count1=getItems("select * from new_book_in");
			jt_get_all.setText(Integer.toString(count1));
			System.out.println("统计1更新完毕");
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
//		刷新库存表记录
		UpdateBookStackTable();
		try {
			int count2=getItems("select * from book_stack;");
			jt_get_sum.setText(Integer.toString(count2));
			System.out.println("统计2更新完毕");
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}

 New_find_panel.java

package frame;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import jdbc.ConnectionManager;

import javax.swing.border.EtchedBorder;
import java.awt.Color;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.Font;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;

public class New_find_panel extends JPanel {
	private JTextField jt_text;
	private JTable table;
	private JTextField jt_text2;
	private JTable table_1;
	private JLabel jl_result; 
	private Object[] o1;
	private JLabel jl2;
	private Object[] headrObjects;

	/**
	 * Create the panel.
	 */
	public New_find_panel() {
		setBackground(new Color(255, 192, 203));
		setBorder(new TitledBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u4FE1\u606F\u67E5\u8BE2\u6A21\u5757", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)), "\u4FE1\u606F\u67E5\u8BE2\u6A21\u5757", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(10, 24, 690, 426);
		add(tabbedPane);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("新书查询", new ImageIcon(New_find_panel.class.getResource("/img/查询 (5).png")), panel, null);
		panel.setLayout(null);
		
		JPanel panel_5 = new JPanel();
		panel_5.setLayout(null);
		panel_5.setBounds(0, 25, 685, 371);
		panel.add(panel_5);
		
		JPanel panel_6 = new JPanel();
		panel_6.setBounds(0, 22, 685, 43);
		panel_5.add(panel_6);
		
		jt_text = new JTextField();
		jt_text.setFont(new Font("宋体", Font.BOLD, 20));
		jt_text.setColumns(30);
		panel_6.add(jt_text);
		
		JButton jb_find = new JButton("查询");
		jb_find.setIcon(new ImageIcon(New_find_panel.class.getResource("/img/查询 (3).png")));
		
		jb_find.setFont(new Font("宋体", Font.BOLD, 20));
		panel_6.add(jb_find);
		
		JPanel panel_7 = new JPanel();
		panel_7.setBounds(0, 67, 685, 43);
		panel_5.add(panel_7);
		
		JLabel lblNewLabel_6 = new JLabel("查询方式:");
		lblNewLabel_6.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(lblNewLabel_6);
		
		JRadioButton jrb_isbn = new JRadioButton("ISBN");
		jrb_isbn.setSelected(true);
		jrb_isbn.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(jrb_isbn);
		
		JRadioButton jrb_bookname = new JRadioButton("书名");
		jrb_bookname.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(jrb_bookname);
		
		JRadioButton jrb_intime = new JRadioButton("入库时间");
		jrb_intime.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(jrb_intime);
		
//		按钮组
		ButtonGroup buttonGroup=new ButtonGroup();
		buttonGroup.add(jrb_intime);
		buttonGroup.add(jrb_bookname);
		buttonGroup.add(jrb_isbn);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(0, 148, 685, 249);
		panel_5.add(scrollPane_1);
		
		o1=new Object[] { "序号", "ISBN", "书名", "作者", "进价", "数量", "入库时间" };
		Object[][] o2=new Object[][] {
			
		};
		
		table = new JTable(o2,o1);
		scrollPane_1.setViewportView(table);
		
		JLabel lblNewLabel_7 = new JLabel("查询结果:");
		lblNewLabel_7.setFont(new Font("宋体", Font.PLAIN, 17));
		lblNewLabel_7.setBounds(38, 120, 86, 18);
		panel_5.add(lblNewLabel_7);
		
		jl_result = new JLabel("");
		jl_result.setFont(new Font("宋体", Font.PLAIN, 16));
		jl_result.setForeground(Color.RED);
		jl_result.setBackground(Color.RED);
		jl_result.setBounds(122, 112, 183, 26);
		panel_5.add(jl_result);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("库存查询", new ImageIcon(New_find_panel.class.getResource("/img/查询 (2).png")), panel_1, null);
		panel_1.setLayout(null);
		
		JPanel panel_5_1 = new JPanel();
		panel_5_1.setLayout(null);
		panel_5_1.setBounds(0, 0, 685, 387);
		panel_1.add(panel_5_1);
		
		JPanel panel_6_1 = new JPanel();
		panel_6_1.setBounds(0, 22, 685, 43);
		panel_5_1.add(panel_6_1);
		
		jt_text2 = new JTextField();
		jt_text2.setFont(new Font("宋体", Font.BOLD, 20));
		jt_text2.setColumns(30);
		panel_6_1.add(jt_text2);
		
		JButton jb_find2 = new JButton("查询");
		jb_find2.setIcon(new ImageIcon(New_find_panel.class.getResource("/img/查询 (3).png")));
		
		jb_find2.setFont(new Font("宋体", Font.BOLD, 20));
		panel_6_1.add(jb_find2);
		
		JPanel panel_7_1 = new JPanel();
		panel_7_1.setBounds(0, 67, 685, 43);
		panel_5_1.add(panel_7_1);
		
		JLabel lblNewLabel_6_1 = new JLabel("查询方式:");
		lblNewLabel_6_1.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7_1.add(lblNewLabel_6_1);
		
		JRadioButton jrb1_isbn = new JRadioButton("ISBN");
		jrb1_isbn.setSelected(true);
		jrb1_isbn.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7_1.add(jrb1_isbn);
		
		JRadioButton jrb2_name = new JRadioButton("书名");
		jrb2_name.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7_1.add(jrb2_name);
		
//		按钮组
		ButtonGroup bGroup=new ButtonGroup();
		bGroup.add(jrb2_name);
		bGroup.add(jrb1_isbn);
		
		JScrollPane scrollPane_1_1 = new JScrollPane();
		scrollPane_1_1.setBounds(0, 148, 685, 249);
		panel_5_1.add(scrollPane_1_1);
		
		headrObjects=new Object[]{"序号","ISBN","书名","作者","数量","标价"};
		Object [][] numObjects= {
		};
		
		table_1 = new JTable(numObjects,headrObjects);
		scrollPane_1_1.setViewportView(table_1);
		
		JLabel lblNewLabel_7_1 = new JLabel("查询结果:");
		lblNewLabel_7_1.setFont(new Font("宋体", Font.PLAIN, 17));
		lblNewLabel_7_1.setBounds(38, 120, 86, 18);
		panel_5_1.add(lblNewLabel_7_1);
		
		jl2 = new JLabel("");
		jl2.setFont(new Font("宋体", Font.PLAIN, 16));
		jl2.setForeground(Color.RED);
		jl2.setBounds(123, 111, 183, 27);
		panel_5_1.add(jl2);
		
		
		jb_find.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				获取文本框数据
				String text=jt_text.getText();
				if (text.equals("")) {
					JOptionPane.showMessageDialog(null, "请先输入要查询的内容!","提示",JOptionPane.INFORMATION_MESSAGE);
				}else {
//					判断所选择的查询方法
					int isselect=0;
					if (jrb_isbn.isSelected()) {
						isselect=1;
					}
					if (jrb_bookname.isSelected()) {
						isselect=2;
					}
					if (jrb_intime.isSelected()) {
						isselect=3;
					}
//					按ISBN查询结果
					if (isselect==1) {
						String sql="select ISBN,bookname,author,price,num,time from new_book_in where ISBN like '"+text+"%';";
						get_result(sql);
					}
					if (isselect==2) {
						String sql="select ISBN,bookname,author,price,num,time from new_book_in where bookname like '"+text+"%';";
						get_result(sql);
						
					}
					if (isselect==3) {
						String sql="select ISBN,bookname,author,price,num,time from new_book_in where time like '"+text+"%';";
						get_result(sql);

					}
				}
				

				
			}
		});
		jb_find2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				获取文本框数据
				String text=jt_text2.getText();
				if (text.equals("")) {
					JOptionPane.showMessageDialog(null, "请先输入要查询的内容!","提示",JOptionPane.INFORMATION_MESSAGE);
				}else {
//					判断所选择的查询方法
					int isselect=0;
					if (jrb1_isbn.isSelected()) {
						isselect=1;
					}
					if (jrb2_name.isSelected()) {
						isselect=2;
					}
//					按ISBN查询结果
					if (isselect==1) {
						String sql="select ISBN,bookname,author,num,markprice from book_stack where ISBN like '"+text+"%';";
						get_result1(sql);
						
					}
//					按书名查询
					if (isselect==2) {
						String sql="select ISBN,bookname,author,num,markprice from book_stack where bookname like '"+text+"%';";
						get_result1(sql);
					}
					
				}
			}

		});
		
	}
		
	/**
	 * 传入SQL语句,查询结果集,并显示到表格中
	 * @param sql
	 */
	public void get_result(String sql) {
		Object[][] a=new Object[][] {};
//		查询结果:
		try {
			ResultSet set=ConnectionManager.query(sql, new Object[] {});
//			如果结果集不为空
			if (set.next()) {
//				将结果转为二维数组
				a=ConnectionManager.getSetArrays(set);
//				将数组反馈到表格
				TableModel dataModel = new DefaultTableModel(a,o1);
				table.setModel(dataModel);
				jl_result.setText("");
			}else {
				TableModel dataModel = new DefaultTableModel(new Object[][] {},o1);
				table.setModel(dataModel);
				jl_result.setText("没有查询到结果");
				System.out.println("没有查询到结果!!!");
			}
			
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void get_result1(String sql) {
		// TODO Auto-generated method stub
		Object[][] a=new Object[][] {};
//		查询结果:
		try {
			ResultSet set=ConnectionManager.query(sql, new Object[] {});
//			如果结果集不为空
			if (set.next()) {
//				将结果转为二维数组
				a=ConnectionManager.getSetArrays(set);
//				将数组反馈到表格
				TableModel dataModel = new DefaultTableModel(a,headrObjects);
				table_1.setModel(dataModel);
				jl2.setText("");
			}else {
				TableModel dataModel = new DefaultTableModel(new Object[][] {},headrObjects);
				table_1.setModel(dataModel);
				
				jl2.setText("没有查询到结果");
				System.out.println("没有查询到结果!!!");
			}
			
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
	}
	
}

 Book_sele.java

package frame;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.text.Document;



import jdbc.ConnectionManager;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Color;
import javax.swing.JTabbedPane;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JRadioButton;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

public class Book_sele extends JPanel {
	private JTextField jt_isbn;
	private JTextField jt_bookname;
	private JTextField jt_num;
	private JTextField jt_price;
	public static JTextField jt_zhekou;
	private JTextField jt_shouldpay;
	private JTextField jt_receive;
	private JTextField jt_return;
	private static JTextField dingdan_nums;
	private JTable table;
	private JTextField find_text;
	private JTable table_1;
	private JLabel trips;
	private JLabel trips_1 ;
	private Object[] o1;
	private Object[][] o2;
	private static JLabel yes_no;
	private static JRadioButton jrb_isbn;
	private static JRadioButton jrb_bookname;
	private static JRadioButton jrb_time;

	/**
	 * Create the panel.
	 */
	public Book_sele() {
		setBackground(new Color(152, 251, 152));
		setBorder(new TitledBorder(null, "\u56FE\u4E66\u9500\u552E\u6A21\u5757", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(10, 24, 690, 426);
		add(tabbedPane);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("图书销售", new ImageIcon(Book_sele.class.getResource("/img/销售 (3).png")), panel, null);
		panel.setLayout(null);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBounds(0, 0, 685, 312);
		panel.add(panel_2);
		panel_2.setLayout(null);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBounds(10, 23, 665, 44);
		panel_2.add(panel_3);
		panel_3.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("ISBN:");
		lblNewLabel.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel.setBounds(68, 6, 91, 28);
		panel_3.add(lblNewLabel);
		
		jt_isbn = new JTextField();
//		动态监听
		Document d1=jt_isbn.getDocument();
		d1.addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				get_bookname_markprice();

			}
			
			@Override
			public void insertUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				get_bookname_markprice();
			}
			
			@Override
			public void changedUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		jt_isbn.setFont(new Font("宋体", Font.BOLD, 19));
		jt_isbn.setBounds(131, 10, 171, 21);
		panel_3.add(jt_isbn);
		jt_isbn.setColumns(25);
		
		JLabel lblNewLabel_1 = new JLabel("书名:");
		lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1.setBounds(352, 6, 75, 28);
		panel_3.add(lblNewLabel_1);
		
		jt_bookname = new JTextField();
		jt_bookname.setFont(new Font("宋体", Font.BOLD, 19));
		jt_bookname.setColumns(25);
		jt_bookname.setBounds(420, 10, 171, 21);
		panel_3.add(jt_bookname);
		
		JPanel panel_3_1 = new JPanel();
		panel_3_1.setLayout(null);
		panel_3_1.setBounds(10, 91, 665, 58);
		panel_2.add(panel_3_1);
		
		JLabel lblNewLabel_2 = new JLabel("购买数量:");
		lblNewLabel_2.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_2.setBounds(37, 6, 122, 28);
		panel_3_1.add(lblNewLabel_2);
		
		jt_num = new JTextField();
		jt_num.setFont(new Font("宋体", Font.BOLD, 19));
		jt_num.setColumns(25);
		jt_num.setBounds(131, 10, 171, 21);
		panel_3_1.add(jt_num);
		
		JLabel lblNewLabel_1_1 = new JLabel("价格:");
		lblNewLabel_1_1.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1_1.setBounds(352, 6, 75, 28);
		panel_3_1.add(lblNewLabel_1_1);
		
		jt_price = new JTextField();
		jt_price.setFont(new Font("宋体", Font.BOLD, 19));
		jt_price.setColumns(25);
		jt_price.setBounds(420, 10, 171, 21);
		panel_3_1.add(jt_price);
		
		trips_1 = new JLabel("");
		trips_1.setForeground(Color.RED);
		trips_1.setFont(new Font("宋体", Font.BOLD, 16));
		trips_1.setBounds(131, 37, 274, 21);
		panel_3_1.add(trips_1);
		
		JPanel panel_3_2 = new JPanel();
		panel_3_2.setLayout(null);
		panel_3_2.setBounds(10, 159, 665, 44);
		panel_2.add(panel_3_2);
		
		JLabel lblNewLabel_3 = new JLabel("折扣:");
		lblNewLabel_3.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_3.setBounds(68, 6, 91, 28);
		panel_3_2.add(lblNewLabel_3);
		
		jt_zhekou = new JTextField();
		jt_zhekou.setText(Double.toString(Jrame2.zhekou));
		jt_zhekou.setEditable(false);
		jt_zhekou.setFont(new Font("宋体", Font.BOLD, 19));
		jt_zhekou.setColumns(25);
		jt_zhekou.setBounds(131, 10, 171, 21);
		panel_3_2.add(jt_zhekou);
		
		JLabel lblNewLabel_1_2 = new JLabel("应付:");
		lblNewLabel_1_2.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1_2.setBounds(352, 6, 75, 28);
		panel_3_2.add(lblNewLabel_1_2);
		
		jt_shouldpay = new JTextField();
//		动态计算应付金额
		Document dtDocument=jt_num.getDocument();
		dtDocument.addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
					try {
						get_shouldpay();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				
			}
			
			@Override
			public void insertUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
					try {
						get_shouldpay();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				
			}
			
			@Override
			public void changedUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		jt_shouldpay.setFont(new Font("宋体", Font.BOLD, 19));
		jt_shouldpay.setColumns(25);
		jt_shouldpay.setBounds(420, 10, 171, 21);
		panel_3_2.add(jt_shouldpay);
		
		JPanel panel_3_3 = new JPanel();
		panel_3_3.setLayout(null);
		panel_3_3.setBounds(10, 235, 665, 67);
		panel_2.add(panel_3_3);
		
		trips = new JLabel("");
		trips.setFont(new Font("宋体", Font.BOLD, 16));
		trips.setForeground(Color.RED);
		trips.setBounds(131, 35, 202, 21);
		panel_3_3.add(trips);
		
		JLabel lblNewLabel_4 = new JLabel("收取:");
		lblNewLabel_4.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_4.setBounds(68, 6, 91, 28);
		panel_3_3.add(lblNewLabel_4);
		
		jt_receive = new JTextField();
		Document document=jt_receive.getDocument();
		document.addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				get_returnmoney();
			}
			
			@Override
			public void insertUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				get_returnmoney();

			}
			
			@Override
			public void changedUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		jt_receive.setFont(new Font("宋体", Font.BOLD, 19));
		jt_receive.setColumns(25);
		jt_receive.setBounds(131, 10, 171, 21);
		panel_3_3.add(jt_receive);
		
		JLabel lblNewLabel_1_3 = new JLabel("找零:");
		lblNewLabel_1_3.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_1_3.setBounds(352, 6, 75, 28);
		panel_3_3.add(lblNewLabel_1_3);
		
		jt_return = new JTextField();
		jt_return.setFont(new Font("宋体", Font.BOLD, 19));
		jt_return.setColumns(25);
		jt_return.setBounds(420, 10, 171, 21);
		panel_3_3.add(jt_return);
		
		
		
		JButton btnNewButton = new JButton("重置");
		btnNewButton.setIcon(new ImageIcon(Book_sele.class.getResource("/img/重置.png")));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				重置输出框
				jt_isbn.setText("");
				jt_bookname.setText("");
				jt_num.setText("");
				jt_price.setText("");
				jt_shouldpay.setText("");
				jt_receive.setText("");
				jt_return.setText("");
			}
		});
		btnNewButton.setFont(new Font("宋体", Font.BOLD, 18));
		btnNewButton.setBounds(155, 322, 113, 30);
		panel.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("确定");
		btnNewButton_1.setIcon(new ImageIcon(Book_sele.class.getResource("/img/确定.png")));
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				判断当前ISBN对应的图书是否存在
				
				if (jt_isbn.getText().equals("")) {
					JOptionPane.showMessageDialog(null, "请输入要购买的图书!","提示",JOptionPane.INFORMATION_MESSAGE);

				}else {
					String isbn=jt_isbn.getText();
					String sql="select * from book_stack where ISBN=?";
					try {
						ResultSet set=ConnectionManager.query(sql, new Object[] {isbn});
//						如果该书不存在
						if (!set.next()) {
							JOptionPane.showMessageDialog(null, "书库中没有该图书","提示",JOptionPane.INFORMATION_MESSAGE);
						}else {
//							当前图书存在,保存相应订单
//							获取要保存的数据
							String isbnString=jt_isbn.getText();
							String bookname=jt_bookname.getText();
							String num=jt_num.getText();
							String markprice=jt_price.getText();
							String zhekou=jt_zhekou.getText();
							String shouldpay=jt_shouldpay.getText();
							String receive=jt_receive.getText();
							String returnmoney=jt_return.getText();
//							下单时间
							String time=ConnectionManager.gettime();
//							保存数据到表
							String sqlstring="insert into book_out values(?,?,?,?,?,?,?,?,?,?);";
							int n=ConnectionManager.Update(sqlstring, new Object[] {null,isbnString,bookname,num,markprice,zhekou,shouldpay,receive,returnmoney,time});
							if(n>0) {
								JOptionPane.showMessageDialog(null, "下单成功!","提示",JOptionPane.INFORMATION_MESSAGE);
//								修改库存数量
								int stocknum=0;
								String sqlString2="select num from book_stack where ISBN=?";
								ResultSet set1=ConnectionManager.query(sqlString2, new Object[] {isbnString});
								if(set1.next()) {
									stocknum=set1.getInt("num");
								}
								stocknum=stocknum-Integer.parseInt(num);
//								保存更改后的数量-库存
								String sqlString3="update book_stack set num=? where ISBN=?";
								int m=ConnectionManager.Update(sqlString3, new Object[] {stocknum,isbn});
								if (m>0) {
									System.out.println("(book-stack table图书数量更新完毕,购买"+num+"现在还剩下"+stocknum);
								}
								else {
									System.out.println("图书数量更新失败!");
								}
//								新书表
								String sqlString4="update new_book_in set num=? where ISBN=?";
								int k=ConnectionManager.Update(sqlString4, new Object[] {stocknum,isbn});
								if (k>0) {
									System.out.println("(new book table)图书数量更新完毕,购买"+num+"现在还剩下"+stocknum);
								}
								else {
									System.out.println("图书数量更新失败!");
								}
//								刷新表格
								
								Update_sele_table();
								Books_panel.update_table_items();
								
							}else {
								JOptionPane.showMessageDialog(null, "下单失败!","提示",JOptionPane.INFORMATION_MESSAGE);
								

							}
							
							
							
						}
						
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				
			}
		});
		btnNewButton_1.setFont(new Font("宋体", Font.BOLD, 18));
		btnNewButton_1.setBounds(455, 322, 113, 30);
		panel.add(btnNewButton_1);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("订单一览", new ImageIcon(Book_sele.class.getResource("/img/浏览.png")), panel_1, null);
		panel_1.setLayout(null);
		
		JPanel panel_4 = new JPanel();
		panel_4.setBounds(10, 43, 665, 344);
		panel_1.add(panel_4);
		panel_4.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 0, 665, 344);
		panel_4.add(scrollPane);
		
		o1=new Object[] {"序号","ISBN","书名","购买数量","标价","折扣","应付","收取","找零","下单时间"};
		o2=new Object[][] {
		
		};
		
		table = new JTable(o2,o1);
		scrollPane.setViewportView(table);
		
		JLabel lblNewLabel_5 = new JLabel("订单总数:");
		lblNewLabel_5.setFont(new Font("宋体", Font.BOLD, 19));
		lblNewLabel_5.setBounds(468, 10, 124, 23);
		panel_1.add(lblNewLabel_5);
		
		dingdan_nums = new JTextField();
		dingdan_nums.setEditable(false);
		dingdan_nums.setBounds(556, 10, 93, 21);
		panel_1.add(dingdan_nums);
		dingdan_nums.setColumns(10);
		
		JPanel panel_5 = new JPanel();
		tabbedPane.addTab("订单查询", new ImageIcon(Book_sele.class.getResource("/img/查询 (2).png")), panel_5, null);
		panel_5.setLayout(null);
		
		JPanel panel_6 = new JPanel();
		panel_6.setBounds(0, 22, 685, 43);
		panel_5.add(panel_6);
		
		find_text = new JTextField();
		find_text.setFont(new Font("宋体", Font.BOLD, 20));
		panel_6.add(find_text);
		find_text.setColumns(30);
		
		JButton btnNewButton_2 = new JButton("查询");
		btnNewButton_2.setIcon(new ImageIcon(Book_sele.class.getResource("/img/查询 (3).png")));
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				获取文本框数据
				String text=find_text.getText();
				if (text.equals("")) {
					JOptionPane.showMessageDialog(null, "请先输入要查询的内容!","提示",JOptionPane.INFORMATION_MESSAGE);
				}else {
//					判断所选择的查询方法
					int isselect=0;
					if (jrb_isbn.isSelected()) {
						isselect=1;
					}
					if (jrb_bookname.isSelected()) {
						isselect=2;
					}
					if (jrb_time.isSelected()) {
						isselect=3;
					}
//					按ISBN查询结果
//					String sql2="SELECT ISBN,bookname,out_num,markprice,zhekou,sholdpay,`return`,receive,time from book_out;";

					if (isselect==1) {
						String sql="SELECT ISBN,bookname,out_num,markprice,zhekou,sholdpay,`return`,receive,time from book_out where ISBN like '"+text+"%';";
						get_find_result(sql);
					}
					if (isselect==2) {
						String sql="SELECT ISBN,bookname,out_num,markprice,zhekou,sholdpay,`return`,receive,time from book_out where bookname like '"+text+"%';";
						get_find_result(sql);

						
					}
					if (isselect==3) {
						String sql="SELECT ISBN,bookname,out_num,markprice,zhekou,sholdpay,`return`,receive,time from book_out where time like '"+text+"%';";
						get_find_result(sql);
					}
				}
				

				
			}
			
		});
		btnNewButton_2.setFont(new Font("宋体", Font.BOLD, 20));
		panel_6.add(btnNewButton_2);
		
		JPanel panel_7 = new JPanel();
		panel_7.setBounds(0, 67, 685, 43);
		panel_5.add(panel_7);
		
		JLabel lblNewLabel_6 = new JLabel("查询方式:");
		lblNewLabel_6.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(lblNewLabel_6);
		
		jrb_isbn = new JRadioButton("ISBN");
		jrb_isbn.setSelected(true);
		jrb_isbn.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(jrb_isbn);
		
		jrb_bookname = new JRadioButton("书名");
		jrb_bookname.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(jrb_bookname);
		
		jrb_time = new JRadioButton("交易时间");
		jrb_time.setForeground(Color.BLACK);
		jrb_time.setFont(new Font("宋体", Font.BOLD, 18));
		panel_7.add(jrb_time);
		
//		按钮组
		ButtonGroup bGroup=new ButtonGroup();
		bGroup.add(jrb_time);
		bGroup.add(jrb_bookname);
		bGroup.add(jrb_isbn);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(0, 148, 685, 249);
		panel_5.add(scrollPane_1);
		
		table_1 = new JTable(o2,o1);
		scrollPane_1.setViewportView(table_1);
		
		JLabel lblNewLabel_7 = new JLabel("查询结果:");
		lblNewLabel_7.setFont(new Font("宋体", Font.PLAIN, 17));
		lblNewLabel_7.setBounds(38, 120, 86, 18);
		panel_5.add(lblNewLabel_7);
		
		yes_no = new JLabel("");
		yes_no.setForeground(Color.RED);
		yes_no.setFont(new Font("宋体", Font.PLAIN, 17));
		yes_no.setBounds(121, 120, 183, 20);
		panel_5.add(yes_no);
		

		Update_sele_table();
		

	}
	
	/**
	 * 动态查询ISBN如有结果返回bookname和markprice
	 */
	public void get_bookname_markprice() {
//		获取ISBN值
		String isbn=jt_isbn.getText();
//		从库存表中查询是否有该图书
		String sql="select * from book_stack where ISBN=?;";
//		执行
		try {
			ResultSet set=ConnectionManager.query(sql, new Object[] {isbn});
//			判断结果集
			if(set.next()) {
				String bookname=set.getString("bookname");
				double markprice=set.getDouble("markprice");
//				将值设置到文本框
				jt_bookname.setText(bookname);
				jt_price.setText(Double.toString(markprice));
			}else {
				jt_bookname.setText("");
				jt_price.setText("");
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	/**
	 * 计算应付金额
	 * @throws SQLException 
	 */
	public void get_shouldpay() throws SQLException {
//		获取该书的库存量
		boolean extis=false;
		String isbn=jt_isbn.getText();
		int num;
		String sql="select num from book_stack where ISBN=?";
		ResultSet set = null;
		try {
			set = ConnectionManager.query(sql, new Object[] {isbn});
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int stock_num = 0;
		while (set.next()) {
			stock_num=set.getInt("num");
			extis=true;
			
		}
		
		if (jt_num.getText().equals("")) {
			trips_1.setText("");
		}else if (extis) {
//			购买数量超过库存
			num=Integer.parseInt(jt_num.getText());
			if (num>stock_num) {
				trips_1.setText("该书当前库存(最多购买)"+stock_num+"本!!!");
			}else {
//				获取价格,数量,折扣
				trips_1.setText("");
				double price=Double.parseDouble(jt_price.getText());
				double zhekou=Double.parseDouble(jt_zhekou.getText());
//				计算应付金额
				double shouldpay=num*price*zhekou;
//				会显
				jt_shouldpay.setText(Double.toString(shouldpay));
			}
			
		}
		
		
	}
	
	/**
	 * 计算找零
	 */
	public void get_returnmoney() {
		if (jt_receive.getText().equals("")) {
			
		}else {
//			获取应付
			double shouldpay=Double.parseDouble(jt_shouldpay.getText());
//			获取 收取
			double receive=Double.parseDouble(jt_receive.getText());
//			判断收取是否够钱
			if (receive

 System_setting-panel.java

package frame;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.TitledBorder;

import jdbc.ConnectionManager;

import javax.swing.border.EtchedBorder;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

public class System_setting_panel extends JPanel {
	private JTextField OriginalCode;
	private JTextField NewPassword;
	private JTextField jt1;
	private JTextField jt2;
	/**
	 * Create the panel.系统设置
	 */
	public System_setting_panel() {
		setBackground(new Color(220, 220, 220));
		setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u7CFB\u7EDF\u8BBE\u7F6E\u6A21\u5757", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		setSize(710, 460);
		setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(10, 24, 690, 426);
		add(tabbedPane);
		
		JPanel panel_3 = new JPanel();
		tabbedPane.addTab("买卖设置", new ImageIcon(System_setting_panel.class.getResource("/img/设 置.png")), panel_3, null);
		panel_3.setLayout(null);
		
		JPanel panel_4 = new JPanel();
		panel_4.setBounds(10, 58, 665, 80);
		panel_3.add(panel_4);
		panel_4.setLayout(null);
		
		JLabel lblNewLabel_4 = new JLabel("标价=进价*");
		lblNewLabel_4.setBounds(190, 27, 136, 27);
		lblNewLabel_4.setFont(new Font("宋体", Font.BOLD, 23));
		panel_4.add(lblNewLabel_4);
		
		jt1 = new JTextField();
		jt1.setBounds(331, 24, 136, 33);
		jt1.setFont(new Font("宋体", Font.BOLD, 23));
		panel_4.add(jt1);
		jt1.setColumns(10);
		jt1.setText(Double.toString(Jrame2.inprice_add));
		
		JPanel panel_4_1 = new JPanel();
		panel_4_1.setLayout(null);
		panel_4_1.setBounds(10, 156, 665, 80);
		panel_3.add(panel_4_1);
		
		JLabel lblNewLabel_4_1 = new JLabel("今日折扣:");
		lblNewLabel_4_1.setFont(new Font("宋体", Font.BOLD, 23));
		lblNewLabel_4_1.setBounds(211, 28, 121, 27);
		panel_4_1.add(lblNewLabel_4_1);
		
		jt2 = new JTextField();
		jt2.setFont(new Font("宋体", Font.BOLD, 23));
		jt2.setColumns(10);
		jt2.setBounds(330, 25, 136, 33);
		panel_4_1.add(jt2);
		jt2.setText(Double.toString(Jrame2.zhekou));
		
		JPanel panel_4_1_1 = new JPanel();
		panel_4_1_1.setBounds(10, 263, 665, 80);
		panel_3.add(panel_4_1_1);
		
		JButton jb_reset = new JButton("重置");
		jb_reset.setIcon(new ImageIcon(System_setting_panel.class.getResource("/img/重置.png")));
		jb_reset.setBounds(172, 5, 103, 35);
		jb_reset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jt1.setText("");
				jt2.setText("");
			}
		});
		panel_4_1_1.setLayout(null);
		jb_reset.setFont(new Font("宋体", Font.BOLD, 20));
		panel_4_1_1.add(jb_reset);
		
		JButton jb_ok = new JButton("确定修改");
		jb_ok.setIcon(new ImageIcon(System_setting_panel.class.getResource("/img/确定.png")));
		jb_ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				拿到数据,设置新数值
				Jrame2.inprice_add=Double.parseDouble(jt1.getText());
				Jrame2.zhekou=Double.parseDouble(jt2.getText());
				System.out.println(Jrame2.inprice_add);
				System.out.println(Jrame2.zhekou);
				Book_sele.jt_zhekou.setText(jt2.getText());
//				
			}
		});
		jb_ok.setBounds(342, 5, 146, 35);
		jb_ok.setFont(new Font("宋体", Font.BOLD, 20));
		panel_4_1_1.add(jb_ok);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("修改密码", new ImageIcon(System_setting_panel.class.getResource("/img/修改密码 (1).png")), panel, null);
		panel.setLayout(null);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBounds(10, 44, 665, 41);
		panel.add(panel_2);
		
		JLabel lblNewLabel_2 = new JLabel("请输入");
		lblNewLabel_2.setFont(new Font("宋体", Font.BOLD, 26));
		panel_2.add(lblNewLabel_2);
		
		OriginalCode = new JTextField();
		OriginalCode.setFont(new Font("宋体", Font.BOLD, 25));
		OriginalCode.setColumns(10);
		OriginalCode.setBounds(215, 124, 299, 29);
		panel.add(OriginalCode);
		
		JLabel lblNewLabel = new JLabel("原密码:");
		lblNewLabel.setFont(new Font("宋体", Font.BOLD, 25));
		lblNewLabel.setBounds(116, 95, 122, 87);
		panel.add(lblNewLabel);
		JLabel lblNewLabel_1 = new JLabel("新密码:");
		lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 25));
		lblNewLabel_1.setBounds(116, 163, 105, 97);
		panel.add(lblNewLabel_1);
		
		NewPassword = new JTextField();
		NewPassword.setFont(new Font("宋体", Font.BOLD, 25));
		NewPassword.setColumns(10);
		NewPassword.setBounds(215, 197, 299, 29);
		panel.add(NewPassword);
		
		JButton btnNewButton = new JButton("重置");
		btnNewButton.setIcon(new ImageIcon(System_setting_panel.class.getResource("/img/重置.png")));
		btnNewButton.setFont(new Font("宋体", Font.BOLD, 21));
		btnNewButton.setBounds(145, 285, 97, 23);
		panel.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("确定");
		btnNewButton_1.setIcon(new ImageIcon(System_setting_panel.class.getResource("/img/确定.png")));
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				先获取输入的密码与已经登录的密码匹配是否一致
				String originalCodeString=OriginalCode.getText();
				if (originalCodeString.equals(Jrame2.manager.getPswString())) {
					System.out.println("原密码正确!");
//					获取新密码
					String newPasswordString=NewPassword.getText();
//					保存新密码到用户表中
					System.out.println(newPasswordString);
					String sql="update manager set password=? where user=?";
					try {
						int n=ConnectionManager.Update(sql, new Object[] {newPasswordString,Jrame2.manager.getUserString()});
						if (n>0) {
//							密码修改成功
							JOptionPane.showMessageDialog(null,"密码修改成功,请重新登录!!!","提示",JOptionPane.INFORMATION_MESSAGE);
							Login.jrame.dispose();
							System.out.println("当前窗口关闭");
							Login login=new Login();
							login.setVisible(true);
							System.out.println("打开新窗口,请登录!");
						}else {
							System.out.println("密码修改发生错误!!!!!!");
						}
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}else {
					JOptionPane.showMessageDialog(null,"原密码错误!","提示",JOptionPane.INFORMATION_MESSAGE);
					System.out.println("原密码错误!");
				}
				
			}
		});
		btnNewButton_1.setFont(new Font("宋体", Font.BOLD, 21));
		btnNewButton_1.setBounds(390, 285, 97, 23);
		panel.add(btnNewButton_1);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("联系作者", new ImageIcon(System_setting_panel.class.getResource("/img/联系.png")), panel_1, null);
		panel_1.setLayout(null);
		
		JLabel lblNewLabel_3 = new JLabel("");
		lblNewLabel_3.setBounds(90, 0, 527, 349);
		lblNewLabel_3.setIcon(new ImageIcon(System_setting_panel.class.getResource("/img/mmqrcode1626318219670.png")));
		panel_1.add(lblNewLabel_3);
		
		JLabel lblNewLabel_5 = new JLabel("更多联系作者VX:17641244340");
		lblNewLabel_5.setFont(new Font("宋体", Font.BOLD, 21));
		lblNewLabel_5.setBounds(193, 359, 367, 40);
		panel_1.add(lblNewLabel_5);

	}
}

        完整代码这里取=》传送门->点我直达

效果图:

登录系统

 添加图书

总体概览

 查询

图书下单


 完整代码这里取=》关注下面公众号:回复关键字“图书系统”获取源码

 

以上只演示了部分操作,感兴趣的可以自己尝试一下哦

有不对或者需要改进的地方欢迎指正哈!!!

喜欢的伙伴三连支持一下哦!!!

欢迎分享,转载请注明来源:内存溢出

原文地址:http://outofmemory.cn/sjk/996428.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

随机推荐

发表评论

登录后才能评论

评论列表(0条)