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

📄 register.java

📁 java版虚拟社区,在mysql上运行.
💻 JAVA
字号:
package clientpack;


import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.io.*;
import java.util.Scanner;
import java.awt.Toolkit;

import java.net.Socket;

import javax.swing.*;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import javax.swing.ButtonGroup;


public class Register  extends JFrame{
	
	private MyMessage mm;  //  @jve:decl-index=0:
	private Message mes;

	private static final long serialVersionUID = 1L;
	
	private ButtonGroup Group =  null;  //  @jve:decl-index=0:

	private JPanel jContentPane = null;

	private JRadioButton Customer = null;

	private JRadioButton SoftDevelp = null;

	private JRadioButton InvestCorp = null;

	private JRadioButton SoftSell = null;

	private JRadioButton Restaurant = null;

	private JTextField RegID = null;

	private JTextField RegName = null;

	private JLabel Labe_RegID = null;

	private JLabel Label_Password = null;

	private JLabel Label_Password2 = null;

	private JLabel Label_RegName = null;

	private JButton Button_Reg = null;

	private JButton Button_Reg_Back = null;

	private JPasswordField jPasswordField = null;

	private JPasswordField jPasswordField1 = null;
	

	/**
	 * This is the default constructor
	 */
	public Register(Scanner pin, PrintStream pout) {
		super();
		initialize();
		mes = new Message(pin,pout);
		mm = new MyMessage();
		setCenter();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 240);
	//	this.setLocation(400, 200);
		this.setContentPane(getJContentPane());
		this.setTitle("Register");
	}
	public void setCenter(){
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize=kit.getScreenSize();
		int width = screenSize.width;
		int height = screenSize.height;
		final int WIDTH= 300;
		final int  HEIGHT= 240;
		int x=(width -WIDTH)/2;
		int y=(height - HEIGHT)/2;
		setLocation(x,y);
	}
	private void ActionRegister()
	{
		if(!(Customer.isSelected()||SoftDevelp.isSelected()||SoftSell.isSelected()
				||InvestCorp.isSelected()||Restaurant.isSelected()))
		{
			JOptionPane.showMessageDialog(null,"Please choose register type!");
			return;
		}
		if("".equals(RegID.getText().trim()))
		{
			JOptionPane.showMessageDialog(null,"Please enter id!");
			return;
		}
		if("".equals(jPasswordField.getText().trim()))
		{
			JOptionPane.showMessageDialog(null,"Please enter password!");
			return;
		}
		if(!jPasswordField.getText().trim().equals(jPasswordField1.getText().trim()))
		{
			JOptionPane.showMessageDialog(null,"Please enter the right password again!");
			return;
		}
		if("".equals(RegName.getText().trim()))
		{
			JOptionPane.showMessageDialog(null,"Please enter name!");
			return;
		}
		mm.SetNum(4);
		mm.SetMes(RegID.getText().trim(), 0);
		mm.SetMes(jPasswordField.getText().trim(), 1);
		mm.SetMes(jPasswordField1.getText().trim(), 2);
		mm.SetMes(RegName.getText().trim(), 3);
		if(Customer.isSelected())
		{
			mm.SetType("RegCustomer");
		}
		if(SoftDevelp.isSelected())
		{
			mm.SetType("RegSoftDevelp");
		}
		if(SoftSell.isSelected())
		{
			mm.SetType("RegSoftSell");
		}
		if(InvestCorp.isSelected())
		{
			mm.SetType("RegInvestCorp");
		}
		if(Restaurant.isSelected())
		{
			mm.SetType("RegRestaurant");
		}
		mes.SendMessage(mm);
		mes.GetMessage(mm);
		if("true".equals(mm.GetType()))
		{
			JOptionPane.showMessageDialog(null,"Register success!");
			dispose();
		}
		else if("false".equals(mm.GetType()))
		{
			JOptionPane.showMessageDialog(null,"ID already exsit,please choose another!");							
		}
		else if("error".equals(mm.GetType()))
		{
			JOptionPane.showMessageDialog(null,"Error!");
		}
		else
		{
			
		}
	
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			Group = new ButtonGroup();
			Label_RegName = new JLabel();
			Label_RegName.setBounds(new Rectangle(75, 140, 30, 15));
			Label_RegName.setText("Name");
			Label_Password2 = new JLabel();
			Label_Password2.setBounds(new Rectangle(68, 115, 35, 15));
			Label_Password2.setText("Again");
			Label_Password = new JLabel();
			Label_Password.setBounds(new Rectangle(50, 89, 55, 17));
			Label_Password.setText("Password");
			Labe_RegID = new JLabel();
			Labe_RegID.setBounds(new Rectangle(87, 65, 17, 14));
			Labe_RegID.setText("ID");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getCustomer(), null);
			jContentPane.add(getSoftDevelp(), null);
			jContentPane.add(getInvestCorp(), null);
			jContentPane.add(getSoftSell(), null);
			jContentPane.add(getRestaurant(), null);
			jContentPane.add(getRegID(), null);
			jContentPane.add(getRegName(), null);
			jContentPane.add(Labe_RegID, null);
			jContentPane.add(Label_Password, null);
			jContentPane.add(Label_Password2, null);
			jContentPane.add(Label_RegName, null);
			jContentPane.add(getButton_Reg(), null);
			jContentPane.add(getButton_Reg_Back(), null);
			jContentPane.add(getJPasswordField(), null);
			jContentPane.add(getJPasswordField1(), null);
			Group.add(Customer);
			Group.add(SoftDevelp);
			Group.add(SoftSell);
			Group.add(InvestCorp);
			Group.add(Restaurant);
		}
		return jContentPane;
	}

	/**
	 * This method initializes Customer	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getCustomer() {
		if (Customer == null) {
			Customer = new JRadioButton("Customer");
			Customer.setBounds(new Rectangle(14, 20, 83, 15));
		}
		return Customer;
	}

	/**
	 * This method initializes SoftDevelp	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getSoftDevelp() {
		if (SoftDevelp == null) {
			SoftDevelp = new JRadioButton("SoftDevelp");
			SoftDevelp.setBounds(new Rectangle(103, 20, 90, 16));
		}
		return SoftDevelp;
	}

	/**
	 * This method initializes InvestCorp	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getInvestCorp() {
		if (InvestCorp == null) {
			InvestCorp = new JRadioButton("InvestCorp");
			InvestCorp.setBounds(new Rectangle(15, 40, 89, 17));
		}
		return InvestCorp;
	}

	/**
	 * This method initializes SoftSell	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getSoftSell() {
		if (SoftSell == null) {
			SoftSell = new JRadioButton("SoftSell");
			SoftSell.setBounds(new Rectangle(193, 20, 82, 16));
		}
		return SoftSell;
	}

	/**
	 * This method initializes Restaurant	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getRestaurant() {
		if (Restaurant == null) {
			Restaurant = new JRadioButton("Restaurant");
			Restaurant.setBounds(new Rectangle(104, 40, 98, 15));
		}
		return Restaurant;
	}

	/**
	 * This method initializes RegID	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getRegID() {
		if (RegID == null) {
			RegID = new JTextField();
			RegID.setBounds(new Rectangle(109, 64, 107, 18));
		}
		return RegID;
	}

	/**
	 * This method initializes RegName	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getRegName() {
		if (RegName == null) {
			RegName = new JTextField();
			RegName.setBounds(new Rectangle(109, 140, 109, 18));
		}
		return RegName;
	}

	/**
	 * This method initializes Button_Reg	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getButton_Reg() {
		if (Button_Reg == null) {
			Button_Reg = new JButton("Reg");
			Button_Reg.setBounds(new Rectangle(74, 173, 69, 17));
			Button_Reg.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 // TODO Auto-generated Event stub actionPerformed()
					ActionRegister();			
				}
			});
		}
		return Button_Reg;
	}

	/**
	 * This method initializes Button_Reg_Back	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getButton_Reg_Back() {
		if (Button_Reg_Back == null) {
			Button_Reg_Back = new JButton("Back");
			Button_Reg_Back.setBounds(new Rectangle(151, 173, 65, 17));
			Button_Reg_Back.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					// TODO Auto-generated Event stub actionPerformed()
				//	Button_Reg_Back.getParent().setVisible(true);
					dispose();
					
				}
			});
		}
		return Button_Reg_Back;
	}

	/**
	 * This method initializes jPasswordField	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField() {
		if (jPasswordField == null) {
			jPasswordField = new JPasswordField();
			jPasswordField.setBounds(new Rectangle(109, 90, 107, 19));
		}
		return jPasswordField;
	}

	/**
	 * This method initializes jPasswordField1	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField1() {
		if (jPasswordField1 == null) {
			jPasswordField1 = new JPasswordField();
			jPasswordField1.setBounds(new Rectangle(109, 116, 108, 18));
		}
		return jPasswordField1;
	}

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

⌨️ 快捷键说明

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