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

📄 registration.java

📁 用户需要注册
💻 JAVA
字号:
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import java.io.*;
import java.net.*;

import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.border.BevelBorder;
import java.awt.ComponentOrientation;
import java.awt.event.KeyEvent;
import java.awt.Toolkit;
import javax.swing.WindowConstants;
//注册
public class Registration extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;  //  @jve:decl-index=0:visual-constraint="153,56"

	private JLabel username = null;

	private JTextField username1 = null;

	private JLabel password = null;

	private JLabel affirm = null;

	private JLabel id = null;

	private JTextField id1 = null;

	private JLabel question = null;

	private JTextField question1 = null;

	private JLabel answer = null;

	private JTextField answer1 = null;

	private JButton submit = null;

	private JPasswordField password1 = null;

	private JPasswordField affirm3 = null;

	private JLabel account = null;

	private JTextField account1 = null;

	private JButton cancel = null;

	private JLabel jLabel = null;
	
	public static String b;
	/**
	 * This is the default constructor
	 */
	public Registration() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(439, 402);
		this.setContentPane(getJContentPane());
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/pic/register.png")));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("用户注册");
		this.setResizable(false);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(0, 0, 432, 369));
			jLabel.setIcon(new ImageIcon(getClass().getResource("/pic/background.jpg")));
			account = new JLabel();
			account.setBounds(new Rectangle(107, 210, 80, 24));
			account.setFont(new Font("\u65b0\u5b8b\u4f53-18030", Font.BOLD, 12));
			account.setText("个人账户号码");
			answer = new JLabel();
			answer.setBounds(new Rectangle(120, 290, 55, 24));
			answer.setFont(new Font("\u65b0\u5b8b\u4f53-18030", Font.BOLD, 12));
			answer.setText("  答案");
			question = new JLabel();
			question.setBounds(new Rectangle(107, 250, 80, 24));
			question.setFont(new Font("\u65b0\u5b8b\u4f53-18030", Font.BOLD, 12));
			question.setText("密码提示问题");
			id = new JLabel();
			id.setBounds(new Rectangle(107, 170, 80, 24));
			id.setFont(new Font("\u65b0\u5b8b\u4f53-18030", Font.BOLD, 12));
			id.setText(" 身份证号码");
			affirm = new JLabel();
			affirm.setBounds(new Rectangle(120, 130, 55, 24));
			affirm.setFont(new Font("\u65b0\u5b8b\u4f53-18030", Font.BOLD, 12));
			affirm.setText("确认密码");
			password = new JLabel();
			password.setBounds(new Rectangle(120, 89, 55, 24));
			password.setFont(new Font("\u65b0\u5b8b\u4f53-18030", Font.BOLD, 12));
			password.setText("  密码");
			username = new JLabel();
			username.setBounds(new Rectangle(120, 50, 55, 24));
			username.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
			username.setFont(new Font("\u65b0\u5b8b\u4f53-18030", Font.BOLD, 12));
			username.setText(" 用户名");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setFont(new Font("Dialog", Font.PLAIN, 12));
			jContentPane.setBorder(BorderFactory.createTitledBorder(null, " ", TitledBorder.RIGHT, TitledBorder.ABOVE_BOTTOM, new Font("\u65b0\u5b8b\u4f53-18030", Font.PLAIN, 10), Color.blue));
			jContentPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			jContentPane.setEnabled(true);
			jContentPane.setForeground(new Color(51, 51, 51));
			jContentPane.add(username, null);
			jContentPane.add(getUsername1(), null);
			jContentPane.add(password, null);
			jContentPane.add(affirm, null);
			jContentPane.add(id, null);
			jContentPane.add(getId1(), null);
			jContentPane.add(question, null);
			jContentPane.add(getQuestion1(), null);
			jContentPane.add(answer, null);
			jContentPane.add(getAnswer1(), null);
			jContentPane.add(getSubmit(), null);
			jContentPane.add(getPassword1(), null);
			jContentPane.add(getAffirm3(), null);
			jContentPane.add(account, null);
			jContentPane.add(getAccount1(), null);
			jContentPane.setBackground(Color.white);
			jContentPane.add(getCancel(), null);
			jContentPane.add(jLabel, null);
		}
		return jContentPane;
	}

	private void sign_out()
	{
		this.dispose();
	}
	/**
	 * This method initializes username1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getUsername1() {
		if (username1 == null) {
			username1 = new JTextField();
			username1.setBounds(new Rectangle(240, 50, 94, 24));
		}
		return username1;
	}

	/**
	 * This method initializes id1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getId1() {
		if (id1 == null) {
			id1 = new JTextField();
			id1.setBounds(new Rectangle(240, 170, 94, 24));
		}
		return id1;
	}

	/**
	 * This method initializes question1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getQuestion1() {
		if (question1 == null) {
			question1 = new JTextField();
			question1.setBounds(new Rectangle(240, 250, 94, 24));
		}
		return question1;
	}

	/**
	 * This method initializes answer1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getAnswer1() {
		if (answer1 == null) {
			answer1 = new JTextField();
			answer1.setBounds(new Rectangle(240, 290, 94, 24));
		}
		return answer1;
	}

	/**
	 * This method initializes submit	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSubmit() {
		if (submit == null) {
			submit = new JButton();
			submit.setBounds(new Rectangle(123, 328, 65, 30));
			submit.setIcon(new ImageIcon(getClass().getResource("/pic/submit.gif")));
			submit.setBorderPainted(false);
			submit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if (e.getSource()==submit)
					{
						
						String username2 = (username1.getText());
						String password2 = (password1.getText());
						String affirm2 = (affirm3.getText());
						String id2=(id1.getText());
						String account2 = (account1.getText());
						String question2 = (question1.getText());
						String answer2 = (answer1.getText());
						int j = 0;
						if(username2.length()==0)
						{
							String a="对不起,用户名不能为空";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(password2.length()==0)
						{
							String a="对不起,密码不能为空";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(affirm2.length()==0)
						{
							String a="对不起,确认密码不能为空";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(!password2.equals(affirm2))
						{
							String a="两次输入的密码不一致,请重新输入";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(id2.length()==0)
						{
							String a="对不起,身份证号码不能为空";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(account2.length()==0)
						{
							String a="对不起,个人账户号码不能为空";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(question2.length()==0)
						{
							String a="对不起,密码提示问题不能为空";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(answer2.length()==0)
						{
							String a="对不起,密码提示问题答案不能为空";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(!integer.isInteger(id2))
						{
							String a="请填写有效的身份证号码";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						else if(!integer.isInteger(account2))
						{
							String a="请填写有效的账户号码";
							messagebox mb=new messagebox(a);
							mb.setVisible(true);
							j = 1;
						}
						if(j == 0)
						{
						try//连接数据库
						{
							Socket socket;
							socket = new Socket("localhost",2000);
							PrintWriter toServer = new PrintWriter(socket.getOutputStream(),true);
							toServer.println(8);
							toServer.println(username1.getText().trim());
							toServer.println(password1.getText().trim());
							toServer.println(id1.getText().trim());
							toServer.println(account1.getText().trim());
							toServer.println(question1.getText().trim());
							toServer.println(answer1.getText().trim());
						}
						catch(IOException ex)
						{
							System.err.println(ex);
						}
						try//服务器返回结果
						{
							ServerSocket serverSocket = new ServerSocket(2001);
							Socket  fromServer = serverSocket.accept();
							DataInputStream isFromServer = new DataInputStream(fromServer.getInputStream());
								int i = isFromServer.readInt();
								System.out.println(i);
								if(i == 1)
								{
									String a="注册成功,点击进入大厅";
									b=username1.getText().trim();
									messagebox1 mb=new messagebox1(a,3);
									mb.setVisible(true);
									sign_out();
								}
								else 
								{
									String a="对不起,用户名已存在";
									messagebox mb=new messagebox(a);
									mb.setVisible(true);
								}
								isFromServer.close();
								serverSocket.close();
							}
							catch(IOException ex)
							{
								System.err.println(ex);
							}
						}
				}
				}
			});
		}
		return submit;
	}
	/**
	 * This method initializes password1	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getPassword1() {
		if (password1 == null) {
			password1 = new JPasswordField();
			password1.setBounds(new Rectangle(240, 90, 94, 24));
		}
		return password1;
	}

	/**
	 * This method initializes affirm3	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getAffirm3() {
		if (affirm3 == null) {
			affirm3 = new JPasswordField();
			affirm3.setBounds(new Rectangle(240, 130, 94, 24));
		}
		return affirm3;
	}

	/**
	 * This method initializes account1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getAccount1() {
		if (account1 == null) {
			account1 = new JTextField();
			account1.setBounds(new Rectangle(240,210, 94, 24));
		}
		return account1;
	}

	/**
	 * This method initializes cancel	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getCancel() {
		if (cancel == null) {
			cancel = new JButton();
			cancel.setBounds(new Rectangle(246, 328, 65, 30));
			cancel.setBackground(Color.white);
			cancel.setIcon(new ImageIcon(getClass().getResource("/pic/cancel.gif")));
			cancel.setBorderPainted(false);
			cancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return cancel;
	}

	public static void main(String[] args) {
				Registration application = new Registration();
	}
}  //  @jve:decl-index=0:visual-constraint="158,55"

⌨️ 快捷键说明

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