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

📄 guiregist.java

📁 提供用户登陆
💻 JAVA
字号:
//注册
package MyPackage;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class GuiRegist
{
	static Socket socket1;
	static PrintWriter os;
	static BufferedReader is;
	static Frame f=null;
	static TextField t1=null;
	static TextField t2=null;
	static TextField t3=null;
	static Label l1=null;
	static Label l2=null;
	static Label l3=null;
	static Label l4=null;
	static Label l5=null;
	static Label l6=null;
	static Label l7=null;
	static Button b1=null;
	static Button b2=null;
	static boolean flag=false;
	public GuiRegist(){
		try{
			socket1=new Socket("172.40.83.44",5700);
			os=new PrintWriter(socket1.getOutputStream());
			is=new BufferedReader(new InputStreamReader(socket1.getInputStream()));
		}catch(Exception e1){}
		f=new Frame("用户注册");
		t1=new TextField();
		t2=new TextField();
		t3=new TextField();
        l1=new Label("用户名:");
		l2=new Label("(由字母组成,长度不超过10个字符)");
		l3=new Label("密码:");
		l4=new Label("确认密码:");
		l5=new Label("(由数字组成,长度");
		l6=new Label("不超过6个字符)");
		l7=new Label("");
		b1=new Button("取消");
		b2=new Button("确定");
        
		
        f.addWindowListener(new WindowsListener());//侦听窗体事件
		b1.addActionListener(new CancelListener());//侦听按钮的事件
		b2.addActionListener(new Register());//侦听按钮事件	
		new Recieve(is);//启动接收线程
		
		t2.setEchoChar('*');
		t3.setEchoChar('*');
		l1.setBackground(Color.gray);
		l2.setBackground(Color.gray);
		l3.setBackground(Color.gray);
		l4.setBackground(Color.gray);
        l5.setBackground(Color.gray);
		l6.setBackground(Color.gray);
		l7.setBackground(Color.gray);

		f.setLayout(null);
		l1.setBounds(40,60,50,20);
		t1.setBounds(110,60,190,20);
		l7.setBounds(305,60,100,20);
		l2.setBounds(80,90,300,20);
		l3.setBounds(40,120,50,20);
		t2.setBounds(110,120,150,20);
	    l5.setBounds(260,120,150,20);
        l4.setBounds(40,150,60,20);
		t3.setBounds(110,150,150,20);
		l6.setBounds(260,150,100,20);
		b1.setBounds(120,190,70,25);
		b2.setBounds(210,190,70,25);
		f.add(l1);
		f.add(t1);
		f.add(l7);
		f.add(l2);
		f.add(l3);
		f.add(t2);
		f.add(l5);
		f.add(l4);
		f.add(t3);
		f.add(l6);
		f.add(b1);
		f.add(b2);
		f.setVisible(true);
		f.setBackground(Color.gray);
		f.setBounds(200,200,400,250);//设置宽和高
		f.setResizable(false);
	}
/*	public static void main(String args[]){
	    new GuiRegist();
	}*/
}

class Register implements ActionListener{
	public void actionPerformed(ActionEvent e){
		String username,key1,key2;
		username=GuiRegist.t1.getText();
		key1=GuiRegist.t2.getText();
		key2=GuiRegist.t3.getText();
		//System.out.println("KEY1"+key1+(key1.toLowerCase()).equals("everybody"));
		if((username.toLowerCase()).equals("everybody")){//判断用户名是否是Everybody
		  new Message("4");
		  return;
	    }
		new Send(username+":"+key1+":"+key2);
	}
}

class Send{
	 public Send(String s){
		try{
			PrintWriter os=new PrintWriter(GuiRegist.socket1.getOutputStream());
			os.println(s);
			os.flush();
		}catch(IOException e){
			System.out.println("Error"+e);
		}
	}
}

class Recieve extends Thread{
	public BufferedReader is;
	Recieve(BufferedReader is1){
		this.is=is1;
		this.start();
	}
	public void run(){
	    try{
			String s,username,key1,key2;
			while(true){
				s=is.readLine();
				System.out.println("readLine="+s);
				if(s==null)break;
				if(s.equals("0")){
					System.out.println("添加一个新用户");
					new Message2("0");
					GuiRegist.socket1.close();
					System.exit(1);
				}
				else if(s.equals("1")){
					System.out.println("!用户已经存在");
					new Message2("1");
					//GuiRegist.l7.setText("!用户已经存在");
				}
				else if(s.equals("2")){
					System.out.println("用户名非法");
					new Message2("2");
					//GuiRegist.l7.setText("!用户名非法");
				}
				else if(s.equals("3")){
					System.out.println("密码非法");
					new Message2("3");
					//GuiRegist.l7.setText("!密码非法");
				}
			}
		}
		catch(Exception e){}
	}
};


class WindowsListener extends WindowAdapter{//窗口事件
	public void windowClosing(WindowEvent e){
		try{
		    GuiRegist.socket1.close();
	    }catch(Exception e1){}
		    System.exit(1);
	}
};

class CancelListener implements ActionListener{
	public void actionPerformed(ActionEvent e){
     try{
		 GuiRegist.socket1.close();
	 }catch(Exception e1){} 
		System.exit(1);
	}
}


class Message2{//消息对话框
	public Message2(String s){
		int type=JOptionPane.PLAIN_MESSAGE;
		String title="Message Dialog";
		String message="";
		if(s.equals("0")){
			type=JOptionPane.INFORMATION_MESSAGE;
            message="恭喜您注册成功";
		}
		else if(s.equals("1")){
			type=JOptionPane.WARNING_MESSAGE;
			message="该用户已存在,请重新注册";
		}
		else if(s.equals("2")){
			type=JOptionPane.ERROR_MESSAGE;
			message="您输入的用户名非法,请重新输入...";

		}
		else if(s.equals("3")){
			type=JOptionPane.WARNING_MESSAGE;
			message="您输入的密码非法,请重新输入...";
		}
		else if(s.equals("4")){
			type=JOptionPane.WARNING_MESSAGE;
			message="您不能注册这个用户,您的权限不够此操作";
		}
		JOptionPane.showMessageDialog(GuiRegist.f,message,title,type);
	}		
		
};

⌨️ 快捷键说明

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