📄 bookmanagermain.java
字号:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.Point;
import java.awt.Dimension;
import java.awt.Color;
import javax.swing.JMenu;
public class BookManagerMain extends JFrame
{
public BookManagerMain()
{
this.addWindowListener(new WindowListener(){
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowClosing(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){
BookManagerMain.this.setEnabled("else");
userLogin dlg=new userLogin(BookManagerMain.this);
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
this.setTitle("计算机系图书管理系统");
setSize(new Dimension(800, 600));
bar=new JMenuBar();
setJMenuBar(bar);
muSystem=new JMenu("系统管理");
muBookManager=new JMenu("书籍管理");
muBookManager.setFocusPainted(true);
muUserManager=new JMenu("用户管理");
muUserManager.setFocusPainted(true);
mucfManager=new JMenu("惩罚管理");
mucfManager.setFocusPainted(true);
muAllInfo=new JMenu("信息检索");
muAllInfo.setFocusPainted(true);
miuserLogin=new JMenuItem("登录");
miUserAdd=new JMenuItem("添加用户");
miUserEdit=new JMenuItem("修改用户");
miUserDel=new JMenuItem("删除用户");
miglAdd=new JMenuItem("添加管理员");
miExit=new JMenuItem("退出");
miBookAdd=new JMenuItem("添加书籍信息");
miBookEdit=new JMenuItem("修改书籍信息");
miBookDel=new JMenuItem("删除书籍信息");
miBookBorrow=new JMenuItem("借阅书籍");
miBookReturn=new JMenuItem("归还书籍");
miAllBook=new JMenuItem("书籍信息检索");
miuserList=new JMenuItem("用户信息检索");
miborrowList=new JMenuItem("借阅信息检索");
mics=new JMenuItem("惩罚信息检索");
micsAdd=new JMenuItem("惩罚添加");
micsDel=new JMenuItem("惩罚删除");
bar.add(muSystem);
bar.add(muBookManager);
bar.add(muUserManager);
bar.add(mucfManager);
bar.add(muAllInfo);
muSystem.add(miuserLogin);
muSystem.add(miExit);
miExit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
muBookManager.add(miBookBorrow);
muBookManager.add(miBookReturn);
muBookManager.addSeparator();
muBookManager.add(miBookAdd);
muBookManager.add(miBookEdit);
muBookManager.add(miBookDel);
muUserManager.add(miUserAdd);
muUserManager.add(miUserEdit);
muUserManager.add(miUserDel);
muUserManager.addSeparator();
muUserManager.add(miglAdd);
mucfManager.add(micsAdd);
mucfManager.add(micsDel);
muAllInfo.add(miAllBook);
muAllInfo.add(miuserList);
muAllInfo.add(miborrowList);
muAllInfo.add(mics);
setJMenuBar(bar);
miuserLogin.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
userLogin dlg=new userLogin(BookManagerMain.this);
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miglAdd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
glAdd dlg=new glAdd();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miUserAdd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
userAdd dlg=new userAdd();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miUserEdit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
userEdit dlg=new userEdit();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
micsAdd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
csAdd dlg=new csAdd();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
micsDel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
csDel dlg=new csDel();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miUserDel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
userDel dlg=new userDel();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miBookAdd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
BookAdd dlg=new BookAdd();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miBookEdit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
BookEdit dlg=new BookEdit();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miBookDel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
BookDel dlg=new BookDel();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miBookBorrow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
BookBorrow dlg=new BookBorrow();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miBookReturn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
BookReturn dlg=new BookReturn();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miAllBook.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
AllBook dlg=new AllBook();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miuserList.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
userList dlg=new userList();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
miborrowList.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
borrowList dlg=new borrowList();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
mics.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cs dlg=new cs();
Dimension dlgSize=dlg.getPreferredSize();
Dimension frmSize=BookManagerMain.this.getSize();
Point loc=BookManagerMain.this.getLocation();
dlg.setLocation((frmSize.width-dlgSize.width)/2+loc.x,(frmSize.height-dlgSize.height)/2+loc.y);
dlg.pack();
dlg.show();
}
});
}
public void setEnabled(String powertype){
if(powertype.equals("管理员"))
{
muUserManager.setEnabled(true);
miuserLogin.setEnabled(true);
muBookManager.setEnabled(true);
miBookBorrow.setEnabled(true);
miBookReturn.setEnabled(true);
miBookAdd.setEnabled(true);
miBookEdit.setEnabled(true);
miBookDel.setEnabled(true);
muUserManager.setEnabled(true);
miUserAdd.setEnabled(true);
miUserEdit.setEnabled(true);
miUserDel.setEnabled(true);
mucfManager.setEnabled(true);
muAllInfo.setEnabled(true);
}
else if(powertype.equals("用户"))
{
muUserManager.setEnabled(true);
miuserLogin.setEnabled(true);
muBookManager.setEnabled(true);
miBookBorrow.setEnabled(true);
miBookReturn.setEnabled(true);
miBookAdd.setEnabled(false);
miBookEdit.setEnabled(false);
miBookDel.setEnabled(false);
muUserManager.setEnabled(false);
mucfManager.setEnabled(false);
muAllInfo.setEnabled(true);
}
else
{
muUserManager.setEnabled(true);
miuserLogin.setEnabled(true);
muBookManager.setEnabled(false);
muUserManager.setEnabled(false);
mucfManager.setEnabled(false);
muAllInfo.setEnabled(false);
}
}
private JLabel label;
private JPanel panel;
private JMenuBar bar;
private JMenu muSystem;
private JMenu muBookManager;
private JMenu muUserManager;
private JMenu mucfManager;
private JMenu muAllInfo;
private JMenuItem miuserLogin;
private JMenuItem miUserAdd;
private JMenuItem miUserEdit;
private JMenuItem miUserDel;
private JMenuItem miglAdd;
private JMenuItem miExit;
private JMenuItem miBookAdd;
private JMenuItem miBookEdit;
private JMenuItem miBookDel;
private JMenuItem miBookBorrow;
private JMenuItem miBookReturn;
private JMenuItem micsAdd;
private JMenuItem micsDel;
private JMenuItem miAllBook;
private JMenuItem miuserList;
private JMenuItem miborrowList;
private JMenuItem mics;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -