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

📄 zhuce.java

📁 能实现图书管理的基本功能,例如读者管理,书库管理等!
💻 JAVA
字号:
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;

public class zhuce 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 JTextField jTextField = null;

	private JPasswordField jPasswordField = null;

	private JPasswordField jPasswordField1 = null;

	private JButton jButton = null;

	private JButton jButton1 = null;

	public zhuce() throws HeadlessException {
		// TODO Auto-generated constructor stub
		super();
		initialize();
	}

	public zhuce(GraphicsConfiguration gc) {
		super(gc);
		// TODO Auto-generated constructor stub
		initialize();
	}

	public zhuce(String title) throws HeadlessException {
		super(title);
		// TODO Auto-generated constructor stub
		initialize();
	}

	public zhuce(String title, GraphicsConfiguration gc) {
		super(title, gc);
		// TODO Auto-generated constructor stub
		initialize();
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(110, 31, 115, 25));
		}
		return jTextField;
	}

	/**
	 * This method initializes jPasswordField	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField() {
		if (jPasswordField == null) {
			jPasswordField = new JPasswordField();
			jPasswordField.setBounds(new Rectangle(110, 72, 115, 25));
		}
		return jPasswordField;
	}

	/**
	 * This method initializes jPasswordField1	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField1() {
		if (jPasswordField1 == null) {
			jPasswordField1 = new JPasswordField();
			jPasswordField1.setBounds(new Rectangle(110, 113, 115, 25));
		}
		return jPasswordField1;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(44, 166, 73, 28));
			jButton.setText("注册");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					jButton_aa(e);
				}
			});
		}
		return jButton;
	}
	public void jButton_aa(ActionEvent e){
		try
	      { 
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
	      }
	    catch (ClassNotFoundException ce)
	      {
	    	System.out.println("SQLException:"+ce.getMessage()); 
	      }
	    try
	      {      
	    	Connection con =DriverManager.getConnection("jdbc:odbc:lib");
	        Statement stmt = con.createStatement();
	        ResultSet rs=stmt.executeQuery("select * from User where Name='"+jTextField.getText()+"'");
	        if(!rs.next())
	        {
	        	if(jPasswordField.getText().equals(jPasswordField1.getText()))
	        	{	
	        		String sqlstr ="insert into User(Name,Pass) values('"+jTextField.getText()+"','"+jPasswordField1.getText()+"')";
	        		stmt.executeUpdate(sqlstr);
	        		JOptionPane.showMessageDialog(null, "注册成功!");
	        		this.hide();
	        	}
	        	else
	        	{
	        		JOptionPane.showMessageDialog(null, "密码不一致!");
	        	}
	        }
	        else
	        {
	        	JOptionPane.showMessageDialog(null, "用户名已经存在!");
	        }
	      }
	    catch (SQLException ce)
	      { 
	    	System.out.println("SQLException:"+ce.getMessage()); 
	      }
	}
	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(133, 166, 82, 28));
			jButton1.setText("取消");
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					Button_qx(e);
				}
			});
		}
		return jButton1;
	}
	public void Button_qx(ActionEvent e)
	{
		this.hide();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				zhuce thisClass = new zhuce();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(273, 237);
		this.setContentPane(getJContentPane());
		this.setTitle("注册");
		this.setVisible(true);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(37, 113, 73, 25));
			jLabel2.setText("确认:");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(37, 72, 73, 25));
			jLabel1.setText("口令:");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(37, 30, 73, 25));
			jLabel.setText("用户名:");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(getJPasswordField(), null);
			jContentPane.add(getJPasswordField1(), null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJButton1(), null);
		}
		return jContentPane;
	}

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

⌨️ 快捷键说明

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