📄 librarybox.java
字号:
import java.util.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
public class Librarybox extends JFrame implements ActionListener
{
JButton b_search;
JTextField t_search;
Object a[][];
Object col[]={"书籍编号","书籍名称","出版发行","书籍作者","文理分类","书籍售价","书籍数量"};
JTable table;
JPanel pan1,pan2;
String a1,loop;
JLabel l_rs;
JRadioButton r_bookname,r_author,r_company;
ButtonGroup g_rb;
JMenuBar mainmenu;
static JMenu system,bookse,bookth,bookfo,booksex,mi_system_manger;
JMenuItem mi_system_login,mifi_system_adduser,mifi_system_moduser,mifi_system_deluser,mi_system_exit;
JMenuItem se_book_addbook,se_book_modifybook,se_book_batadd,se_book_sta;
JMenuItem th_book_borrowmsg;
JMenuItem fo_book_returnmsg;
JMenuItem fi_msglabel_borrow;
JMenuItem sex_edition;
Loginfrm frml=new Loginfrm(this,"登录窗口");
Adduser frma=new Adduser(this,"添加用户");
Mdiuser frmm=new Mdiuser(this,"修改用户");
Deluser frmd=new Deluser(this,"删除用户");
Addbookfrm frmab;Mdibookfrm frmmb;Borbookfrm frmbb;
Borlistbookfrm frmblb;Returnbookfrm frmrb;BatAdd frmbat;Statistics frmsta;
NetConn sql;
Statement sqll;
ResultSet rs;
Librarybox()
{
super("高校图书馆管理系统");
a=new Object[20][7];
table=new JTable(a,col);
b_search=new JButton("查询");
b_search.addActionListener(this);
t_search=new JTextField("",10);
r_bookname=new JRadioButton("名称",true);
r_author=new JRadioButton("作者");
r_company=new JRadioButton("出版社");
g_rb=new ButtonGroup();
g_rb.add(r_bookname);
g_rb.add(r_author);
g_rb.add(r_company);
pan1=new JPanel();
pan2=new JPanel();
pan1.add(t_search);
pan1.add(b_search);
pan1.add(r_bookname);
pan1.add(r_author);
pan1.add(r_company);
add(pan1,BorderLayout.NORTH);
add(new JScrollPane(table),BorderLayout.CENTER);
l_rs=new JLabel("高校图书馆管理系统");
pan2.add(l_rs);
add(pan2,BorderLayout.SOUTH);
sql=new NetConn();
mainmenu=new JMenuBar();
system=new JMenu("系统管理");
mi_system_login=new JMenuItem("用户登录");
mi_system_manger=new JMenu("用户管理");
mifi_system_adduser=new JMenuItem("添加用户");
mifi_system_moduser=new JMenuItem("修改用户");
mifi_system_deluser=new JMenuItem("删除用户");
mi_system_manger.add(mifi_system_adduser);
mi_system_manger.add(mifi_system_moduser);
mi_system_manger.add(mifi_system_deluser);
mi_system_exit=new JMenuItem("退出");
mi_system_login.addActionListener(this);
mi_system_exit.addActionListener(this);
mifi_system_adduser.addActionListener(this);
mifi_system_moduser.addActionListener(this);
mifi_system_deluser.addActionListener(this);
system.add(mi_system_login);
system.add(mi_system_manger);
system.addSeparator();
system.add(mi_system_exit);
mainmenu.add(system);
bookse=new JMenu("书籍管理" );
se_book_addbook=new JMenuItem("添加书籍");
se_book_batadd=new JMenuItem("批量添加");
se_book_modifybook=new JMenuItem("修改书籍");
se_book_addbook.addActionListener(this);
se_book_batadd.addActionListener(this);
se_book_modifybook.addActionListener(this);
bookse.add(se_book_addbook);
bookse.add(se_book_batadd);
bookse.add(se_book_modifybook);
mainmenu.add(bookse);
bookth=new JMenu("借阅管理" );
th_book_borrowmsg=new JMenuItem("新书借阅");
fi_msglabel_borrow=new JMenuItem("借阅情况表");
se_book_sta=new JMenuItem("信息统计");
th_book_borrowmsg.addActionListener(this);
fi_msglabel_borrow.addActionListener(this);
se_book_sta.addActionListener(this);
bookth.add(th_book_borrowmsg);
bookth.add(fi_msglabel_borrow);
bookth.add(se_book_sta);
mainmenu.add(bookth);
bookfo=new JMenu("还书管理");
fo_book_returnmsg=new JMenuItem("还书操作");
fo_book_returnmsg.addActionListener(this);
bookfo.add(fo_book_returnmsg);
mainmenu.add(bookfo);
booksex=new JMenu("帮助");
sex_edition=new JMenuItem("关于");
sex_edition.addActionListener(this);
booksex.add(sex_edition);
mainmenu.add(booksex);
this.setJMenuBar(mainmenu);
setBounds(0,0,550,350);
this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="退出")
{
dispose();
System.exit(0);
}
else if(e.getActionCommand()=="添加用户")
{
frma.setVisible(true);
}
else if(e.getActionCommand()=="用户登录")
{
this.setVisible(false);
this.dispose();
frml.setVisible(true);
}
else if(e.getActionCommand()=="修改用户")
{
frmm.setVisible(true);
}
else if(e.getActionCommand()=="删除用户")
{
frmd.setVisible(true);
}
else if(e.getActionCommand()=="添加书籍")
{
frmab=new Addbookfrm();
frmab.setVisible(true);
}
else if(e.getActionCommand()=="批量添加")
{
frmbat=new BatAdd();
frmbat.setVisible(true);
}
else if(e.getActionCommand()=="修改书籍")
{
frmmb=new Mdibookfrm();
frmmb.setVisible(true);
}
else if(e.getActionCommand()=="新书借阅")
{
frmbb=new Borbookfrm();
frmbb.setVisible(true);
}
else if(e.getActionCommand()=="还书操作")
{
frmrb=new Returnbookfrm();
frmrb.setVisible(true);
}
else if(e.getActionCommand()=="借阅情况表")
{
frmblb=new Borlistbookfrm();
frmblb.setVisible(true);
}
else if(e.getActionCommand()=="信息统计")
{
frmsta=new Statistics();
frmsta.setVisible(true);
}
else if(e.getActionCommand()=="关于")
{
JOptionPane.showMessageDialog(null,"版权所有:翟楚敬\nVer1.00\n2008.05","关于",JOptionPane.INFORMATION_MESSAGE);
}
else if(e.getSource()==b_search)
{
try
{
int i=0;
sqll=sql.connect();
for(int x=0;x<table.getRowCount();x++)
{
for(int y=0;y<7;y++)
{
while(a[x][y]!="")
{
a[x][y]="";
}
}
}
if(r_bookname.isSelected())
{
loop="bookname";
}
else if(r_author.isSelected())
{
loop="author";
}
else if(r_company.isSelected())
{
loop="company";
}
a1="'"+"%"+t_search.getText().trim()+"%"+"'";
String temp="select * from books where "+loop+" like "+a1;
rs=sqll.executeQuery(temp);
while(rs.next())
{
a[i][0]=rs.getString(1);a[i][1]=rs.getString(2);a[i][2]=rs.getString(3);a[i][3]=rs.getString(4);a[i][5]=rs.getString(5);
a[i][6]=rs.getString(6);a[i][4]=rs.getString(7);
i++;
}
l_rs.setText("查询了"+i+"条记录!");
table.selectAll();
table.clearSelection();
}catch(SQLException e2){
System.out.println(e2);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -