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

📄 user.java

📁 IO流的项目好
💻 JAVA
字号:
//用户按钮
package myQQ;

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

class User extends JPanel
{
	Adom ad = new Adom();
	JWindow jw = new JWindow();
	Font f = new Font("宋体",Font.PLAIN,12);
	String sendId; //本人ID
	String sendPn; //本人昵称
	String readId;//用户ID
	String readPn; //用户昵称
	String readHead; //用户头像图片名
	JButton jbFace;//用户头像按扭
	JButton jbFace1;
	JLabel jlNiCheng;
	JLabel jlNiCheng1;//用户昵称标签
	JLabel jlShangXian = new JLabel("上线了!!!");
	JPanel jp1 = new JPanel();
	
	QQClient client = null;
	
	public User(QQClient client,String sId,String sNiCheng,String rURL,String rNiCheng,String rId)
	{
		this.sendId = sId;
		this.sendPn = sNiCheng;
		this.readId = rId;
		this.readPn = rNiCheng;
		this.readHead = rURL;
		this.client = client;
		this.setLayout(null);
		this.setSize(150,50);
		this.setBackground(Color.white);
		//----------------------------------------------------------------------
		//构造用户头像按扭
		ImageIcon im = new ImageIcon(rURL);
		jbFace = new JButton(im);
		jbFace.setBorder(null);
		jbFace.setBounds(5,5,40,40);
		jbFace.setOpaque(false);
		jbFace.addMouseListener(new mm());
		//---------------------------------------------------------------------
		jbFace1 = new JButton(im);
		jbFace1.setBorder(null);
		jbFace1.setBounds(5,5,40,40);
		jbFace1.setOpaque(false);
		//----------------------------------------------------------------------
		//构造用户昵称标签
		jlNiCheng = new JLabel(rNiCheng);
		jlNiCheng.setFont(f);
		jlNiCheng.setBounds(46,5,110,20);
		//---------------------------------------------------------------------
		jlNiCheng1 = new JLabel(rNiCheng);
		jlNiCheng1.setFont(f);
		jlNiCheng1.setBounds(46,5,110,20);
		//---------------------------------------------------------------------
		this.add(jbFace,null);this.add(jlNiCheng,null);
		//	jw.setLayout(new BorderLayout());
		jp1.setLayout(null);
		jp1.setBackground(Color.white);
		jp1.setBorder(BorderFactory.createLineBorder(Color.BLUE));
		jw.setSize(160,50);
		//jw.setResizable(false);
		jw.setLocation(ad.setCenter(320,80));
		jlShangXian.setForeground(Color.red);
	}
	
	public User(String rURL,String rNiCheng,String rId)
	{
		this.readId = rId;
		this.readPn = rNiCheng;
		this.readHead = rURL;
	
		this.setLayout(null);
		this.setSize(250,50);
		this.setOpaque(false);
		//----------------------------------------------------------------------
		//构造用户头像按扭
		ImageIcon im = new ImageIcon(rURL);
		jbFace = new JButton(im);
		jbFace.setBorder(null);
		jbFace.setBounds(5,0,40,40);
		jbFace.setOpaque(false);
		//----------------------------------------------------------------------
		//构造用户昵称标签
		jlNiCheng = new JLabel(rNiCheng+"("+rId+")");
		jlNiCheng.setFont(f);
		jlNiCheng.setBounds(46,5,200,20);
		//---------------------------------------------------------------------
		this.add(jbFace,null);this.add(jlNiCheng,null);
	
	}
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);	
	}
	//上线提示
	public void sur()
	{
		Thread1 th1 = new Thread1();
		Thread2 th2 = new Thread2();
		th1.start();
		th2.start();	
	}
	
	public User tem()
	{
		return this;
	}
	//--------------------------------------------------------------------------
	class mm extends MouseAdapter
	{
		public void mouseClicked(MouseEvent e)
		{
			if(e.getSource().equals(jbFace))
			{
				jbFace.setBorder(null);
			}
			if(e.getClickCount()==2)
			{	//聊天界面
				QQChatFrame	x = new QQChatFrame(client,sendId,sendPn,tem());
				//将此界面传入客户端
				client.setChatFrame(x);
			}
		}
		public void mouseEntered(MouseEvent e)
		{
			if(e.getSource().equals(jbFace))
			{
				jbFace.setBorder(BorderFactory.createEtchedBorder());	
			}
			
		}
		public void mouseExited(MouseEvent e)
		{
			if(e.getSource().equals(jbFace))
			{
				jbFace.setBorder(null);
			}
			
		}
	}
	//上线提示
	class Thread1 extends Thread
	{
		Color c[] = {Color.orange,Color.green,Color.yellow,Color.gray,Color.blue,Color.red};
		
		public void run()
		{
			for (int i = 0; i<c.length; i++)
			{
				jlNiCheng.setForeground(c[i]);
				try {
					Thread.sleep(500);
			    }
			    catch (Exception ex) {
			    }
			}
			jlNiCheng.setForeground(Color.black);
		}

	}
	class Thread2 extends Thread
	{
		Thread2()
		{
			
			jp1.add(jbFace1,null);	jp1.add(jlNiCheng1,null);
			jlShangXian.setBounds(46,25,110,18);
			jp1.add(jlShangXian,null);
			jlNiCheng.setForeground(Color.red);
			jw.getContentPane().add(jp1);
			
		}
		public void run()
		{
			for (int i = 0; i<3000; i+=3000)
			{
				jw.setVisible(true);
				try {
					Thread.sleep(3000);
			    }
			    catch (Exception ex) {
			    }
			}
			jw.setVisible(false);
		}
	}
}

⌨️ 快捷键说明

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