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

📄 readerloginframe.java

📁 模拟图书馆管理系统 实现了各种图书馆管理功能
💻 JAVA
字号:
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JToggleButton;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.Font;
import java.sql.*;

public class ReaderLoginFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel4 = null;

	private JRadioButton jRadioButton = null;

	private JRadioButton jRadioButton1 = null;
	
	private ButtonGroup buttonGroup = null;  //  @jve:decl-index=0:

	private JPasswordField jPasswordField = null;

	private JTextField jTextField = null;

	private JPanel jPanel = null;

	private JPasswordField jPasswordField1 = null;

	private JLabel jLabel5 = null;

	private JLabel jLabel6 = null;

	private JPanel jPanel1 = null;

	private JLabel jLabel7 = null;

	private JLabel jLabel8 = null;

	private JTextField jTextField1 = null;

	private JLabel jLabel9 = null;

	private JLabel jLabel10 = null;

	private JLabel jLabel11 = null;

	private JTextField jTextField2 = null;

	private JButton jButton = null;

	private JButton jButton1 = null;

	private JComboBox jComboBox = null;

	private JComboBox jComboBox1 = null;

	private JLabel jLabel31 = null;

	private JComboBox jComboBox2 = null;
	
	private Connection connection = null;

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

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(414, 411);
		this.setContentPane(getJContentPane());
		this.setTitle("读者帐号注册");
		this.setLocation(300, 150);
		this.setVisible(true);
		
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				setVisible(false);
				//System.out.println("windowClosing()"); // TODO Auto-generated Event stub windowClosing()
			}
		});
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel31 = new JLabel();
			jLabel31.setBounds(new Rectangle(206, 195, 47, 22));
			jLabel31.setText("系别");
			jLabel11 = new JLabel();
			jLabel11.setBounds(new Rectangle(9, 338, 69, 28));
			jLabel11.setText("Email");
			jLabel6 = new JLabel();
			jLabel6.setBounds(new Rectangle(9, 291, 70, 31));
			jLabel6.setText("  出生年月");
			jLabel5 = new JLabel();
			jLabel5.setText(" 密码验证");
			jLabel5.setBounds(new Rectangle(6, 163, 70, 22));
			jLabel4 = new JLabel();
			jLabel4.setText("   姓别");
			jLabel4.setBounds(new Rectangle(9, 225, 67, 24));
			jLabel3 = new JLabel();
			jLabel3.setText("   姓名");
			jLabel3.setBounds(new Rectangle(9, 196, 64, 22));
			jLabel2 = new JLabel();
			jLabel2.setText("   密码");
			jLabel2.setBounds(new Rectangle(9, 134, 64, 21));
			jLabel1 = new JLabel();
			jLabel1.setText("   学号");
			jLabel1.setBounds(new Rectangle(9, 105, 63, 21));
			jLabel = new JLabel();
			jLabel.setText("");
			jLabel.setIcon(new ImageIcon("Icon\\reader.gif"));
			jLabel.setBounds(new Rectangle(1, 1, 425, 91));
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(jLabel3, null);
			jContentPane.add(jLabel4, null);
			jContentPane.add(getJPasswordField(), null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(getJPasswordField1(), null);
			jContentPane.add(jLabel5, null);
			jContentPane.add(jLabel6, null);
			jContentPane.add(getJPanel1(), null);
			jContentPane.add(getJTextField1(), null);
			jContentPane.add(jLabel11, null);
			jContentPane.add(getJTextField2(), null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJButton1(), null);
			jContentPane.add(jLabel31, null);
			jContentPane.add(getJComboBox2(), null);
			
			buttonGroup = new ButtonGroup();
			buttonGroup.add(jRadioButton);
			buttonGroup.add(jRadioButton1);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jRadioButton	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setText("男");
			jRadioButton.setSelected(true);
			jRadioButton.setBounds(new Rectangle(10, 15, 38, 26));
		}
		return jRadioButton;
	}

	/**
	 * This method initializes jRadioButton1	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setText("女");
			jRadioButton1.setBounds(new Rectangle(96, 16, 38, 26));
		}
		return jRadioButton1;
	}

	/**
	 * This method initializes jPasswordField	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField() {
		if (jPasswordField == null) {
			jPasswordField = new JPasswordField();
			jPasswordField.setBounds(new Rectangle(89, 135, 199, 23));
			jPasswordField.setFont(new Font("Dialog", Font.PLAIN, 18));
		}
		return jPasswordField;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(89, 107, 199, 23));
			jTextField.setFont(new Font("Dialog", Font.PLAIN, 18));
		}
		return jTextField;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel10 = new JLabel();
			jLabel10.setBounds(new Rectangle(137, 5, 37, 42));
			jLabel10.setText("");
			jLabel10.setIcon(new ImageIcon("Icon\\female.gif"));
			jLabel9 = new JLabel();
			jLabel9.setBounds(new Rectangle(57, 6, 39, 39));
			jLabel9.setText("");
			jLabel9.setIcon(new ImageIcon("Icon\\male.gif"));
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(90, 225, 202, 51));
			jPanel.add(getJRadioButton(), null);
			jPanel.add(getJRadioButton1(), null);
			jPanel.add(jLabel9, null);
			jPanel.add(jLabel10, null);
		}
		return jPanel;
	}

	/**
	 * This method initializes jPasswordField1	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField1() {
		if (jPasswordField1 == null) {
			jPasswordField1 = new JPasswordField();
			jPasswordField1.setBounds(new Rectangle(89, 165, 199, 23));
			jPasswordField1.setFont(new Font("Dialog", Font.PLAIN, 18));
		}
		return jPasswordField1;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jLabel8 = new JLabel();
			jLabel8.setBounds(new Rectangle(154, 4, 19, 19));
			jLabel8.setText("月");
			jLabel7 = new JLabel();
			jLabel7.setBounds(new Rectangle(77, 6, 22, 17));
			jLabel7.setText("年");
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.setBounds(new Rectangle(90, 291, 199, 29));
			jPanel1.add(jLabel7, null);
			jPanel1.add(jLabel8, null);
			jPanel1.add(getJComboBox(), null);
			jPanel1.add(getJComboBox1(), null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setBounds(new Rectangle(90, 197, 101, 22));
			jTextField1.setFont(new Font("Dialog", Font.PLAIN, 18));
		}
		return jTextField1;
	}

	/**
	 * This method initializes jTextField2	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
			jTextField2.setBounds(new Rectangle(98, 339, 187, 24));
			jTextField2.setFont(new Font("Dialog", Font.PLAIN, 18));
		}
		return jTextField2;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(323, 307, 66, 23));
			jButton.setText("提交");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String warn = "";
					String warnId = null;
					String warnPassword = null;
					String warnName = null;
					String warnEmail = null;
					
					if(jTextField.getText().length()==0){
						warnId = "学号不能为空\n";
					    warn += warnId;
					}
					if(jPasswordField.getText().length()==0 || jPasswordField1.getText().length()==0){
						warnPassword = "密码信息不完整\n";
					    warn += warnPassword;
					}
					else if(new String(jPasswordField.getText()).equals(new String(jPasswordField1.getText()))==false){
						warnPassword = "两次密码输入不同\n";
					    warn += warnPassword;
					}
					if(jTextField1.getText().length()==0){
						warnName = "姓名不能为空\n";
						warn += warnName;
					}
					if(jTextField2.getText().length()==0){
						warnEmail = "Email信息不能为空\n";
						warn += warnEmail;
					}
					if(warn.length()==0){
						String id = jTextField.getText();
						String password = jPasswordField.getText();
						String name = jTextField1.getText();
						String sex = null;
						if(jRadioButton.isSelected()==true)
							sex = "男";
						else
							sex = "女";
						String department = ((String)jComboBox2.getSelectedItem());
						int year = ((Integer)jComboBox.getSelectedItem()).intValue();
						int month = ((Integer)jComboBox1.getSelectedItem()).intValue();
						String Email = jTextField2.getText();
						
						try{
							String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Library";
							String user = "sa";
							String password2 = "";
							if(connection == null)
							connection = DataBaseConnect.connect(url, user, password2) ;
							Statement statement = connection.createStatement();
							String query = "insert into Reader values("
								           + "'" + id + "',"
								           + "'" + password + "',"
								           + "'" + name + "',"
								           + "'" + sex + "',"
								           + "'" + department + "',"
								           + "'" + year + "',"
								           + "'" + month + "',"
								           + "'" + Email + "'"
								           +")";
							//System.out.println(query);
							statement.executeUpdate(query);
							statement.close();
							setVisible(false);
							JOptionPane.showMessageDialog(null, "注册成功\n您可以登录了","注册成功",JOptionPane.INFORMATION_MESSAGE);
						}catch(Exception sqlE){
							sqlE.printStackTrace();
						}
					}
					else
					    JOptionPane.showMessageDialog(null, warn, "注册不成功", JOptionPane.ERROR_MESSAGE);

					//System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(322, 344, 67, 23));
			jButton1.setText("清空");
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jTextField.setText(null);
					jPasswordField.setText(null);
					jPasswordField1.setText(null);
					jTextField1.setText(null);
					jTextField2.setText(null);
					//System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButton1;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		Integer[] yearData = new Integer[40];
		for(int i=0;i<40;i++){
			yearData[i] = i + 1970;
		}
		if (jComboBox == null) {
			jComboBox = new JComboBox(yearData);
			jComboBox.setSelectedItem(new Integer(1985));
			jComboBox.setBounds(new Rectangle(10, 3, 65, 19));
		}
		return jComboBox;
	}

	/**
	 * This method initializes jComboBox1	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox1() {
		Integer[] monthData = new Integer[12];
		for(int i=0;i<12;i++){
			monthData[i] = i+1;
		}
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox(monthData);
			jComboBox1.setBounds(new Rectangle(103, 4, 46, 19));
		}
		return jComboBox1;
	}

	/**
	 * This method initializes jComboBox2	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox2() {
		String[] jComboBox2Data = {"计算机系","数学系","物理系","美术系","音乐系","法律系","自动化系","经济系","统计系","会计系","其他"};
		if (jComboBox2 == null) {
			jComboBox2 = new JComboBox(jComboBox2Data);
			jComboBox2.setBounds(new Rectangle(250, 197, 141, 21));
		}
		return jComboBox2;
	}

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

⌨️ 快捷键说明

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