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

📄 register.java

📁 这是一个仿QQ的聊天程序
💻 JAVA
字号:
package com.cloudcloud.soft;
import java.awt.*;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;


public class Register extends JFrame
{

	LeftPanel lp;

	ClausePanel cp;
	
	Login l;
	
	Register(Login l)
	{
		this.l = l;
		this.setTitle("申请新QQ号码");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(160,120,640,480);
		this.setResizable(false);
		this.setLayout(null);
		
		lp = new LeftPanel();
		cp = new ClausePanel(this, lp, l);
	
		this.add(lp);
		this.add(cp);		
	}
}


class LeftPanel extends JPanel
{
	JLabel l1 = new JLabel("同意条款");
	JLabel l2 = new JLabel("填写信息");
	JLabel l3 = new JLabel("完成");
	
	LeftPanel()
	{
		this.setBounds(0,0,100,480);
		this.setLayout(null);
		this.setBackground(new Color(180,230,255));
		
		l1.setFont(new Font("宋体", Font.PLAIN, 12));
		l1.setBounds(10,30,80,20);
		l2.setFont(new Font("宋体", Font.PLAIN, 12));
		l2.setBounds(10,80,80,20);
		l3.setFont(new Font("宋体", Font.PLAIN, 12));
		l3.setBounds(10,130,80,20);
		this.add(l1);
		this.add(l2);
		this.add(l3);
		
	}
}


class ClausePanel extends JPanel implements ActionListener
{
	JLabel l1;
	JLabel l2;
	JLabel l3;
	JLabel l4;
	JTextArea ta;
	JScrollPane sp;
	JButton bAgree;
	JButton bDisagree;
	Register r;
	InputPanel ip;
	LeftPanel lp;
	Login l;
	ClausePanel(Register r, LeftPanel lp, Login l)
	{
		this.r = r;
		this.lp = lp;
		this.l = l;
		this.setBounds(100,0,540,480);
		this.setLayout(null);
		this.setBackground(new Color(240,250,255));
		
		lp.l1.setForeground(Color.BLUE);
		
		l1 = new JLabel("·请仔细阅读并接受《CloudQQ用户服务条款》");
		l1.setFont(new Font("宋体", Font.PLAIN, 12));
		l1.setBounds(10,30,500,20);
		
		l2 = new JLabel("·请点击“我同意”继续");
		l2.setFont(new Font("宋体", Font.PLAIN, 12));
		l2.setBounds(10,50,500,20);
		
		l3 = new JLabel("本着有效利用QQ号码资源,对于恶意注册或者长期不登陆的QQ号码,系统有权回收。");
		l3.setFont(new Font("宋体", Font.PLAIN, 12));
		l3.setBounds(10,330,500,20);
		
		l4 = new JLabel("cloudcloud.com具有对以上条款内容的最终解释权。");
		l4.setFont(new Font("宋体", Font.PLAIN, 12));
		l4.setBounds(10,350,500,20);
		
		ta = new JTextArea();
		ta.setLineWrap(true);
		ta.setEditable(false);
		
		

		String tmp;
		try
		{
			asdrsdf f = new asdrsdf("files/clause.txt");
			while((tmp = f.readLine()) != null)
			{
				ta.setText(ta.getText() + tmp + "\n");
			}
		}
		catch(Exception e)
		{
			ta.setText("没有找到");
		}
		
		sp = new JScrollPane(ta);
		sp.setBounds(10,90,500,230);
		sp.getVerticalScrollBar().setValue(sp.getVerticalScrollBar().getMinimum());
		
		bAgree = new JButton("我同意");
		bAgree.setFont(new Font("宋体", Font.PLAIN, 14));
		bAgree.setBounds(70,390,100,40);
		bAgree.addActionListener(this);
		
		bDisagree = new JButton("我不同意");
		bDisagree.setFont(new Font("宋体", Font.PLAIN, 14));
		bDisagree.setBounds(320,390,100,40);
		bDisagree.addActionListener(this);
		
		this.add(l1);
		this.add(l2);
		this.add(sp);
		this.add(l3);
		this.add(l4);
		this.add(bAgree);
		this.add(bDisagree);
	}
	public void actionPerformed(ActionEvent e) 
	{
		if(e.getSource() == bAgree)
		{
			lp.l1.setForeground(Color.BLACK);
			lp.l2.setForeground(Color.BLUE);
			this.setVisible(false);
			ip = new InputPanel(r,lp,l);
			ip.setVisible(true);
			r.add(ip);
		}
		else
		{
			System.exit(0);
		}
	}
}


class InputPanel extends JPanel implements ActionListener
{
	MyLabel lName;
	MyLabel lPwd1;
	MyLabel lPwd2;
	MyLabel lHead;
	MyLabel lSex;
	MyLabel lAge;
	MyLabel lEmail;
	MyLabel lShow;
	
	JTextField tName;
	
	JPasswordField pfPwd1;
	JPasswordField pfPwd2;
	
	JRadioButton rMale;
	JRadioButton rFemale;
	ButtonGroup bgSex;
	
	JComboBox cbAge;
	
	JTextField tEmail;
	
	JTextArea taShow;
	JScrollPane spShow;
	
	JLabel lFace;
	FacePanel fp;
	JButton bNext;
	Register r;
	FinishPanel finishp;
	LeftPanel lp;
	Login l;
	asdwqer mb;
	
	cawesda member;
	int HeadNum = 0;
	Socket s;
	
	InputPanel(Register r, LeftPanel lp, Login l)
	{
		this.r = r;
		this.lp =lp;
		this.l = l;
		this.setBounds(100,0,540,480);
		this.setBackground(new Color(240,250,255));
		this.setLayout(null);
		
		lName = new MyLabel("昵    称:", 20, 40);
		lPwd1 = new MyLabel("密    码:", 20, 70);
		lPwd2 = new MyLabel("确认密码:", 20, 100);
		lSex = new MyLabel("性    别:", 20, 130);
		lAge = new MyLabel("年    龄:", 20, 160);
		lEmail = new MyLabel("E-mail  :", 20, 190);
		lShow = new MyLabel("个人说明:", 20, 230);
		lHead = new MyLabel("头像:");
		lHead.setBounds(270,20,80,20);

		tName = new JTextField();
		tName.setBounds(100,40,150,20);

		pfPwd1 = new JPasswordField();
		pfPwd1.setBounds(100,70,150,20);

		pfPwd2 = new JPasswordField();
		pfPwd2.setBounds(100,100,150,20);

		rMale = new JRadioButton("男");
		rMale.setBounds(100,130,50,20);
		rMale.setBackground(new Color(240,250,255));
		rMale.setFont(new Font("宋体", Font.PLAIN, 12));
		rMale.setSelected(true);

		rFemale = new JRadioButton("女");
		rFemale.setBounds(180,130,50,20);
		rFemale.setBackground(new Color(240,250,255));
		rFemale.setFont(new Font("宋体", Font.PLAIN, 12));

		bgSex = new ButtonGroup();
		bgSex.add(rMale);
		bgSex.add(rFemale);

		cbAge = new JComboBox();
		for(int i = 10; i <= 100; i++)
		{
			cbAge.addItem(Integer.toString(i));
		}
		cbAge.setBounds(100,160,50,20);
		cbAge.setFont(new Font("宋体", Font.PLAIN, 12));
		cbAge.setBackground(new Color(240,250,255));
		tEmail = new JTextField();
		tEmail.setBounds(100,190,150,20);
		taShow = new JTextArea();
		taShow.setText("这个家伙很懒,所以什么都没留下。");
		spShow = new JScrollPane(taShow);
		spShow.setBounds(20,260,230,130);
		lFace = new JLabel();
		lFace.setBounds(350,20,40,40);
		fp = new FacePanel(this);
		bNext = new JButton("下一步");
		bNext.setFont(new Font("宋体", Font.PLAIN, 14));
		bNext.setBounds(420,380,80,30);
		bNext.addActionListener(this);
		
		this.add(lName);
		this.add(lPwd1);
		this.add(lPwd2);
		this.add(lHead);
		this.add(lSex);
		this.add(lAge);
		this.add(lEmail);
		this.add(lShow);
		this.add(lHead);
		this.add(tName);
		this.add(pfPwd1);
		this.add(pfPwd2);
		this.add(rMale);
		this.add(rFemale);
		this.add(cbAge);
		this.add(tEmail);
		this.add(spShow);
		this.add(lFace);
		this.add(fp);
		this.add(bNext);
		
	}
	class MyLabel extends JLabel
	{
		MyLabel(String n)
		{
			this.setFont(new Font("宋体", Font.PLAIN, 12));
			this.setText(n);
		}
		MyLabel(String n, int x, int y)
		{
			this.setFont(new Font("宋体", Font.PLAIN, 12));
			this.setText(n);
			this.setBounds(x,y,80,20);
		}
	}
	public String IsInputAllCorrect()
	{
		String pwd1 = pfPwd1.getText();
		String pwd2 = pfPwd2.getText();
		String name = tName.getText();
		String e = tEmail.getText();
		String show = taShow.getText();
		if(!pwd1.equals(pwd2))
		{
			return "两次密码输入不一致";
		}
		else if(pwd1.equals(""))
		{
			return "密码不能为空";
		}
		else if(name.equals(""))
		{
			return "昵称不能为空";
		}
		else if(e.indexOf("@") <= 0 || e.indexOf(".") <= 0)
		{
			return "E-mail输入不合法";
		}
		else if(show.equals(""))
		{
			return "个人说明不能为空";
		}
		else if(HeadNum == 0)
		{
			return "请选择头像";
		}
		else
		{
			return "OK";
		}
	}

