import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseListener;
import java.awt.print.PrinterException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.StreamCorruptedException
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.table.DefaultTableCellRenderer
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
public class LibraryMainF
{
private static final long serialVersionUID = 1L;
public LibraryMainF()
{
super("图书管理系统—主界面","Library.png",850,600);
//设置系统托盘
TrayIcon trayIcon =null;
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
//设置系统图标显示的右键菜单
PopupMenu popup = new PopupMenu();
MenuItem exit_pop = new MenuItem("退出");
MenuItem showMainF_pop = new MenuItem("显示主界面");
exit_pop.addActionListener(listener);
showMainF_pop.addActionListener(listener);
popup.add(showMainF_pop);
popup.addSeparator();
popup.add(exit_pop);
trayIcon
trayIcon.addActionListener(listener);
//为托盘添加鼠标事件 当单击或者双击系统托盘图标时
trayIcon.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e)
{
// 当单击左键时将主界面设为可见
if(e.getButton()==MouseEvent.BUTTON1)
LibraryMainF.this.setVisible(true);
}
public void mouseEntered(MouseEvent e1) {
}
public void mouseExited(MouseEvent e2) {
}
public void mousePressed(MouseEvent e3) {
}
public void mouseReleased(MouseEvent e4) {
}
});
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
if (trayIcon != null) {
trayIcon.setImage(Toolkit.getDefaultToolkit().getImage("library_tray.png"));
}
//添加设置菜单
JMenuBar bar = new JMenuBar();
JMenu menu_book = new JMenu("图书");
JMenu menu_edit = new JMenu("编辑");
JMenu menu_help = new JMenu("帮助");
this.setJMenuBar(bar);
bar.add(menu_book);
bar.add(menu_edit);
bar.add(menu_help);
menuItem_add = new JMenuItem("添书(A)",new ImageIcon("add.png"));
menuItem_add.setMnemonic('A');
//设置加速键
menuItem_add.setAccelerator(
//添加监听器
menuItem_add.addActionListener(listener);
menuItem_add_class = new JMenuItem("添类(C)",new ImageIcon("add_class.png"));
menuItem_add_class.setMnemonic('C');
//设置加速键
menuItem_add_class.setAccelerator(
//添加监听器
menuItem_add_class.addActionListener(listener);
menuItem_search = new JMenuItem("查询(S)",new ImageIcon("search.png"));
menuItem_search.setMnemonic('S');
menuItem_search.setAccelerator(
menuItem_del = new JMenuItem("借出(B)",new ImageIcon("del.png"));
menuItem_del.setMnemonic('B');
menuItem_del.setAccelerator(
menuItem_del.addActionListener(listener);
menuItem_print = new JMenuItem("打印(P)",new ImageIcon("print.png"));
menuItem_print.setMnemonic('P');
menuItem_print.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_P,
InputEvent.CTRL_MASK));
menuItem_print.addActionListener(listener);
menuItem_exit = new JMenuItem("退出(E)",new ImageIcon("exit.png"));
menuItem_exit.setMnemonic('E');
menuItem_exit.setAccelerator(
menuItem_exit.addActionListener(listener);
menu_book.add(menuItem_add);
menu_book.add(menuItem_add_class);
menu_book.add(menuItem_search);
menu_book.add(menuItem_del);
menu_book.add(menuItem_print);
menu_book.addSeparator();
menu_book.add(menuItem_exit);
JMenuItem menuItem_edit_passW = new JMenuItem("改密(W)",new ImageIcon("edit_paasW.png"));
menuItem_edit_passW.setMnemonic('W');
menuItem_edit_passW.setAccelerator(
menuItem_edit_passW.addActionListener(listener);
JMenuItem menuItem_help = new JMenuItem("帮助文档(H)",new ImageIcon("help.png"));
menuItem_help.setMnemonic('S');
menuItem_help.setAccelerator(
menuItem_help.addActionListener(listener);
JMenuItem menuItem_about = new JMenuItem("关于(T)",new ImageIcon("about.png"));
menuItem_about.setMnemonic('T');
menuItem_about.setAccelerator(
menuItem_about.addActionListener(listener);
menu_help.add(menuItem_help);
menu_help.addSeparator();
menu_help.add(menuItem_about);
this.setLayout(new BorderLayout());
JPanel northPanel = new JPanel();
JPanel southPanel = new JPanel();
this.add(northPanel,BorderLayout.NORTH);
this.add(southPanel,BorderLayout.CENTER);
northPanel.setLayout(new BorderLayout());
southPanel.setLayout(new BorderLayout());
//设置工具箱
JToolBar toolBar = new JToolBar();
toolBar.setEnabled(false);
JButton button_add =new JButton(new ImageIcon("add.png"));
button_add.setToolTipText("添书");
button_add.setActionCommand("添书(A)");
toolBar.add(button_add);
button_add.addActionListener(listener);
JButton button_add_class = new JButton(new ImageIcon("add_class.png"));
button_add_class.setToolTipText("添类");
button_add_class.setActionCommand("添类(C)");
toolBar.add(button_add_class);
button_add_class.addActionListener(listener);
JButton button_search =new JButton(new ImageIcon("search.png"));
button_search.setToolTipText("查询");
button_search.setActionCommand("查询(S)");
toolBar.add(button_search);
button_search.addActionListener(listener);
JButton button_del =new JButton(new ImageIcon("del.png"));
button_del.setToolTipText("借出");
button_del.setActionCommand("借出(B)");
toolBar.add(button_del);
button_del.addActionListener(listener);
JButton button_print = new JButton(new ImageIcon("print.png"));
button_print.setToolTipText("打印");
button_print.setActionCommand("打印(P)");
toolBar.add(button_print);
button_print.addActionListener(listener);
JButton button_refresh =new JButton(new ImageIcon("refresh.png"));
button_refresh.setToolTipText("刷新");
button_refresh.setActionCommand("刷新(R)");
toolBar.add(button_refresh);
button_refresh.addActionListener(listener);
northPanel.add(toolBar,BorderLayout.WEST);
//添加右键菜单
pop = new JPopupMenu();
southPanel.setComponentPopupMenu(pop);
pop_add = new JMenuItem("添书(A)",new ImageIcon("add.png"));
pop_add.addActionListener(listener);
pop_add_class = new JMenuItem("添类(C)");
pop_add_class.addActionListener(listener);
pop_search = new JMenuItem("查询(S)",new ImageIcon("search.png"));
pop_search.addActionListener(listener);
pop_del = new JMenuItem("借出(B)",new ImageIcon("del.png"));
pop_del.addActionListener(listener);
pop_exit = new JMenuItem("退出(E)",new ImageIcon("exit.png"));
pop_exit.addActionListener(listener);
pop.add(pop_add);
pop.add(pop_search);
pop.add(pop_del);
pop.add(pop_exit);
southPanel.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent event) {
}
public void mouseEntered(MouseEvent event) {
}
public void mouseExited(MouseEvent event) {
}
}
public void mouseReleased(MouseEvent event) {
if(pop.isPopupTrigger(event))
}
});
//创建 图书分类的下拉列表
File file_Library= new File("E:\\图书管理系统\\分类");
file_class = file_Library.listFiles();
comBo= new JComboBox(file_class);
comBo.setSelectedItem("E:\\图书管理系统\\分类\\文学");
comBo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
//
//
//
//
//
}
JOptionPane.showConfirmDialog(pop_add_class, label_result,"图书管理系统-加添分类—输入为空", JOptionPane.INFORMATION_MESSAGE,JOptionPane.OK_OPTION, new ImageIcon("null.png"));
JOptionPane.showConfirmDialog(pop_add_class, label_result,"图书管理系统-分类已存在", JOptionPane.WARNING_MESSAGE,JOptionPane.OK_OPTION , new ImageIcon("result.png"));
try {
FileWriter fo = new FileWriter(f_book);
String str = "";
fo.write(str);
fo.close();
} catch (IOException e1) {
e1.printStackTrace();
}
//
try {
FileOutputStream fo = new FileOutputStream(f_book_num);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}catch (IOException e5) {
System.out.println("初始化写入异常");
e5.printStackTrace();
}
JLabel label_result = new JLabel(selection+"分类创建成功!!");
JOptionPane.showConfirmDialog(pop_add_class, label_result,"图书管理系统-添加成功", JOptionPane.INFORMATION_MESSAGE,JOptionPane.OK_OPTION, new ImageIcon("succes.png"));
table_MainF.print();
} catch (PrinterException e1) {
e1.printStackTrace();
}
{
}
private static final long serialVersionUID = 1L;
public
if(row%2==0)
{
this.setBackground(Color.PINK);
}else
this.setBackground(Color.WHITE);
//
//
try {
FileInputStream fi = new FileInputStream(file_book_num);
ObjectInputStream oi = new ObjectInputStream(fi);
System.out.println(num);
num =oi.readInt();
System.out.println(num);
fi.close();
catch (FileNotFoundException e1) {
e1.printStackTrace();
}catch(InvalidClassException
{
e4.printStackTrace();
}catch(StreamCorruptedException
{
e5.printStackTrace();
}
catch (IOException e1) {
e1.printStackTrace();
}
if(num!=0){
// 读取书籍信息的文件
File file_book_info = new File("E:\\图书管理系统\\分类\\书法\\bookinfo.dat");
try {
FileInputStream fis = new FileInputStream(file_book_info);
ObjectInputStream ois = new ObjectInputStream(fis);
{
// 将书籍数据遍历 存放到temp数组中 然后传入data
model_default
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}catch (FileNotFoundException e2) {
e2.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}
if(num==0)
{
model_default = new DefaultTableModel();
Object[] temp = new Object[]{"","","","","",""};
data[0]= temp;
model_default
}
return model_default ;
private File[] file_class ;
private JTable table_MainF;
private JMenuItem menuItem_add;
private JMenuItem menuItem_search ;
private JMenuItem menuItem_del;
private JMenuItem menuItem_print;
private JMenuItem menuItem_exit ;
private JMenuItem pop_add;//右键菜单
private JMenuItem pop_add_class;
private JMenuItem pop_search;
private JMenuItem pop_del;
private JMenuItem pop_exit;
private JPopupMenu pop ;
private JScrollPane js;
private JComboBox comBo;
;
private Book book_main;
private TableModel model;
TableModel model_default;
private Object[][] book;
private Object [][] data ;
private int num =0;
private String str_null ="";
}