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

📄 basedialog.java

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

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
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 javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import librarymanagement.view.common.GBC;
/*
 * 图书管理和读者管理的父类
 */
public class BaseDialog extends JDialog {

	public JComboBox combox;//查询条件中的JConboBox
	public JLabel label;
	// private JRadioButton radioButton;
	public JTextField text;
	//构建总面板jp,查询面板panel, 按钮面板,查询条件面板
	public JPanel jp,  panel, radioPanel, jpanel;
	public JButton Btn;
	public JToolBar toolBar;//工具栏
	public JSplitPane splitPane = new JSplitPane();//分割面板
	public JTable table;//JTable表
	private String radioStr;
	//获得JRadioButton事件对象的方法方便事件BookMangementaction类的处理;
	public String selectRadioButton;
	//获得JComboBox事件对象的方法
	public String selectCombox;

	public BaseDialog() {
		initialPanel();
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		this.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight());

	}

	/**
	 * 向窗体BasePanel(图书、读者管理的父类)中加分割面板,边界布局
	 */
	public void initialPanel() {
		this.setLayout(new BorderLayout());
		splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPane.setTopComponent(buildJPanel());
		splitPane.setBottomComponent(getJTableScrollPane());
		splitPane.setOneTouchExpandable(true);
		this.add(splitPane);
	}

	// 向带滚动条的面板中加JTable表
	public JScrollPane getJTableScrollPane() {
		JScrollPane js = new JScrollPane(buildJTable());
		return js;
	}

	/**
	 * 父类的JTable
	 */
	public JTable buildJTable() {
		return null;
	}

	/**
	 * 由工具栏、查询面板组成的jp 面板,
	 * 
	 * @return
	 */
	public JPanel buildJPanel() {
		if (jp == null) {
			jp = new JPanel(new BorderLayout());
			jp.add(buildToolBar(), BorderLayout.NORTH);
			jp.add(buildJCheckPanel());
		}
		return jp;
	}

	/**
	 * 查找面板
	 * 
	 * @return
	 */
	public JPanel buildJCheckPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setLayout(new FlowLayout(FlowLayout.LEFT));
			// panel.add(createInfoPanel(),"Center");
			panel.add(buildRadioPanel());
			panel.add(buildComJPanel());
			panel.setBorder(BorderFactory.createTitledBorder("查询条件"));
		}
		return panel;
	}

	/**
	 * 查找面板中的中的ButtonGroup的面板
	 * 
	 * @return
	 */
	public JPanel buildRadioPanel() {
		if (radioPanel == null) {
			ButtonGroup group = new ButtonGroup();
			JRadioButton radioButton1 = buildRadioBtn("精确",true);
			JRadioButton radioButton2 = buildRadioBtn("模糊",false);
			group.add(radioButton1);
			group.add(radioButton2);
			radioPanel = new JPanel(new BorderLayout());
			radioPanel.add(radioButton1, BorderLayout.NORTH);
			radioPanel.add(radioButton2);
			// Rigor.addActionListener(new RadioAction(this));
			// Dark.addActionListener(new RadioAction(this));

		}
		return radioPanel;
	}
	/**
	 * JRadioButto的事件处理
	 * @param name
	 * @return
	 */

	public JRadioButton buildRadioBtn(String name,boolean select) {
		JRadioButton radioButton = new JRadioButton(name,select);
		selectRadioButton ="精确";
		radioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				selectRadioButton = e.getActionCommand();
				// System.out.print(selectRadioButton);
			}

		});
		return radioButton;
	}
/**
 * 获得JRadioButton事件对象的方法方便事件BookMangementaction类的处理;
 * @return
 */
	public String getSelectRadioButton() {
		return selectRadioButton;
	}
	/**
	 * 由填写查询条件组件的面板
	 */
	public JPanel buildComJPanel() {
		if (jpanel == null) {
			jpanel = new JPanel(new GridBagLayout());
			jpanel.add(buildCheckCombo(), new GBC(0, 1, 5, 1).setInset(5)
					.setFill(GBC.HORIZONTAL));
			jpanel.add(buildJLabel(), new GBC(7, 1));
			jpanel.add(buildJText(), new GBC(9, 1));
			Icon i1 = new ImageIcon("icons/查询.jpg");
			jpanel.add(buildBtn("查询", i1),new GBC(13,1).setInset(20));
		}
		return jpanel;
	}
  /**
   * 查询面板中的JComboBox
   * @return  combox
   */
	public JComboBox buildCheckCombo() {
		if (combox == null) {
			String[] CheckName = { "","图书编号", "存放位置", "图书名", "作者" };
			combox = new JComboBox(CheckName);
			combox.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent arg0) {
					selectCombox = combox.getSelectedItem().toString();
				}

			});
		}
		return combox;
	}
 /**
  * 获得JComboBox事件对象的方法
  * @return selectCombox
  */
	public String getSelectCombox() {
		return selectCombox;
	}

	public JLabel buildJLabel() {
		label = new JLabel("中 含有");
		return label;
	}

	public JTextField buildJText() {
		text = new JTextField(15);
		// text.setEditable(false);
		return text;
	}

	public String getTextInfo() {
		String in = text.getText();
		
		return in;
	}

	/**
	 * 工具栏
	 * 
	 * @return toolBar
	 */
	public JToolBar buildToolBar() {
		if (toolBar == null) {

			
			Icon i2 = new ImageIcon("icons/添加1.jpg");
			Icon i3 = new ImageIcon("icons/修改.jpg");
			Icon i4 = new ImageIcon("icons/删除.jpg");
			Icon i5 = new ImageIcon("icons/刷新.jpg");
			
			Icon i7 = new ImageIcon("icons/打印.jpg");
			Icon i8 = new ImageIcon("icons/Excel.jpg");
			Icon i9 = new ImageIcon("icons/退出.jpg");
			toolBar = new JToolBar();
			//toolBar.add(buildBtn("查询", i1));
			toolBar.add(buildBtn("添加", i2));
			toolBar.add(buildBtn("修改", i3));
			toolBar.add(buildBtn("删除", i4));
			toolBar.add(buildBtn("刷新", i5));
		
//			toolBar.add(buildBtn("打印", i7));
			toolBar.add(buildBtn("转Excel", i8));
			toolBar.add(buildBtn("退出", i9));


		}
		return toolBar;
	}
/**
 * 获得带文本框和图标按钮的方法
 * @param name
 * @param icon
 * @return Btn
 */
	public JButton buildBtn(String name, Icon icon) {
		Btn = new JButton(name, icon);
		return Btn;
	}
	
	
}

⌨️ 快捷键说明

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