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

📄 book_management.java

📁 EIS的主界面文档。适合学习。调用其他下属模块。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:


import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Vector;

public class Book_Management extends JFrame{
	private JTabbedPane main_window=new JTabbedPane();

	private int personid;
	private Connection con;
	public Book_Management(Connection con,int pid){
		
		super("Welcome to EIS");
		this.con=con;
		personid=pid;

		main_window.addTab("已借到的书本",new BorrowPanel(this.con,personid));
		main_window.addTab("已预约的书本",new PrecontractPanel(this.con,personid));
		main_window.addTab("我的书本",new MinePanel(this.con,personid));
		main_window.addTab("上EIS借书",new SearchPanel(this.con,personid));
		getContentPane().add(main_window);
		getContentPane().setVisible(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(600,600);
		show(true);
	
		
	}
	/*
	public static void main(String args[]){
		javax.swing.SwingUtilities.invokeLater(new Runnable(){
			public void run(){
				Book_Management bm=new Book_Management();				
			}
		});
				
	} 
	*/
}

class BorrowPanel extends JPanel{
	private	String command; 
	private Connection con;
	//private Statement st;
	//private ResultSet rs;
	private int person_id;
	private JTable result;
	private JButton flasher=new JButton("刷新");
	private JLabel book_id=new JLabel("书本ID");
	private Vector<String> columnNames=new Vector<String>();
	private Vector data=new Vector();
	private Vector temp=new Vector();
	public BorrowPanel(Connection con,int pid){
		this.con=con;
		person_id=pid;
		command="select BookID, BookName, BorrowTime,ReturnTime,Owner from Book where BorrowID="+Integer.toString(person_id)+" and Statement=2";
		columnNames.add("序号");
		columnNames.add("书本ID");
		columnNames.add("书本名称");
		columnNames.add("借书时间");
		columnNames.add("截至时间");
		columnNames.add("书本拥有者");
		
		try{
            Statement st=this.con.createStatement();
            ResultSet rs=st.executeQuery( command );
            System.out.println( "操作数据表成功!" );
            System.out.println( "----------------!" );
            
            while(rs.next()){
            	temp.add(rs.getRow());
                temp.add(rs.getString("BookID").trim());
                temp.add(rs.getString("BookName").trim());
                temp.add(rs.getDate("BorrowTime"));
                temp.add(rs.getDate("ReturnTime"));
                temp.add(rs.getString("Owner").trim());
                data.add(new Vector(temp));
                temp.clear();
                
            }
            rs.close();
            st.close();
            
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
        
		
		
		result=new JTable(data,columnNames);
		result.setDragEnabled(false);
		setLayout(new BorderLayout());
		JScrollPane p1=new JScrollPane(result);
		
		//p1.getViewport().setVisible(true);
		JPanel p2=new JPanel();
		p2.add(flasher);
		add(p1,BorderLayout.CENTER);
		add(p2,BorderLayout.SOUTH);
		//result.setVisible(true);
		result.setPreferredScrollableViewportSize(new Dimension(500,700));
		result.setFillsViewportHeight(true);
		
		flasher.addActionListener(new Flash());
		
		
	}
	
	private void get_result(){
		
		try{
            Statement st=this.con.createStatement();
            ResultSet rs = st.executeQuery( command );
            System.out.println( "操作数据表成功!" );
            System.out.println( "----------------!" );
            
            while(rs.next()){
            	temp.add(rs.getRow());
                temp.add(rs.getString("BookID"));
                temp.add(rs.getString("BookName"));
                temp.add(rs.getDate("BorrowTime"));
                temp.add(rs.getDate("ReturnTime"));
                temp.add(rs.getString("Owner"));
                data.add(new Vector(temp));
                temp.clear();
                
            }
            rs.close();
            st.close();
            
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
		
	}
	
	private class Flash implements ActionListener{
		public void actionPerformed(ActionEvent e){	
		    data.clear();		
			get_result();
			result.setModel(new DefaultTableModel(data,columnNames));
			result.repaint();
			result.show(true);
            
		}
	}
	
}
class PrecontractPanel extends JPanel{
	private	String command; 
	private Connection con;
	//private Statement st;
	//private ResultSet rs;
	private int person_id;
	private JTable result;
	private JButton flasher=new JButton("刷新");
	private JLabel book_id=new JLabel("书本ID");
	private Vector<String> columnNames=new Vector<String>();
	private Vector data=new Vector();
	private Vector temp=new Vector();
	public PrecontractPanel(Connection con,int pid){
		this.con=con;
		person_id=pid;
		command="select BookID, BookName, Owner, BorrowID, ReturnTime from Book where BookingID="+Integer.toString(person_id)+" and Statement=2";
        columnNames.add("序号");
		columnNames.add("预约书本ID");
		columnNames.add("预约书本名称");
		columnNames.add("书本拥有者");		
		columnNames.add("到期时间");
		
		try{
            Statement st=this.con.createStatement();
            ResultSet rs=st.executeQuery( command );
            System.out.println( "操作数据表成功!" );
            System.out.println( "----------------!" );
            
            while(rs.next()){
            	temp.add(rs.getRow());
                temp.add(rs.getString("BookID").trim());
                temp.add(rs.getString("BookName").trim());                
                temp.add(rs.getString("Owner").trim());
                temp.add(rs.getDate("ReturnTime"));
                data.add(new Vector(temp));
                temp.clear();
                
            }
            rs.close();
            st.close();
            
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
        
		
		
		result=new JTable(data,columnNames);
		result.setDragEnabled(false);
		setLayout(new BorderLayout());
		JScrollPane p1=new JScrollPane(result);
		
		//p1.getViewport().setVisible(true);
		JPanel p2=new JPanel();
		p2.add(flasher);
		add(p1,BorderLayout.CENTER);
		add(p2,BorderLayout.SOUTH);
		//result.setVisible(true);
		result.setPreferredScrollableViewportSize(new Dimension(500,700));
		result.setFillsViewportHeight(true);
		
		flasher.addActionListener(new Flash());
		
		
	}
	
	private void get_result(){
		
		try{
            Statement st=this.con.createStatement();
            ResultSet rs = st.executeQuery( command );
            System.out.println( "操作数据表成功!" );
            System.out.println( "----------------!" );
            
            while(rs.next()){
            	temp.add(rs.getRow());
                temp.add(rs.getString("BookID"));
                temp.add(rs.getString("BookName"));                                
                temp.add(rs.getString("Owner"));
                temp.add(rs.getDate("ReturnTime"));
                data.add(new Vector(temp));
                temp.clear();
                
            }
            rs.close();
            st.close();
            
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
		
	}
	
	private class Flash implements ActionListener{
		public void actionPerformed(ActionEvent e){	
		    data.clear();		
			get_result();
			result.setModel(new DefaultTableModel(data,columnNames));
			result.repaint();
			result.show(true);
            
		}
	}

}
class MinePanel extends JPanel{
	
	private	String command; 
	private Connection con;
	//private Statement st;
	//private ResultSet rs;
	private int person_id;
	private JTable result;
	private JButton flasher=new JButton("刷新");
	private JButton confirm=new JButton("确认归还");
	private JLabel book_id=new JLabel("书本ID");
	private JComboBox choose=new JComboBox();
	private JTextArea resultarea=new JTextArea();
	private Vector<String> columnNames=new Vector<String>();
	private Vector data=new Vector();
	private Vector temp=new Vector();
	public MinePanel(Connection con,int pid){
		this.con=con;
		person_id=pid;
		command="select BookID, BookName, Statement from Book where Owner="+Integer.toString(person_id);
        columnNames.add("序号");
		columnNames.add("书本ID");
		columnNames.add("书本名称");	
		columnNames.add("书本状态");
		int stmt;
		String bid;
		try{
            Statement st=this.con.createStatement();
            ResultSet rs=st.executeQuery( command );
            System.out.println( "操作数据表成功!" );
            System.out.println( "----------------!" );
            
            while(rs.next()){
            	temp.add(rs.getRow());
            	bid=rs.getString("BookID").trim();
                temp.add(bid);
                
                temp.add(rs.getString("BookName").trim());
                stmt=rs.getInt("Statement");
                if(stmt==1)
                   temp.add("可借");
                else if(stmt==2){
                	choose.addItem(bid);
                	temp.add("借出");
                }
                       
                data.add(new Vector(temp));
                temp.clear();
                
            }
            rs.close();
            st.close();
            
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
        
		
		
		result=new JTable(data,columnNames);
		result.setDragEnabled(false);
		setLayout(new BorderLayout());
		JScrollPane p1=new JScrollPane(result);
		
		//p1.getViewport().setVisible(true);
		JPanel p2=new JPanel(new GridLayout(1,4));
		p2.add(choose);
		p2.add(resultarea);
		p2.add(confirm);
		p2.add(flasher);
		add(p1,BorderLayout.CENTER);
		add(p2,BorderLayout.SOUTH);
		//result.setVisible(true);
		result.setPreferredScrollableViewportSize(new Dimension(500,700));
		result.setFillsViewportHeight(true);
		
		flasher.addActionListener(new Flash());
		confirm.addActionListener(new Return());
		
		
	}
	
	private void get_result(){
		
		try{
            Statement st=this.con.createStatement();
            ResultSet rs = st.executeQuery( command );
            System.out.println( "操作数据表成功!" );
            System.out.println( "----------------!" );
            int stmt;
            String bid;
            while(rs.next()){
                temp.add(rs.getRow());
                bid=rs.getString("BookID").trim();
                temp.add(bid);
                
                temp.add(rs.getString("BookName").trim());
                stmt=rs.getInt("Statement");
                if(stmt==1)
                   temp.add("可借");
                else if(stmt==2){
                	choose.addItem(bid);
                	temp.add("借出");
                }
                       
                data.add(new Vector(temp));
                temp.clear();
                
            }
            rs.close();
            st.close();
            
        }
        catch(Exception err){
            err.printStackTrace(System.out);
        }
		

⌨️ 快捷键说明

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