	public void actionPerformed(ActionEvent e) 
	{
		String Massage = null;	

		if(IsInputAllCorrect().equals("OK"))
		{

			member = new cawesda();
			member.setName(tName.getText());
			member.setPwd(pfPwd1.getText());
			member.setHeadNum(HeadNum);
			if(bgSex.getButtonCount() == 0)
			{
				member.setSex("男");
			}
			else if(bgSex.getButtonCount() == 1)
			{
				member.setSex("女");
			}
			member.setAge(cbAge.getSelectedIndex() + 10);
			member.setEmail(tEmail.getText());
			member.setShow(taShow.getText());
			

			try 
			{
				s = new Socket(sasdasd.SERVERIP, sasdasd.SERVERPORT);
				Zdasdasd ms = new Zdasdasd(s);
				ms.println("APPLY");
				String sep = "==QQ==";
				ms.println(member.getName() + sep + member.getPwd() + sep + member.getHeadNum() + sep + member.getSex() + sep + member.getAge() + sep + member.getEmail() + sep + member.getShow());

				String QQNum = ms.readLine();
				Massage = "<html><font color=#0000FF>注册成功!&nbsp;&nbsp;您的号码为:</font><br><font size=20 color=blue >&nbsp;&nbsp;" + QQNum + "</font></body></html>";
				s.close();
				s = null;
			} 
			catch (Exception e1) 
			{
				e1.printStackTrace();
				Massage = "<html><font color=#0000FF>对不起,连接服务器失败,请您稍候再试。</font></body></html>";
			}
			
			
			lp.l2.setForeground(Color.BLACK);
			lp.l3.setForeground(Color.BLUE);
			this.setVisible(false);
			finishp = new FinishPanel(r,l);
			finishp.setLmass(Massage);
			finishp.setVisible(true);
			r.add(finishp);
			l.setSocket(s);
		}

		else
		{
			mb = new asdwqer();
			mb.setVisible(true);
			mb.setLms(IsInputAllCorrect());
		}
		
	}

	class FacePanel extends JPanel implements ActionListener
	{

		JButton[] bHead = new JButton[30];
		InputPanel ip;
		FacePanel(InputPanel ip)
		{
			this.ip = ip;
			this.setBounds(270,80,250,290);
			this.setLayout(new GridLayout(6,5,2,2));
			
			for(int i = 0; i <= 29; i++)
			{
				bHead[i] = new JButton();
				bHead[i].setIcon(new ImageIcon(getImageSource("face/" + ( i + 1 ) + ".gif")));
				bHead[i].setActionCommand(Integer.toString(i));
				bHead[i].addActionListener(this);
				this.add(bHead[i]);
			}
			
		}
		private BufferedImage getImageSource(String imagePath)
		{
			BufferedImage image = null;
			InputStream in = Class.class.getClass().getResourceAsStream("/" + imagePath);
			try 
			{
				image = ImageIO.read(in);
				return image;
			}
			catch (IOException e) 
			{
				e.printStackTrace();
				return image;
			}
		}

		public void actionPerformed(ActionEvent e) 
		{
			HeadNum = Integer.parseInt(e.getActionCommand()) + 1;
			ip.lFace.setIcon(new ImageIcon(getImageSource("face/" + HeadNum + ".gif")));
		}
	}
}


class FinishPanel extends JPanel implements ActionListener
{
	JLabel lmass;
	JButton b;
	Register r;
	Login l;
	public void setLmass(String s)
	{
		lmass.setText(s);
	}
	FinishPanel(Register r, Login l)
	{
		this.r = r;
		this.l = l;
		this.setBounds(100,0,540,480);
		this.setBackground(new Color(240,250,255));
		this.setLayout(null);
		lmass= new JLabel();
		lmass.setFont(new Font("", Font.PLAIN, 14));
		lmass.setVerticalAlignment(JLabel.NORTH);
		lmass.setBounds(50,50,600,400);
		
		
		b = new JButton("完成");
		b.setBackground(new Color(240,250,255));
		b.setFont(new Font("宋体", Font.PLAIN, 14));
		b.setBounds(420,380,80,30);
		b.addActionListener(this);
		
		this.add(lmass);
		this.add(b);
	}
	public void actionPerformed(ActionEvent e) 
	{
		
		r.setVisible(false);
		l.setVisible(true);
		
	} 
}

⌨️ 快捷键说明

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