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

📄 qqface.java

📁 IO流的项目好
💻 JAVA
字号:
//选择表情的封装类
package myQQ;

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

class QQFace extends JWindow 
{
	//手型面板
	JTabbedPane faceMain = new JTabbedPane();
	//表情子面板
	QQFacePanel[] faceSub = new QQFacePanel[3];
	//对应的表情名称
	String[] fname = {"mm豆","绿豆","猪猪"};
	//对应的表情个数
	int[] fc = {20,32,20};  
	//聊天主面板
	QQChatFrame chat = null;
	
	QQFace(Point p,Frame f)
	{
		super(f); //在聊天框架之上显示
		this.chat = (QQChatFrame)f; //传入聊天主面板以插入选择的表情
		this.setSize(300,200);
		for (int i = 0; i<faceSub.length; i++)
		{
			faceSub[i] = new QQFacePanel(fname[i],fc[i]);
			faceMain.addTab(fname[i],faceSub[i]);
		}
		faceMain.setBackground(Color.white);
		Container c = this.getContentPane();
		c.add(faceMain);
		c.setBackground(Color.white);
		//传入表情按钮的位置以此为锚点显示
		p.x -= 150;
		p.y -= 200;
		this.setLocation(p);
		this.setVisible(true);
	}
	
	class QQFacePanel extends JPanel implements ActionListener
	{	//表情子面板---内部类
		String name; //表情组名称
		int count; //表情个数
		JButton[] face = null; //表情按钮
		JWindow facePre = new JWindow(); //预览表情
		
		QQFacePanel(String name,int c)
		{
			this.name = name;
			this.count = c;
			this.setBackground(Color.white);
			this.setLayout(new GridLayout(5,10,0,0));
			this.buildFace();
		}
		
		public void buildFace()
		{	//将表情添加入面板
			face = new JButton[this.count];
			for (int i = 0; i<50; i++)
			{	//先添加面板
				JPanel tem = new JPanel();
				tem.setBackground(Color.white);
				this.add(tem);
				if(i<face.length)
				{	//添加表情按钮
					ImageIcon im = new ImageIcon("QQ/face/"+this.name+"/"+i+".png");
					face[i] = new JButton(im);
					face[i].setMargin(new Insets(0,0,0,0));
					face[i].setContentAreaFilled(false);
					face[i].addActionListener(this);
					tem.add(face[i]);	
				}
			}
		}
		
		public void actionPerformed(ActionEvent e)
		{	//选择表情事件
			JButton x = (JButton)e.getSource();
			String s = ((ImageIcon)x.getIcon()).getDescription();
			s = s.replaceFirst("png","gif");
			//插入所选的表情
			chat.chatIn.setFace(s);
			this.hideFacePane();
		}
		
		public void hideFacePane()
		{	//隐藏选择表情窗体
			//恢复按钮状态
			chat.jbType[1].setBorder(null);
			chat.jbType[1].click = false;
			//清除窗体
			dispose();
		}
	}
}

⌨️ 快捷键说明

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