该图书管理系统是我研一时候的一个课程设计,当时也刚重新学完Java。你可能会“重新”是什么意思。唉,说来惭愧,大学时我先学了点Java的皮毛,就投奔搞Android去了,所以对Java的基础比较薄弱。而现在学完了,所以就想试着弄个小系统来练练手,所以参考了上一篇中国象棋的代码,就做了这个图书管理系统。
同样,这个系统采用的是客户端/服务端(C/S)的模式,相对于上一篇的中国象棋,该系统保留了Socket和多线程编程外,增加了JDBC编程,对数据库进行操作。数据库采用的是SqlServer 2005,建立了用户信息表以及图书信息表,两者是一对多的关系,下面下载的源码中已包含了建数据库和建表,以及插入用户数据以及图书数据。
package Library_Server;
public class ServerAgentThread extends Thread{
Library_ServerUI father;
Socket socket;//声明Socket的引用
/* PrintWriter Write_out;//获取Socket的输出流,用来向客户端发送数据
BufferedReader Read_in;//获取Socket的输入流,用来接收从客户端发送过来的数据 */
ObjectOutputStream Write_out;
ObjectInputStream Read_in;
boolean flag=true;//控制线程的标志位
IO_in IOin=new IO_in();
IO_out IOout=new IO_out();
public ServerAgentThread(Library_ServerUI father,Socket sc,String socket_name) throws UnsupportedEncodingException, IOException {
this.father=father;
this.socket=sc;
this.setName(socket_name);
/* Write_out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream(),"utf-8")),true);
Read_in= new BufferedReader(new InputStreamReader(this.socket.getInputStream(),"utf-8")); */
Read_in=new ObjectInputStream(socket.getInputStream());
Write_out=new ObjectOutputStream(this.socket.getOutputStream());
}
@Override
public void run() {
super.run();
while (flag) {
try {
String sql = null;
String msg=(String)IOin.ReceiveMessage(Read_in);
if(msg.startsWith(Order_format.All_book)){//从数据库中返回所有书并打包发送
sql="select * from Book_Info";
Vector vector= Search_Book(sql);
IOout.SendMessage(Write_out,vector);
}else if(msg.startsWith(Order_format.bookname)){//返回搜索的书
sql="select * from Book_Info where bookname like '"+msg.substring(Order_format.count2)
+"%' "+"or bookname like '%"+msg.substring(Order_format.count2)+"%'";
Vector vector= Search_Book(sql);
IOout.SendMessage(Write_out,vector);
}else if(msg.startsWith(Order_format.author)){
sql="select * from Book_Info where author like '"+msg.substring(Order_format.count3)
+"%' "+"or author like '%"+msg.substring(Order_format.count3)+"%'";
Vector vector= Search_Book(sql);
IOout.SendMessage(Write_out,vector);
}else if(msg.startsWith(Order_format.Callno)){
sql="select * from Book_Info where Callno like '"+msg.substring(Order_format.count5)
+"%' "+"or Callno like '%"+msg.substring(Order_format.count5)+"%'";
Vector vector= Search_Book(sql);
IOout.SendMessage(Write_out,vector);
}else if(msg.startsWith(Order_format.publishment)){
sql="select * from Book_Info where publishment like '"+msg.substring(Order_format.count4)
+"%' "+"or publishment like '%"+msg.substring(Order_format.count4)+"%'";
Vector vector= Search_Book(sql);
IOout.SendMessage(Write_out,vector);
}else if(msg.startsWith(Order_format.Borrow_Book)){
sql="select * from Record_Info where account=?";
String[] user_book=Get_Borrow_book(sql,this.getName());//得到借的5本书,不管有没有
Update_Borrow_Record(user_book,msg.substring(Order_format.count6),this.getName());
}else if(msg.startsWith(Order_format.User_book)){
sql="select * from Record_Info where account=?";
String[] user_book=Get_Borrow_book(sql,msg.substring(Order_format.count7));//得到借的5本书,不管有没有
GetBack_Book(user_book);
}else if(msg.startsWith(Order_format.Return_Book)){
sql="select * from Record_Info where account=?";
String[] user_book=Get_Borrow_book(sql,this.getName());//得到借的5本书,不管有没有
Update_Return_Record(user_book,msg.substring(Order_format.count8),this.getName());//换的书变为null,并设置该书在架上
String[] user_book1=Get_Borrow_book(sql,this.getName());//得到更新后的借的5本书
GetBack_Book(user_book1);
}else if(msg.startsWith(Order_format.Exit)){
this.father.onlineList.removeElement(this.getName());
this.father.refreshList();
socket.close();
flag=false;
}
} catch (ClassNotFoundException|IOException e){
e.printStackTrace();
}
}
}
public Vector Search_Book(String sql){
Database database = null;
Book_Info book_info;
Vector vector=new Vector();
try{
database=new Database();
ResultSet rs=database.query_Book(sql);
while(rs.next())
{
book_info=new Book_Info();
book_info.setBookname(rs.getString(1));
book_info.setAuthor(rs.getString(2));
book_info.setPublishment(rs.getString(3));
book_info.setState(rs.getString(4));
book_info.setCallno(rs.getString(5));
vector.addElement(book_info);
}
}catch(Exception e){}
finally
{
database.close();
}
return vector;
}
public String[] Get_Borrow_book(String sql,String loginID){
Database database = null;
String[] user_book = new String[5];
try {
database=new Database();
ResultSet rs=database.query_Bookcount(sql, loginID);
while(rs.next()){
for(int i=0;i对不起,你的借阅数量已达上限!");
} catch (IOException e) {}
}
}
public void Update_Return_Record(String[] user_book,String bookname,String loginID){
Database database = null;
String sql=null;
for(int i=0;i vector=Search_Book(sql);
try {
IOout.SendMessage(Write_out,vector);
} catch (IOException e) {
e.printStackTrace();
}
}
}
(3)电脑客户端
客户端就只贴电脑客户端的代码,至于手机客户端就不贴了,感兴趣的可以自行下载代码!
用户登陆UI
package Library_Client;
public class Library_LoginUI extends JFrame implements ActionListener{
public static final String title="图书馆系统";
ImageIcon background=new ImageIcon("./image/background.jpg");
JPanel jps=new JPanel();//创建一个JPanel对象
JLabel Jl_background=new JLabel(background);
JLabel Jl_title=new JLabel(title,JLabel.CENTER);
JLabel Jl_IP=new JLabel("IP:",JLabel.RIGHT);
JLabel Jl_stytle=new JLabel("类型:",JLabel.RIGHT);
JLabel Jl_user=new JLabel("账号:",JLabel.RIGHT);
JLabel Jl_password=new JLabel("密码:",JLabel.RIGHT);
JTextField Jf_IP=new JTextField("127.0.0.1");
JTextField Jf_user=new JTextField("1534041005");
JComboBox Jb_stytle=new JComboBox();
JPasswordField jpassword=new JPasswordField("1234567");
JButton Jlogin=new JButton(new ImageIcon("./image/login.jpg"));
Socket socket;//声明Socket引用
ClientThread clientThread;
ObjectOutputStream Write_out;
ObjectInputStream Read_in;
IO_in IOin=new IO_in();
IO_out IOout=new IO_out();
public Library_LoginUI() {
initialComponent();
addListener();
initialFrame();
}
public static void main(String[] args) {
new Library_LoginUI();
}
public void initialComponent(){
jps.setLayout(null);//设为空布局
Jl_title.setBounds(350, 100, 300, 50);
Jl_title.setFont(new Font(title, 1,50));
Jl_title.setForeground(Color.GREEN);
jps.add(Jl_title);
Jl_IP.setBounds(250, 250, 110, 25);
Jl_IP.setFont(new Font("IP:", 1,25));
Jl_IP.setForeground(Color.lightGray);
jps.add(Jl_IP);
Jl_stytle.setBounds(250, 300, 110, 25);
Jl_stytle.setFont(new Font("类型:", 1,25));
Jl_stytle.setForeground(Color.lightGray);
jps.add(Jl_stytle);
Jl_user.setBounds(250, 350, 110, 25);
Jl_user.setFont(new Font("账号:", 1,25));
Jl_user.setForeground(Color.lightGray);
jps.add(Jl_user);
Jl_password.setBounds(250, 400, 110, 25);
Jl_password.setFont(new Font("密码:", 1,25));
Jl_password.setForeground(Color.lightGray);
jps.add(Jl_password);
Jf_IP.setBounds(370, 250, 200, 25);
jps.add(Jf_IP);
Jb_stytle.setBounds(370, 300, 200, 25);
Vector v=new Vector();
v.add("学生");
v.add("管理员");
v.add("老师");
Jb_stytle.setModel(new DefaultComboBoxModel(v));
jps.add(Jb_stytle);
Jf_user.setBounds(370, 350, 200,25);
jps.add(Jf_user);
jpassword.setBounds(370, 400, 200,25);
jps.add(jpassword);
Jlogin.setBounds(620, 385, 80,40);
jps.add(Jlogin);
Jl_background.setBounds(0, 0, background.getIconWidth(),background.getIconHeight());
jps.add(Jl_background);
}
public void addListener(){
Jlogin.addActionListener(this);
}
public void initialFrame(){
this.setTitle("图书管理系统--客户端");//设置窗体标题
Image image=new ImageIcon("./image/library_ico.jpg").getImage();
this.setIconImage(image);
Dimension scrSize=Toolkit.getDefaultToolkit().getScreenSize(); //获取屏幕长宽
this.setBounds(scrSize.width/6,scrSize.height/6, background.getIconWidth(),background.getIconHeight());
this.add(jps);
this.setVisible(true);//设置可见性
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addWindowListener(mywindowadapter);
}
public WindowAdapter mywindowadapter=new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
// socket.close();
};
};
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==this.Jlogin){
jbConnect_event();
}
}
public void jbConnect_event(){
String ip=Jf_IP.getText().trim();
String user=Jf_user.getText().trim();
String password=jpassword.getText().trim();
String position=(String)Jb_stytle.getSelectedItem();
if(!isIP(ip)){
JOptionPane.showMessageDialog(this,"IP地址错误!","错误",JOptionPane.ERROR_MESSAGE);
return;
}
if(!(user.length()>0)||!(password.length()>0))
{
JOptionPane.showMessageDialog(this,"用户名和密码不能为空!","错误",JOptionPane.ERROR_MESSAGE);
return;
}
try{
socket=new Socket(ip,9999);//创建Socket对象
User user_info=Authentication(socket,user,password,position);
if(user_info.grtIsuser()){
if(position.equals("管理员")){
}else{
new Library_ClientUI(socket,user_info.getUserId(),user_info.getUsername(),user_info.getPosition());
}
dispose();
}
}catch(Exception e){}
}
public boolean isIP(String addr)
{
if(addr.length() < 7 || addr.length() > 15 || "".equals(addr))
{
return false;
}
/**
* 判断IP格式和范围
*/
String rexp = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
Pattern pat = Pattern.compile(rexp);
Matcher mat = pat.matcher(addr);
boolean ipAddress = mat.find();
return ipAddress;
}
public User Authentication(Socket socket,String user,String password,String position) throws IOException, ClassNotFoundException{
User u=new User();
u.setUserId(user);
u.setPasswd(password);
u.setIsuser(false);
u.setPosition(position);
Write_out=new ObjectOutputStream(socket.getOutputStream());
IOout.SendMessage(Write_out, u);
Read_in=new ObjectInputStream(socket.getInputStream());
User user1=(User)IOin.ReceiveMessage(Read_in);
return user1;
}
}
电脑客户端UI
用户登陆后,点检索键会把所有图书的信息列出来,从中我们可以看到那些图书已经借出去了,哪些还没有借。对于已经借出去的图书,你是不能选中的,而没借出去的可以双击选中。
package Library_Client;
public class Library_ClientUI extends JFrame implements ActionListener,MouseListener{
Socket socket;
String user_ID,position,user_name;
ObjectOutputStream Write_out;
ObjectInputStream Read_in;
IO_in IOin=new IO_in();
IO_out IOout=new IO_out();
JPanel title_Jpanel=new JPanel();
JLabel title_bg;
JLabel title;
JLabel Welcome;
ImagePanel Menu_Jpanel;
JLabel Menu_title;
JLabel Menu1,Menu2,Menu3,Menu4,Menu5,Menu6;
Image Menu_bg;
JPanel Main_Jpanel=new JPanel();
JLabel Spacer_bar;
JPanel inter_Jpanel=new JPanel();
JPanel Search_Jpanel=new JPanel();
JComboBox Search_Key;
String[] key={"关键词","索书号","书名","作者名","出版社"};
JTextField key_name;
JButton Search_Button;
Show_BookList List_Jpanel;
JPanel title_name=new JPanel();
JLabel Sel_book,Book_name,Author,Status,Callno;
public Library_ClientUI(Socket socket,String user_ID,String user_name,String position) throws IOException {
this.socket=socket;
this.user_ID=user_ID;
this.position=position;
this.user_name=user_name;
Write_out=new ObjectOutputStream(this.socket.getOutputStream());
Read_in=new ObjectInputStream(this.socket.getInputStream());
initialComponent();
initialFrame();
}
public Library_ClientUI(){
initialComponent();
initialFrame();
}
/* public static void main(String[] args) {
new Library_ClientUI();
}*/
private void initialComponent(){
title_Jpanel.setLayout(new BorderLayout());
title=new JLabel("暨南大学图书馆",JLabel.CENTER);
title.setBounds(300, 10,400, 80);
title.setFont(new Font("暨南大学图书馆", 1,50));
title.setForeground(Color.black);
title_Jpanel.add(title,BorderLayout.NORTH);
Welcome=new JLabel("欢迎!"+user_name);
Welcome.setFont(new Font("欢迎!"+user_name, 1,15));
Welcome.setForeground(Color.black);
title_Jpanel.add(Welcome,BorderLayout.SOUTH);
title_bg=new JLabel(new ImageIcon("./image/title_bg.jpg"),JLabel.CENTER);
title_bg.setBounds(0, 0, 1000, 100);
title_Jpanel.add(title_bg,BorderLayout.NORTH);
try {
Menu_bg=ImageIO.read(new File("./image/Menu_bg.jpg"));
} catch (Exception e) {}
Menu_Jpanel=new ImagePanel(Menu_bg);
Menu_Jpanel.setLayout(new GridLayout(7,1));
Cursor myCursor=new Cursor(Cursor.HAND_CURSOR);
Menu_title=new JLabel(new ImageIcon("./image/mylibrary.jpg"),JLabel.CENTER);
Menu_Jpanel.add(Menu_title);
Menu1=new JLabel("借阅图书",new ImageIcon("image/Borrow_book.jpg"),JLabel.CENTER);
Menu1.setCursor(myCursor);
Menu1.setFont(new Font("借阅图书", 1,15));
Menu1.setEnabled(false);
Menu1.addMouseListener(this);
Menu_Jpanel.add(Menu1);
Menu2=new JLabel("预约培训",new ImageIcon("image/Pre_book.jpg"),JLabel.CENTER);
Menu2.setCursor(myCursor);
Menu2.setFont(new Font("预约培训", 1,15));
Menu2.setEnabled(false);
Menu2.addMouseListener(this);
Menu_Jpanel.add(Menu2);
Menu3=new JLabel("电子资源",new ImageIcon("image/e-resources.jpg"),JLabel.CENTER);
Menu3.setCursor(myCursor);
Menu3.setFont(new Font("电子资源", 1,15));
Menu3.setEnabled(false);
Menu3.addMouseListener(this);
Menu_Jpanel.add(Menu3);
Menu4=new JLabel("书库检索",new ImageIcon("image/DataBase_retrieval.jpg"),JLabel.CENTER);
Menu4.setCursor(myCursor);
Menu4.setFont(new Font("书库检索", 1,15));
Menu4.setEnabled(false);
Menu4.addMouseListener(this);
Menu_Jpanel.add(Menu4);
Menu5=new JLabel("好书收藏",new ImageIcon("image/collect_book.jpg"),JLabel.CENTER);
Menu5.setCursor(myCursor);
Menu5.setFont(new Font("好书收藏", 1,15));
Menu5.setEnabled(false);
Menu5.addMouseListener(this);
Menu_Jpanel.add(Menu5);
Menu6=new JLabel("个人资料",new ImageIcon("image/Personal _info.jpg"),JLabel.CENTER);
Menu6.setCursor(myCursor);
Menu6.setFont(new Font("个人资料", 1,15));
Menu6.setEnabled(false);
Menu6.addMouseListener(this);
Menu_Jpanel.add(Menu6);
inter_Jpanel.setLayout(new BorderLayout());
Search_Jpanel.setLayout(new GridLayout(2, 5,50,40));
Search_Jpanel.add(new JPanel());//起间隔作用
Search_Key=new JComboBox<>(key);
Search_Jpanel.add(Search_Key);
key_name=new JTextField(20);
Search_Jpanel.add(key_name);
Search_Button=new JButton("检索");
Search_Button.addActionListener(this);
Search_Jpanel.add(Search_Button);
Search_Jpanel.add(new JPanel());//起间隔作用
Search_Jpanel.add(new JPanel());//起间隔作用
Search_Jpanel.add(new JPanel());//起间隔作用
Search_Jpanel.add(new JPanel());//起间隔作用
Search_Jpanel.add(new JPanel());//起间隔作用
Search_Jpanel.add(new JPanel());//起间隔作用
inter_Jpanel.add(Search_Jpanel,BorderLayout.NORTH);
List_Jpanel=new Show_BookList(socket,Read_in,Write_out);
inter_Jpanel.add(List_Jpanel, BorderLayout.CENTER);
Main_Jpanel.setLayout(new BorderLayout());
Spacer_bar=new JLabel(new ImageIcon("image/spacer_bar.jpg"));
Main_Jpanel.add(Spacer_bar,BorderLayout.WEST);
Main_Jpanel.add(inter_Jpanel,BorderLayout.CENTER);
}
private void initialFrame() {
this.setTitle("图书管理系统--客户端");//设置窗体标题
Image image=new ImageIcon("./image/library_ico.jpg").getImage();
this.setIconImage(image);
Dimension scrSize=Toolkit.getDefaultToolkit().getScreenSize(); //获取屏幕长宽
this.setBounds(scrSize.width/6,scrSize.height/6,1000,700);
this.add(title_Jpanel,BorderLayout.NORTH);
this.add(Menu_Jpanel,BorderLayout.WEST);
this.add(Main_Jpanel,BorderLayout.CENTER);
this.setVisible(true);//设置可见性
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addWindowListener(mywindowadapter);
}
public WindowAdapter mywindowadapter=new WindowAdapter() {
public void windowClosing(WindowEvent e) {
try {
IOout.SendMessage(Write_out, Order_format.Exit);//通知服务器退出
} catch (IOException e1) {
e1.printStackTrace();
}
dispose();
};
};
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==this.Search_Button){//检索按键
try {
Search_Book();
} catch (IOException | ClassNotFoundException e1) {}
}
}
public void Search_Book() throws IOException, ClassNotFoundException{
List_Jpanel.Isclick_ture();
switch (Search_Key.getSelectedIndex()) {
case 0: Got_Allbook();break;
case 1:Search_Gotbook(Order_format.Callno);break;
case 2:Search_Gotbook(Order_format.bookname);break;
case 3:Search_Gotbook(Order_format.author);break;
case 4:Search_Gotbook(Order_format.publishment);break;
default:
break;
}
}
@SuppressWarnings("unchecked")
public void Got_Allbook() throws IOException, ClassNotFoundException{
IOout.SendMessage(Write_out, Order_format.All_book+key_name.getText().trim());
Vector vector=(Vector) IOin.ReceiveMessage(Read_in);
List_Jpanel.Update(vector);
}
public void Search_Gotbook(String order) throws IOException, ClassNotFoundException{
String msg=key_name.getText().trim();
if(msg.length()>0){
IOout.SendMessage(Write_out, order+msg);
Vector vector=(Vector) IOin.ReceiveMessage(Read_in);
if(vector.size()!=0)
List_Jpanel.Update(vector);
else{
List_Jpanel.clear();
JOptionPane.showMessageDialog(this,"木有查询结果!","提醒",JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(this,"输入框不能为空!","错误",JOptionPane.ERROR_MESSAGE);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if(e.getSource()==this.Menu1){
try {
IOout.SendMessage(Write_out, Order_format.User_book+this.user_ID);
Vector vector=(Vector) IOin.ReceiveMessage(Read_in);
List_Jpanel.Update(vector);
List_Jpanel.Isclick_false();
} catch (IOException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
}else if(e.getSource()==this.Menu2){
}else if(e.getSource()==this.Menu3){
}else if(e.getSource()==this.Menu4){
}else if(e.getSource()==this.Menu5){
}else if(e.getSource()==this.Menu6){
}
}
@Override
public void mouseEntered(MouseEvent e) {
if(e.getSource()==this.Menu1){
Menu1.setEnabled(true);
}else if(e.getSource()==this.Menu2){
Menu2.setEnabled(true);
}else if(e.getSource()==this.Menu3){
Menu3.setEnabled(true);
}else if(e.getSource()==this.Menu4){
Menu4.setEnabled(true);
}else if(e.getSource()==this.Menu5){
Menu5.setEnabled(true);
}else if(e.getSource()==this.Menu6){
Menu6.setEnabled(true);
}
}
@Override
public void mouseExited(MouseEvent e) {
if(e.getSource()==this.Menu1){
Menu1.setEnabled(false);
}else if(e.getSource()==this.Menu2){
Menu2.setEnabled(false);
}else if(e.getSource()==this.Menu3){
Menu3.setEnabled(false);
}else if(e.getSource()==this.Menu4){
Menu4.setEnabled(false);
}else if(e.getSource()==this.Menu5){
Menu5.setEnabled(false);
}else if(e.getSource()==this.Menu6){
Menu6.setEnabled(false);
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
}
查询功能以及借书还书功能
package Library_Client;
public class Show_BookList extends JPanel {
Socket socket;
ObjectOutputStream Write_out;
ObjectInputStream Read_in;
IO_in IOin=new IO_in();
IO_out IOout=new IO_out();
boolean Isclick;
Vector head = new Vector();
{//定义表头
head.add("书名");head.add("作者");head.add("出版社");
head.add("状态");head.add("索引号");
}
Vector data=new Vector();//定义检索出的书的基本信息
DefaultTableModel TableModel=new DefaultTableModel(data,head); //创建表格模型
JTable head_table=new JTable(TableModel){
public boolean isCellEditable(int row, int column) { //表格不可编辑
return false;
}
}; //创建Jtable对象
JScrollPane ScrollPane=new JScrollPane(head_table);//将JTable封装到滚动窗格
public Show_BookList(Socket socket,ObjectInputStream Read_in,ObjectOutputStream Write_out){
this.socket=socket;
this.Read_in=Read_in;
this.Write_out=Write_out;
this.setLayout(new BorderLayout());
head_table.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
if(e.getClickCount()==2){
if(head_table.getValueAt(head_table.getSelectedRow(), 3).toString().equals("在架上")){//判断是否已借出
Object value= head_table.getValueAt(head_table.getSelectedRow(), 0);//得到选中的单元格的值,表格中都是字符串
try {
Correct_Borrow(JOptionPane.showConfirmDialog
(null,"是否借阅 “"+value.toString()+"” 这本书?","提示", JOptionPane.YES_NO_OPTION),value.toString());
} catch (HeadlessException | IOException e1) {
e1.printStackTrace();
}
}else{
if(Isclick)
JOptionPane.showMessageDialog(null,"该书已借出!","提醒",JOptionPane.ERROR_MESSAGE);
else{
Object value= head_table.getValueAt(head_table.getSelectedRow(), 0);//得到选中的单元格的值,表格中都是字符串
try {
Correct_return(JOptionPane.showConfirmDialog
(null,"是否还 “"+value.toString()+"” 这本书?","提示", JOptionPane.YES_NO_OPTION),value.toString());
} catch (HeadlessException | IOException e1) {
e1.printStackTrace();
}
}
}
}
}
});
this.add(ScrollPane,BorderLayout.NORTH);
this.setVisible(true);
}
public void Update(Vector vector){
Vector data=new Vector();
Vector a;
for(int i=0;i();
a.addElement(vector.get(i).getBookname());
a.addElement(vector.get(i).getAuthor());
a.addElement(vector.get(i).getPublishment());
a.addElement(vector.get(i).getState());
a.addElement(vector.get(i).getCallno());
data.addElement(a);
}
TableModel.setDataVector(data,head);
head_table.updateUI();
head_table.repaint();
}
public void clear(){
Vector data=new Vector();
TableModel.setDataVector(data,head);
head_table.updateUI();
head_table.repaint();
}
public void Correct_Borrow(int a,String msg) throws IOException{
if(a==0){
msg=Order_format.Borrow_Book+msg;
IOout.SendMessage(Write_out,msg);
try {
Object ms=(Object) IOin.ReceiveMessage(Read_in);
if(ms instanceof String){//判断接收数据的类型
String m=(String)ms;
JOptionPane.showMessageDialog(this,m.substring(11),"提醒",JOptionPane.ERROR_MESSAGE);
}else
Update((Vector)ms);//刷新数据
} catch (ClassNotFoundException e) {}
}
}
public void Correct_return(int a,String msg) throws IOException{
if(a==0){
msg=Order_format.Return_Book+msg;
IOout.SendMessage(Write_out,msg);
try {
Update((Vector)IOin.ReceiveMessage(Read_in));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
public void Isclick_false(){
Isclick=false;
}
public void Isclick_ture(){
Isclick=true;
}
}
其余代码就不贴出来了,有兴趣可以自己下载!
源码下载