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

📄 qq_adduser.java

📁 IO流的项目好
💻 JAVA
字号:
package myQQ;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

class QQ_AddUser extends JFrame implements ActionListener
{
	Adom ad = new Adom();
	String sID = "00000";
	QQPhoto QQp= new QQPhoto();//头像
	Image img = Toolkit.getDefaultToolkit().getImage("img/Regis/4.gif");
	ImageIcon imTu = new ImageIcon("img/Regis/1.jpg");
	ImageIcon imTian1 = new ImageIcon("img/Regis/1.gif");
	ImageIcon imGB1 = new ImageIcon("img/Regis/5.gif");
	ImageIcon imGB2 = new ImageIcon("img/Regis/6.gif");
	JLabel jTitle = new JLabel(imTu);
	JLabel jx0 = new JLabel("注册成功",JLabel.CENTER);
	JLabel jx1 = new JLabel("恭喜你!注册成功!",imTian1,JLabel.LEFT);
	JLabel jx2 = new JLabel("请纪录您的ID :",imTian1,JLabel.LEFT);
	JLabel jx3 = new JLabel(sID);
	JLabel jx4 = new JLabel("请关闭本窗口!凭借此ID登录MyQQ",imTian1,JLabel.LEFT);
	JPanel jpB = new JPanel();
	MyPane mp = new MyPane(img,732,650);
	JButton jbG = new JButton(imGB1);
	Dimension ds = Toolkit.getDefaultToolkit().getScreenSize();
	//--------------------------------------------------------------------------
	JPanel jpT = new JPanel();
	JPanel jpC = new JPanel();
	String []s ={"昵称","年龄","性别","密码","确认密码","选择头像",
		"省份","城市","验证码"};
	String []sex = {"性别","男","女"};
	JLabel jl[] = new JLabel[9];
	JLabel jTian = new JLabel("填写资料",JLabel.CENTER);
	JLabel jTian1 = new JLabel("填写以下资料您可以注册成为MyQQ用户。",imTian1,JLabel.LEFT);
	JTextField jtf[] = new JTextField[3];
	JPasswordField jpf[] = new JPasswordField[2];
	JComboBox jcbSex = new JComboBox(sex);
	JComboBox jcbState = new JComboBox();
	JComboBox jcbCity = new JComboBox();
	//-----------------------------------------------------------------------
	JPanel jp1 = new JPanel(new FlowLayout(FlowLayout.CENTER,20,15));
	ImageIcon imIcon1 = new ImageIcon("img/Regis/2.gif");
	ImageIcon imIcon2 = new ImageIcon("img/Regis/3.gif");
	ImageIcon imIcon3 = new ImageIcon("img/Regis/2.png");
	ImageIcon imIcon4 = new ImageIcon("img/Regis/3.png");
	JButton jbQD = new JButton(imIcon1);
	JButton jbQX = new JButton(imIcon2);

	//----------------------------------------------------------------------
	YanZhengMa yzm = new YanZhengMa();
	JButton jbCL = new JButton("看不清楚!换张图片");
	
	//客户端
	QQClient client = null;
		
	public QQ_AddUser(QQClient client)
	{
		super("注册");
		this.setIconImage(Adom.icon);
		this.setLocation(ad.setCenter(732,600));//居中显示
		this.setSize(732,600);	
		Container c =this.getContentPane();
		c.add(mp);
		c.add(jTitle,BorderLayout.NORTH);
		jx3.setFont(new Font("隶书",Font.PLAIN,16));
		jx3.setForeground(Color.red);
		jx0.setFont(new Font("黑体",Font.BOLD,16));
		jx0.setForeground(Color.orange);
		//----------------------------------------------------------------------
		jbG.addActionListener(this);
		jbG.addMouseListener(new mm());
		jbG.setBorder(null);	jbG.setOpaque(false);
		jpB.add(jbG);c.add(jpB,BorderLayout.SOUTH);
		jpB.setBackground(Color.white);
		jpB.show(false);
		//----------------------------------------------------------------------
		mp.setLayout(new CardLayout());
		jpT.setLayout(null);	jpC.setLayout(null);
		jpT.setOpaque(false);	jpC.setOpaque(false);
		for (int i = 0; i<jl.length; i++)
		{
			jl[i] = new JLabel(s[i]);
			jpT.add(jl[i],null);
		}
		for (int i = 0; i<jtf.length; i++)
		{
			jtf[i] = new JTextField(15);
			jpT.add(jtf[i],null);
		}
		for (int i = 0; i<jpf.length; i++)
		{
			jpf[i] = new JPasswordField();
			jpT.add(jpf[i],null);
		}
		jpT.add(QQp,null);
		//------------------------------------------------------------------
		jp1.add(jbQD);	jp1.add(jbQX);
		jbQD.addMouseListener(new mm());
		jbQX.addMouseListener(new mm());
		jbQD.addActionListener(this);
		jbQX.addActionListener(this);
		jbQD.setBorder(null);	jbQX.setBorder(null);
		jbQD.setOpaque(false);	jbQX.setOpaque(false);
		jp1.setBounds(0,390,732,60);
		jp1.setBorder(BorderFactory.createEtchedBorder());
		jp1.setOpaque(false);
			
		//------------------------------------------------------------------
		jTian.setBounds(273,5,185,40);
		jTian.setForeground(Color.orange);
		jTian.setFont(new Font("黑体",Font.BOLD,16));
		jTian1.setBounds(50,60,500,30);
		jpT.add(jTian,null);	jpT.add(jTian1,null);
		//------------------------------------------------------------------
		jx0.setBounds(273,5,185,40);	jx1.setBounds(50,60,500,30);
		jx2.setBounds(50,100,200,30);	jx3.setBounds(180,100,400,30);
		jx4.setBounds(50,140,500,30);
		jpC.add(jx0,null);	jpC.add(jx1,null);	jpC.add(jx2,null);
		jpC.add(jx3,null);	jpC.add(jx4,null);
		//------------------------------------------------------------------
		jl[0].setBounds(44,129,86,30);jl[1].setBounds(331,129,86,30);
		jl[2].setBounds(541,129,76,30);jl[3].setBounds(44,170,86,30);
		jl[4].setBounds(44,211,86,30);jl[5].setBounds(331,190,100,30);
		jl[6].setBounds(44,251,86,30);jl[7].setBounds(331,251,86,30);
		jl[8].setBounds(44,291,86,30);
		QQp.setBounds(431,170,100,60);
		//------------------------------------------------------------------
		jtf[0].setBounds(109,129,162,24);jtf[1].setBounds(408,129,86,24);
		jtf[2].setBounds(109,291,100,24); yzm.setBounds(230,289,100,30);
		jbCL.setBounds(340,291,120,24);	jbCL.addActionListener(this);
		jbCL.setBorder(null); jbCL.setOpaque(false);
		//------------------------------------------------------------------
		jpf[0].setBounds(109,170,162,24);jpf[1].setBounds(109,211,162,24);
		//------------------------------------------------------------------
		jcbState.addItem("选取省份");
		jcbCity.addItem("选取城市");
		jcbState.setSelectedIndex(0);	jcbCity.setSelectedIndex(0);
		jcbState.addActionListener(this);
		jcbSex.setBounds(608,129,84,24);jcbState.setBounds(109,251,100,24);
		jcbCity.setBounds(408,251,100,24);
		jcbSex.setBackground(Color.white);	jcbState.setBackground(Color.white);
		jcbCity.setBackground(Color.white);	
		jbCL.setFont(new Font("宋体",Font.PLAIN,12));
		jcbSex.setFont(new Font("宋体",Font.PLAIN,12));
		jcbCity.setFont(new Font("宋体",Font.PLAIN,12));
		jcbState.setFont(new Font("宋体",Font.PLAIN,12));
		//------------------------------------------------------------------
		jpT.add(jcbSex,null);jpT.add(jcbState,null);jpT.add(jcbCity,null);
		jpT.add(jp1,null);		jpT.add(yzm,null);	jpT.add(jbCL,null);
		mp.add("Card1",jpT);	mp.add("Card2",jpC);
		this.setVisible(true);
	}
	
	class mm extends MouseAdapter
	{
		public void mousePressed(MouseEvent e)
		{
			if(e.getSource().equals(jbQD))
			{
				jbQD.setIcon(imIcon3);
			}
			if(e.getSource().equals(jbQX))
			{
				jbQX.setIcon(imIcon4);
			}
			if(e.getSource().equals(jbG))
			{
				jbG.setIcon(imGB2);
			}
		}
		public void mouseReleased(MouseEvent e)
		{
			jbQD.setIcon(imIcon1);
			jbQX.setIcon(imIcon2);
			jbG.setIcon(imGB1);
		}
			
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource().equals(jcbState))
		{	//选择省份
			String x = (String)jcbState.getSelectedItem();
			if(x.equals("选取省份"))
			{
				//--------------------客户端初始化
				this.client = client;
				if(client==null)
				{
					this.client = new QQClient();
					client.setQQ_AddUser(this);
					client.start();
				}
				MessType mt = new MessType("10000",41);
				client.sendMess(mt);	
			}
			else
			{
				MessType mt = new MessType("10000",42);
				mt.Pro = x;
				client.sendMess(mt);
			}	
		}
		if(e.getSource().equals(jbG))
		{
			qingkong();
			for (int i = 0; i<jtf.length; i++)
			{
				jtf[i].setText("");
			}
			jcbSex.setSelectedIndex(0);
			jcbState.setSelectedIndex(0);
			jcbCity.setSelectedIndex(0);
			yzm.again();
			((CardLayout)mp.getLayout()).show(mp,"Card1");
			
			this.show(false);
		}
		if(e.getSource().equals(jbCL))
		{
			yzm.again();	
		}
		if(e.getSource().equals(jbQX))
		{
			for (int i = 0; i<jtf.length-1; i++)
			{
				jtf[i].setText("");
			}
			qingkong();
			jtf[2].setText("");
			jcbSex.setSelectedIndex(0);
			jcbState.setSelectedIndex(0);
			jcbCity.setSelectedIndex(0);
		}
		if(e.getSource().equals(jbQD))
		{
			String	sNiCheng = jtf[0].getText().trim();//昵称
			String	sNianLing =jtf[1].getText().trim();//年龄
			String  sM1 = jpf[0].getText().trim();//密码
			String 	sM2 = jpf[1].getText().trim();//确认密码
			String  sSex = jcbSex.getSelectedItem().toString().trim();//性别================
			String	sState = jcbState.getSelectedItem().toString().trim();//省
			String  sCity = jcbCity.getSelectedItem().toString().trim();//市
			String  sPhoto = ((ImageIcon)QQp.jlPhoto.getIcon()).getDescription();//头像
			String  sYZM = jtf[2].getText().trim();//验证码
			try {
					int age = Integer.parseInt(sNianLing);
					if(!sM1.equals(sM2))
					{
					    JOptionPane.showMessageDialog(null,"两次输入的密码不一致","错误",JOptionPane.ERROR_MESSAGE);
						qingkong();
						yzm.again();
						jtf[2].setText("");
						jpf[0].setFocusable(true);
					}
					else if(sM1.equals(""))
					{
					    JOptionPane.showMessageDialog(null,"请输入密码","错误",JOptionPane.ERROR_MESSAGE);
					    yzm.again();
						jtf[2].setText("");
						jpf[0].setFocusable(true);
				 	}
					else if(sM2.equals(""))
					{
					    JOptionPane.showMessageDialog(null,"请确认密码","错误",JOptionPane.ERROR_MESSAGE);
					    yzm.again();
						jtf[2].setText("");
						jpf[1].setFocusable(true);
					}
					else if(!sYZM.equals(yzm.s1))
					{
					    JOptionPane.showMessageDialog(null,"验证码错误","错误",JOptionPane.ERROR_MESSAGE);
						qingkong();
						yzm.again();
						jtf[2].setText("");
						jtf[2].setFocusable(true);
					}
					else if(sNiCheng.equals(""))
					{
						JOptionPane.showMessageDialog(null,"请输入昵称","错误",JOptionPane.ERROR_MESSAGE);
						qingkong();
						jtf[0].setFocusable(true);
					}
					else if(jcbSex.getSelectedIndex()==0)
					{
						JOptionPane.showMessageDialog(null,"请选择性别","错误",JOptionPane.ERROR_MESSAGE);
						jcbSex.setFocusable(true);
					}
					else if(sState.equals("选取省份"))
					{
						JOptionPane.showMessageDialog(null,"请选择省份","错误",JOptionPane.ERROR_MESSAGE);
						jcbState.setFocusable(true);
					}
					else if(sCity.equals("选取城市"))
					{
						JOptionPane.showMessageDialog(null,"请选择城市","错误",JOptionPane.ERROR_MESSAGE);
						jcbCity.setFocusable(true);
					}
					else
					{	//验证后发送注册消息
						MessType mt = new MessType("10000",sNiCheng,sM1,age,sSex,sState,sCity,sPhoto);
						client.sendMess(mt);
					}
			}catch (Exception ex) {
			    JOptionPane.showMessageDialog(null,"请输入正确的年龄","错误",JOptionPane.ERROR_MESSAGE);
			    qingkong();
			    jtf[1].setText("");
			    jtf[1].setFocusable(true);
			}
		}

	}		
	public void qingkong()
	{
		for (int i = 0; i<jpf.length; i++)
		{
			jpf[i].setText("");
		}

	}

}

⌨️ 快捷键说明

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