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

📄 returnbook.java

📁 JAVA图书管理软件源码,是我师兄亲自参与编的毕业设计
💻 JAVA
字号:
package com.ivan.menu;

import java.awt.Font;
import java.awt.Rectangle;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.ImageIcon;

public class ReturnBook extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JTextField jTextField = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	private JButton jButton = null;
	private JButton jButton1 = null;
	private JLabel jLabel2 = null;

	/**
	 * This is the default constructor
	 */
	public ReturnBook() {
		super();
		initialize();
	}

	
	public ReturnBook getReturnPanel()
	{
		return this;
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabel2 = new JLabel();
		jLabel2.setBounds(new Rectangle(465, 30, 47, 56));
		jLabel2.setIcon(new ImageIcon(getClass().getResource("/image/n04.gif")));
		jLabel2.setText("");
		jLabel1 = new JLabel();
		jLabel1.setBounds(new Rectangle(17, 57, 77, 27));
		jLabel1.setText("   图 书 编 号");
		jLabel = new JLabel();
		jLabel.setBounds(new Rectangle(219, 9, 121, 29));
		jLabel.setFont(new Font("Dialog", Font.BOLD, 16));
		jLabel.setText("   还  书  管  理");
		this.setSize(604, 334);
		this.setLayout(null);
		this.add(jLabel, null);
		this.add(jLabel1, null);
		this.add(getJTextField(), null);
		this.add(getJScrollPane(), null);
		this.add(getJButton(), null);
		this.add(getJButton1(), null);
		this.add(jLabel2, null);
	}


	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(104, 58, 111, 24));
			
			jTextField.addKeyListener(new java.awt.event.KeyAdapter()
			{
				public void keyReleased(java.awt.event.KeyEvent e)
				{
					if (jTextField.getText().length() == 9) 
					{

						DefaultTableModel mode = getMode();
						refrashTable(jTextField.getText(), mode);
						jTextField.setText("");
					}
				}
			});
		}
		return jTextField;
	}

	
	private void refrashTable(String bookid,DefaultTableModel mode)
	{
		//initTable(mode);
		
		Vector<String> v = QueryBook.getBorrowInfo(bookid);
		
		if(v!=null)      
		    mode.addRow(v);
		else
			JOptionPane.showMessageDialog(null, "查无此书或此书暂不可还!");
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(26, 107, 576, 161));
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}


	/**
	 * This method initializes jTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private DefaultTableModel getMode()
	{
		DefaultTableModel mode = (DefaultTableModel) jTable.getModel();
		return mode;
	}
	private JTable getJTable()
	{
		if (jTable == null)
		{
			jTable = new JTable();
			DefaultTableModel mode=getMode();
			mode.addColumn("图书编号");
			mode.addColumn("图书书名");
			mode.addColumn("图书作者");
			mode.addColumn("借出时间");
			mode.addColumn("读者编号");
			mode.addColumn("读者姓名");
			mode.addColumn("超期天数");
			mode.addColumn("超期罚款");
		}
		return jTable;
	}


	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(260, 290, 109, 26));
			jButton.setText("还书入库");
			
			jButton.addActionListener(new java.awt.event.ActionListener() 
			{
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					Vector<String[]> v = new Vector<String[]>();
                    DefaultTableModel mode=getMode();					
					int count = mode.getRowCount();
					
					for(int i=0;i<count;i++)
					{
						String[] value = new String[5];
						value[0]=mode.getValueAt(i, 0).toString();//bookid
						value[1]=mode.getValueAt(i, 3).toString();//borrow time
						value[2]=mode.getValueAt(i, 4).toString();//reader id
						value[3]=mode.getValueAt(i, 6).toString();//out day
						value[4]=mode.getValueAt(i, 7).toString();//out money
						
						v.add(value);
					}
						
					if(ReturnAction.returnBook(v))
					{
						JOptionPane.showMessageDialog(null, "成功归还!");
						initTable(mode);
					}
					else
						JOptionPane.showMessageDialog(null, "运行错误!");
				}
			});
		}
		return jButton;
	}
	private void initTable(DefaultTableModel mode)
	{
		int count=mode.getRowCount();
		for(int row=0;row<count;row++)
			mode.removeRow(0);
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(434, 288, 91, 27));
			jButton1.setText("取消");
		}
		return jButton1;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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