⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchbooks.java

📁 一个简单的图书馆的管理系统,该系统主要是针对学校的图书馆而做的
💻 JAVA
字号:
package librarymanagement.view.dialog;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import librarymanagement.action.dialogAction.SearchBookAction;
import librarymanagement.view.common.Appreance;
import librarymanagement.view.common.ButtonCommon;
import librarymanagement.view.common.CenterLoction;
import librarymanagement.view.common.CommonTable;
/**
 * 构建图书查询对话框
 * @author 虎兴龙
 *
 */
public class SearchBooks extends JDialog {
	public static SearchBooks instance;
	private JSplitPane split;
	// 保存查找数据的表
	private JTable table;
	public JTextField bookIdT, bookNameT, authorT;
	private JCheckBox bookIdC, bookNameC, authorC;

	public  SearchBooks() {
		super();
		new Appreance(1);
		this.setTitle("图书查询借阅");
		this.setSize(900, 700);
		CenterLoction.locateCenter(this);
		this.setLayout(new BorderLayout());
		this.add(buildSplitPane());
	}

	
public JSplitPane buildSplitPane() {
		if (split == null) {
			split = new JSplitPane();
			split.setTopComponent(buildFindPanel());
			split.setBottomComponent(getJTableScrollPane());
			split.setOrientation(JSplitPane.VERTICAL_SPLIT);
		}
		return split;
	}

	private JScrollPane getJTableScrollPane() {
		JScrollPane p = new JScrollPane(buildTable());
		return p;
	}
  /**
   * 构建表
   * @return 返回一个JTable对象
   */
	public  JTable buildTable() {
		String[] titles = { "图书编号", "图书名称", "所属类别", "作者", 
				       "出版社","版本", "存放位置","价格","图书总数", "在馆数量",};
		Object[][] data = {};
		JTable table = new CommonTable(titles, data);
		((CommonTable) table).setColumnSize(4, 150);
		((CommonTable) table).setColumnSize(7, 150);
		return table;
	}
  /**
   * 构建查询面板
   * @return 返回一个JPanel对象
   * @see buildFindInfoPanel()
   * @see  buildBtnPanel()
   */
	public JPanel buildFindPanel() {
		JPanel panel = new JPanel();
		panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		panel.add(buildFindInfoPanel());
		panel.add(buildBtnPanel());
		panel.setBorder(BorderFactory.createTitledBorder("查找面板"));
		return panel;
	}

	private JPanel buildBtnPanel() {
		JPanel jp = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
		ImageIcon i1 = new ImageIcon("img/toolbarimg/查询.jpg");
		ImageIcon i2 = new ImageIcon("img/toolbarimg/刷新.jpg");
		ImageIcon i3 = new ImageIcon("img/Dialogimg/导出Excel.jpg");
		ImageIcon i4 = new ImageIcon("img/Dialogimg/退出Dialog.jpg");
		jp.add(buildBtn("查询", i1));
		jp.add(buildBtn("刷新", i2));
		//jp.add(buildBtn("导出表", i3));
		jp.add(buildExitBtn("退出", i4));
		return jp;
	}

	public JPanel buildFindInfoPanel() {
		JPanel p = new JPanel(new GridLayout(4, 2));
		
		p.add(new JLabel("请选择您要查询的书目类别:"));
		p.add(buildCombobox());
		initTextField();
		p.add(buildBookIdCheck());
		p.add(bookIdT);
		p.add(buildBookNameCheck());
		p.add(bookNameT);
		p.add(buildauthorCheck());
		p.add(authorT);
		return p;
	}
    public JComboBox buildCombobox(){
    	String[] s = { "建筑学类", "矿物学类", "材料学类", "文学类", "奇闻异事类", "社会学类", "化学类",
				"物理学类", "数学类", "哲学类", "自然科学类", "医学类" };
    	JComboBox box = new JComboBox(s);
    	return box;
    }
	public  JCheckBox buildBookIdCheck() {
		if (bookIdC == null) {
			bookIdC = new JCheckBox("按图书编号查询");
			bookIdC.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent e) {
					if (bookIdC.isSelected()) {
						bookIdT.setEditable(true);
					} else {
						bookIdT.setText("");
						bookIdT.setEditable(false);
					}

				}

			});
		}
		return bookIdC;
	}

	public  JCheckBox buildBookNameCheck() {
		if (bookNameC == null) {
			bookNameC = new JCheckBox("按图书名称查询");
			bookNameC.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent e) {
					if (bookNameC.isSelected()) {
						bookNameT.setEditable(true);
					} else {
						bookNameT.setText("");
						bookNameT.setEditable(false);
					}

				}

			});
		}
		return bookNameC;
	}

	public JCheckBox buildauthorCheck() {
		if (authorC == null) {
			authorC = new JCheckBox("按图书作者查询");
			authorC.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent e) {
					if (authorC.isSelected()) {
						authorT.setEditable(true);
					} else {
						authorT.setText("");
						authorT.setEditable(false);
					}

				}

			});
		}
		return authorC;
	}

	public void initTextField() {
		bookIdT = new JTextField(16);
		bookNameT = new JTextField(16);
		authorT = new JTextField(16);
		bookIdT.setEditable(false);
		bookNameT.setEditable(false);
		authorT.setEditable(false);
	}

	/*
	 * private JTextField buildTextFeild(){ JTextField t = new JTextField(20);
	 * return t; }
	 */
	/**
	 * 
	 * @param name
	 *            按钮名称
	 * @param icon
	 *            按钮图片
	 * @return
	 */
	private JButton buildBtn(String name, Icon icon) {
		JButton b = new ButtonCommon(name, icon);
		b.setActionCommand(name);
		b.addActionListener(new SearchBookAction(this));
		return b;
	}
  /**
   * 单独构建退出按钮,直接添加退出事件
   * @param name 按钮名称
   * @param icon 按钮图片
   * @return 返回一个JButton对象
   */
	private JButton buildExitBtn(String name, Icon icon) {
		JButton bt = new ButtonCommon(name, icon);
		bt.setActionCommand(name);
		bt.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				dispose();

			}
		});
		return bt;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -