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

📄 membersinformation.java

📁 图书管理系统v1.0是使用JAVA语言开发的解决图书基本管理的一个应用程序。 该系统能够实现简单的图书和用户管理
💻 JAVA
字号:
package lib;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
/**
 *A public class
 */
public class MembersInformation extends JInternalFrame {
	/***************************************************************************
	 ***      declaration of the private variables used in the program       ***
	 ***************************************************************************/

	//for creating the North Panel
	private JPanel northPanel = new JPanel();
	//for creaing the North Label
	private JLabel northLabel = new JLabel("用户信息");

	//for creating the Center Panel
	private JPanel centerPanel = new JPanel();
	//for creating the edit Panel
	private JPanel memberIDPanel = new JPanel();
	//for creating the edit information Panel
	private JPanel memberIDInformationPanel = new JPanel();
	//for creating the edit label panel
	private JPanel memberIDInformationLabelPanel = new JPanel();
	//for creating the edit textField panel
	private JPanel memberIDInformationTextFieldPanel = new JPanel();
	//for creating the edit button panel
	private JPanel memberIDButtonPanel = new JPanel();

	//for creating the label
	private JLabel memberIDLabel = new JLabel("用户ID: ");
	//for creating the textField
	private JTextField memberIDTextField = new JTextField(25);
	//for creating the button
	private JButton memberIDButton = new JButton("确定");

	//for creating the information Panel
	private JPanel informationPanel = new JPanel();
	//for creating an Internal Panel in the center panel
	private JPanel informationLabelPanel = new JPanel();
	//for creating an array of JLabel
	private JLabel[] informationLabel = new JLabel[6];
	//for creating an array of String
	private String[] informaionString = {" 学号: "," 姓名: ", " 电子邮件地址: ", " 专业: ", " 欠款:"," 到期时间: "};
	//for creating an Internal Panel in the center panel
	private JPanel informationTextFieldPanel = new JPanel();
	//for creating an array of JTextField
	private JTextField[] informationTextField = new JTextField[6];
	//for creating an Internal Panel in the center panel
	private JPanel InformationButtonPanel = new JPanel();
	//for creating a button
	private JButton fButton = new JButton(new ImageIcon(ClassLoader.getSystemResource("images/next.gif")));
	private JButton bButton = new JButton(new ImageIcon(ClassLoader.getSystemResource("images/before.gif")));
	private JButton recordButton = new JButton("显示借书纪录");

	//for creating the South Panel
	private JPanel southPanel = new JPanel();
	//for creating a button
	private JButton exitButton = new JButton("退出",new ImageIcon(ClassLoader.getSystemResource("images/exit.gif")));

	//create objects from another classes for using them in the ActionListener
	private Members member;
	//for creating an array of string to store the data
	private String[] data;
	private boolean found = false; 
	//for checking the information from the text field
		//for checking the information from the text field
	private boolean isEditCorrect() {
		if (memberIDTextField.getText().equals(""))
			return false;
		return true;
	}

	//for setting the array of JTextField & JPasswordField to null
	
	//constructor of addMembers
	public MembersInformation() {
		//for setting the title for the internal frame
		super("用户信息", false, true, false, true);
		//for setting the icon
		setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Information16.gif")));
		//for getting the graphical user interface components display area
		Container cp = getContentPane();

		//for setting the layout
		northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		//for setting the font
		northLabel.setFont(new Font("Default", Font.BOLD, 14));
		//for adding the label to the panel
		northPanel.add(northLabel);
		//for adding the panel to the container
		cp.add("North", northPanel);

		//for setting the layout
		centerPanel.setLayout(new BorderLayout());
		//for setting the layout
		memberIDPanel.setLayout(new BorderLayout());
		//for setting the border to the panel
		memberIDPanel.setBorder(BorderFactory.createTitledBorder("用户ID: "));
		//for setting the layout
		memberIDInformationPanel.setLayout(new BorderLayout());
		//for setting the layout
		memberIDInformationLabelPanel.setLayout(new GridLayout(1, 1, 1, 1));
		//for adding the label to the panel
		memberIDInformationLabelPanel.add(memberIDLabel);
		//for setting the font to the label
		memberIDLabel.setFont(new Font("Default", Font.BOLD, 13));
		//for adding the editInformationLabelPanel to the editInformationLabel
		memberIDInformationPanel.add("West", memberIDInformationLabelPanel);
		//for setting the layout
		memberIDInformationTextFieldPanel.setLayout(new GridLayout(1, 1, 1, 1));
		//for adding the textField to the panel
		memberIDInformationTextFieldPanel.add(memberIDTextField);
		//for setting the font to the textField
		memberIDTextField.setFont(new Font("Default", Font.PLAIN, 13));
		//for adding the editInformationTextField to the editInformationPanel
		memberIDInformationPanel.add("East", memberIDInformationTextFieldPanel);
		//for adding the editInformationPanel to the editPanel
		memberIDPanel.add("North", memberIDInformationPanel);
		//for setting the layout
		memberIDButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		//for adding the button to the panel
		memberIDButtonPanel.add(memberIDButton);
		//for setting the fonr to the button
		memberIDButton.setFont(new Font("Default", Font.BOLD, 13));
		//for adding the editInformationButtonPanel to the editPanel
		memberIDPanel.add("Center", memberIDButtonPanel);
		//for adding the editPanel to the centerPanel
		centerPanel.add("North", memberIDPanel);

		//for setting the layout
		informationPanel.setLayout(new BorderLayout());
		//for setting the border to the panel
		informationPanel.setBorder(BorderFactory.createTitledBorder("用户信息: "));
		//for setting the layout
		informationLabelPanel.setLayout(new GridLayout(7, 1, 1, 1));
		//for setting the layout
		informationTextFieldPanel.setLayout(new GridLayout(7, 1, 1, 1));
		/***********************************************************************
		 * for adding the strings to the labels, for setting the font		   *
		 * and adding these labels to the panel.							   *
		 * finally adding the panel to the container						   *
		 ***********************************************************************/
		for (int i = 0; i < informationLabel.length; i++) {
			informationLabelPanel.add(informationLabel[i] = new JLabel(informaionString[i]));
			informationLabel[i].setFont(new Font("Default", Font.BOLD, 13));
		}
		//for adding the panel to the centerPanel
		informationPanel.add("West", informationLabelPanel);

		/***********************************************************************
		 * for adding the JTextField and JPasswordField to the panel and       *
		 * setting the font to the JTextField and JPasswordField. Finally      *
		 * adding the panel to the centerPanel                                 *
		 ***********************************************************************/
		for (int i = 0; i < informationLabel.length; i++) {
			informationTextFieldPanel.add(informationTextField[i] = new JTextField(25));
			informationTextField[i].setFont(new Font("Default", Font.PLAIN, 13));
			informationTextField[i].setEditable(false);
		}
		informationPanel.add("East", informationTextFieldPanel);

		/***********************************************************************
		 * for setting the layout for the panel,setting the font for the button*
		 * and adding the button to the panel.								   *
		 * finally adding the panel to the container						   *
		 ***********************************************************************/
		InformationButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		fButton.setFont(new Font("Default", Font.BOLD, 13));
	    bButton.setFont(new Font("Default", Font.BOLD, 13));
	    recordButton.setFont(new Font("Default", Font.BOLD, 13));
		InformationButtonPanel.add(bButton);
		InformationButtonPanel.add(fButton);
		InformationButtonPanel.add(recordButton);
		
		informationPanel.add("South", InformationButtonPanel);
		centerPanel.add("Center", informationPanel);
		cp.add("Center", centerPanel);

		/***********************************************************************
		 * for setting the layout for the panel,setting the font for the button*
		 * adding the button to the panel & setting the border.				   *
		 * finally adding the panel to the container						   *
		 ***********************************************************************/
		southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		exitButton.setFont(new Font("Default", Font.BOLD, 13));
		southPanel.add(exitButton);
		southPanel.setBorder(BorderFactory.createEtchedBorder());
		cp.add("South", southPanel);
		memberIDButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				if (!memberIDTextField.getText().equals("")) {
					member = new Members();
					member.connection("SELECT * FROM Members WHERE MemberID = " + memberIDTextField.getText());
					int memberID = member.getMemberID();
					if (memberID != 0) {
					    found = true;
					    informationTextField[0].setText(Integer.toString(member.getID()));
					    informationTextField[1].setText(member.getName());
					    informationTextField[2].setText(member.getEmail());
					    informationTextField[3].setText(member.getMajor());
					    informationTextField[4].setText(member.getMoney()+"");
						informationTextField[5].setText(member.getExpired() + "");
					}
					else {
					    found = false;
						JOptionPane.showMessageDialog(null, "没有匹配的用户!", "出错", JOptionPane.ERROR_MESSAGE);
						memberIDTextField.setText(null);
					}
				}
				else{
				    found = false;
					JOptionPane.showMessageDialog(null, "请将信息填写完整", "警告", JOptionPane.WARNING_MESSAGE);
				}
			}
		});
		bButton.addActionListener(new ActionListener (){
		    public void actionPerformed(ActionEvent ae){
		        if(found) findBefore(Integer.parseInt(memberIDTextField.getText()));
		    }
		});
		fButton.addActionListener(new ActionListener(){
		    public void actionPerformed(ActionEvent ae){
		        if(found) findAfter(Integer.parseInt(memberIDTextField.getText()));
		    }
		});
		recordButton.addActionListener(new ActionListener(){
		    public void actionPerformed(ActionEvent ae){
		        if(found) printRecord();
		    }
		});

		//for adding the action listener for the button to dispose the frame
		exitButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				dispose();
			}
		});
		//for setting the visible to true
		setVisible(true);
		//show the internal frame
		pack();
	}
	private void findBefore(int ID){
	   try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch (ClassNotFoundException cnfe) {
			System.out.println("MembersInformation.java\n" + cnfe.toString());
		}
		catch (Exception e) {
			System.out.println("MembersInformation.java\n" + e.toString());
		}
		try {
			Connection connection = DriverManager.getConnection( "jdbc:odbc:JLibrary");
			Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			ResultSet resultSet = statement.executeQuery("SELECT * FROM Members");
			resultSet.beforeFirst();
			while (resultSet.next()) 
				if(ID == resultSet.getInt(1)) break;
			if(resultSet.previous()) {
			    memberIDTextField.setText(Integer.toString(resultSet.getInt(1)));
			    informationTextField[0].setText( Integer.toString(resultSet.getInt(2)));
				informationTextField[1].setText( resultSet.getString(4));
				informationTextField[2].setText( resultSet.getString(5));
				informationTextField[3].setText( resultSet.getString(6));
				informationTextField[4].setText( resultSet.getFloat(8)+"");
				informationTextField[5].setText( resultSet.getDate(9)+ " ");
			};
			resultSet.close();
			statement.close();
			connection.close();
 		}
		catch (SQLException SQLe) {
			System.out.println("MembersInformation.java\n" + SQLe.toString());
		}
	}
	private void findAfter(int ID){
	    try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch (ClassNotFoundException cnfe) {
			System.out.println("MembersInformation.java\n" + cnfe.toString());
		}
		catch (Exception e) {
			System.out.println("MembersInformation.java\n" + e.toString());
		}
		try {
			Connection connection = DriverManager.getConnection( "jdbc:odbc:JLibrary");
			Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			ResultSet resultSet = statement.executeQuery("SELECT * FROM Members");
			resultSet.beforeFirst();
			while (resultSet.next()) 
				if(ID == resultSet.getInt(1)) break;
			if(resultSet.next()) {
			    memberIDTextField.setText(Integer.toString(resultSet.getInt(1)));
			    informationTextField[0].setText( Integer.toString(resultSet.getInt(2)));
				informationTextField[1].setText( resultSet.getString(4));
				informationTextField[2].setText( resultSet.getString(5));
				informationTextField[3].setText( resultSet.getString(6));
				informationTextField[4].setText( resultSet.getFloat(8)+"");
				informationTextField[5].setText( resultSet.getDate(9)+ " ");
			};
			resultSet.close();
			statement.close();
			connection.close();
 		}
		catch (SQLException SQLe) {
			System.out.println("MembersInformation.java\n" + SQLe.toString());
		}
	}
	private void printRecord()
	{
	    member = new Members();
		member.connection("SELECT * FROM Members WHERE MemberID = " + memberIDTextField.getText());
	    int numberOfBook = member.getNumberOfBooks();
	    if (numberOfBook > 0) {
	        System.out.println("numberOfBook:"+numberOfBook);
	        System.out.println("Execute SQL!");
	        String sql = "SELECT Books.BookID,Books.Title,borrow.DayOfBorrowed,borrow.DayOfReturn FROM borrow,Books "
	        	+"WHERE borrow.BookID = Books.BookID AND borrow.MemberID = "
	        	+ Integer.toString (member.getMemberID());
	        ListBorrowRecord lbr = new ListBorrowRecord(sql);
	        getParent().add(lbr);
			try {
					lbr.setSelected(true);
			}
			catch (java.beans.PropertyVetoException e) {}
	    }
	    else
	    	JOptionPane.showMessageDialog(null, "该用户没有借书!", "信息", JOptionPane.YES_OPTION);
	}
}

⌨️ 快捷键说明

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