首页>代码>java swing仿qq写的群聊软件>/javaqq/src/Clientframe.java
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.TextArea;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

/**
 * 
 * @author tian
 *	
 */
public class Clientframe {
	
	//	登陆窗口
	JFrame jf;
	JPanel jp1;			
	JPanel jp2;
	JLabel jl1;			
	JLabel jl2;			
	JLabel jl3;
	JLabel jl4;
	JLabel jl5;
	JLabel jl6;
	JLabel jl7;
	Checkbox cb;
	Checkbox cb2;
	Choice ci ;
	ImageIcon im;
	JLabel jl8;
	JTextField jtfname;	
	JPasswordField jtfpwd;	
	JTextField jtfname2;
	JTextField jtfname3;
	JButton jb1;		
	JButton jb2;
	
//	  群聊窗口
	JFrame jfa;
	JPanel jpa;
	JPanel jp;
	JPanel jpl;
	TextArea jtaa;
	TextArea jtab;
	JButton jba;
	JButton jbb;
	JButton jbc;
	JTextPane textPane;
	JTextPane textPane1;	
	ImageIcon iic;
	
//	  私聊窗口
	JFrame jfaa;			
	JPanel jpaa;			
	JPanel jpp;
	JPanel jpll;
	JTextPane jtaaa;	
	JTextPane jtabb;	
	JButton jbaa;		
	JButton jbbb;		
	JButton jbbc;
	ImageIcon iic2;
	
//	  上线用户列表
	JFrame jfb;
	JPanel jpan;
	JPanel jpan1;
	DefaultListModel dlm;
	JList jli;
	JButton jb;
	ImageIcon ii;
	ImageIcon iii;
	JLabel jl;
	
//	群聊表情窗口
	JFrame jfc;
	JPanel jpbq;
	
	/**
	 * 
	 */
	public Clientframe(){
		
//		初始化群聊表情窗口
		jfc = new JFrame("表情");
		jpbq = new JPanel();
		jfc.add(jpbq, BorderLayout.CENTER);
		jpbq.setLayout(new GridLayout(5,5));
		jfc.add(jpbq);
		URL qqurl = this.getClass().getClassLoader().getResource("Image/qq.jpg"); 
		jfc.setIconImage(Toolkit.getDefaultToolkit().createImage(qqurl));
		ArrayList al = new ArrayList();
		for (int i = 10; i < 35; i++) {
			URL url = this.getClass().getClassLoader().getResource( "Image/"+i+".gif"); 
			ImageIcon ii=new ImageIcon(url);
			JLabel jl = new JLabel(ii);
			al.add(jl);
		}
		for (int j = 0; j < al.size(); j++) {
			JLabel jl = (JLabel) al.get(j);
			jl.addMouseListener(new MouseListener(){
				public void mouseClicked(MouseEvent e) {
					StyledDocument doc = textPane1.getStyledDocument();
					SimpleAttributeSet attr = new SimpleAttributeSet();
					StyleConstants.setForeground(attr, Color.red);
					String s = e.getSource().toString();
					Pattern p = Pattern.compile(".gif");
					Matcher m = p.matcher(s);
					while(m.find()){
							int start = m.start();
							int end = m.end();
							String subs = s.substring(start-2,end);
							String path = "d:\\"+subs;
							textPane1.setCaretPosition(doc.getLength()); // 设置插入位置
							File file = new File(path);
							Icon image = new ImageIcon(file.getAbsoluteFile().toString());
							textPane1.insertIcon(image);
							try {
								doc.insertString(doc.getLength(), file.getName(), attr);
							} catch (BadLocationException e1) {
								
								e1.printStackTrace();
							}
						}
				}

				public void mouseEntered(MouseEvent e) {
					
				}
			
				public void mouseExited(MouseEvent e) {
					
				}

				public void mousePressed(MouseEvent e) {
					
				}

				public void mouseReleased(MouseEvent e) {
					
				}
			});
			jpbq.add(jl);
		}
		
		jfc.setVisible(false);
		jfc.setSize(250,250);

		
//		初始化登陆窗口
		
		jf = new JFrame("QQ用户登陆");
		jp1 = new JPanel();
		jp2 = new JPanel();
		jtfname = new JTextField("",15);
		jtfpwd = new JPasswordField("",15);
		jtfname2 = new JTextField("",15);
		jl1 = new JLabel("QQ账号:");
		jl2 = new JLabel("QQ密码:");
		jl3 = new JLabel("ServerIP:");
		jl4 = new JLabel("申请账号");
	    jl5 = new JLabel("忘了密码");
		jl6 = new JLabel("QQ状态:");
		jl7=new JLabel("动感地带 ");
		cb = new Checkbox("自动登录");
	    cb2 = new Checkbox("记住密码");
		ci = new Choice();
		jb1 = new JButton("登录");
        jb2 = new JButton("退出");
        URL jmurl =this.getClass().getClassLoader().getResource("Image/jm.jpg");
        im = new ImageIcon(jmurl);
        jl8=new JLabel(im);
		jf.add(jp1,BorderLayout.CENTER);
		jf.add(jp2,BorderLayout.SOUTH);
		jp1.add(jl8);
		jp1.add(jl1);
		jp1.add(jtfname);
		jp1.add(jl4);
		jp1.add(jl2);
		jp1.add(jtfpwd);
		jp1.add(jl5);
		jp1.add(jl3);
		jp1.add(jtfname2);
		jp1.add(jl7);
		jp1.add(jl6);
		jp1.add(ci);
		jp1.add(cb2);
		jp1.add(cb);
		jp2.add(jb1);
		jp2.add(jb2);
		jf.setBackground(new Color(100, 253, 98));
		jp1.setBackground(new Color(176, 224, 230 ));
		jp2.setBackground(new Color(127, 255, 212 ));
		ci.add("在线");
		ci.add("Q我吧");
		ci.add("忙碌");
		ci.add("离开");
		ci.add("静音");
		ci.add("隐身");
		jl1.setForeground(Color.BLUE);
		jl2.setForeground(Color.BLUE);
		jl3.setForeground(Color.BLUE);
		jl4.setForeground(Color.BLUE);
		jl5.setForeground(Color.BLUE);
		jl7.setForeground(Color.BLUE);
		jb1.setSize(20, 10);
		jb2.setSize(20, 10);
        jf.setSize(333, 250);
		jf.setIconImage(Toolkit.getDefaultToolkit().createImage(qqurl));
		jf.setLocation(500, 250);
		jf.setResizable(false);
		jf.setVisible(true);
		
		jb2.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				System.exit(1);
				
			}
			
		});
		
//		初始化群聊窗口
		jfa = new JFrame("QQ聊天室");
		jpa = new JPanel();
		jp = new JPanel();
		jpl = new JPanel();
		dlm = new DefaultListModel();
		URL iicurl =this.getClass().getClassLoader().getResource("Image/12.gif");
		iic=new ImageIcon(iicurl);
		textPane = new JTextPane();
		textPane1 = new JTextPane();
		textPane.setPreferredSize(new Dimension(360, 200));
		textPane1.setPreferredSize(new Dimension(360, 100));
		textPane.setFont(new Font("Serif",Font.BOLD,14));
		textPane1.setFont(new Font("Serif",Font.BOLD,14));
		JScrollPane scrollPane = new JScrollPane(textPane);
		JScrollPane scrollPane1 = new JScrollPane(textPane1);
		textPane1.setForeground(Color.red);
		jba = new JButton("发送");
		jbb = new JButton("清空");
		jbc = new JButton("表情",iic);
		jbc.setMnemonic(KeyEvent.VK_F);//给“表情”按钮设置快捷键
		jba.setForeground(Color.BLUE);
		jbb.setForeground(Color.BLUE);
		jbc.setForeground(Color.BLUE);
		jfa.add(jpa, BorderLayout.NORTH);
		jfa.add(jp, BorderLayout.CENTER);
		jfa.add(jpl, BorderLayout.SOUTH);
		jfa.setIconImage(Toolkit.getDefaultToolkit().createImage(qqurl));
		jpa.add(scrollPane);
		jp.add(scrollPane1);
		jpl.add(jba);
		jpl.add(jbc);
		jpl.add(jbb);
		jpa.setBackground(new Color(100, 253, 98));
		jp.setBackground(new Color(100, 253, 98));
		jpl.setBackground(new Color(100, 253, 98));
		jfa.setSize(380, 400);
		jfa.setLocation(500, 150);
		jfa.setResizable(false);
		jfa.setVisible(false);

		jbb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textPane1.setText("");
			}
		});
		
		
//		 监听群聊表情按钮
		jbc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jfc.setVisible(true);
				jfc.setLocation(500, 150);
			}
		});
		
//		初始化私聊窗口
		jfaa = new JFrame("私聊");			
		jpaa = new JPanel();			
		jpp = new JPanel();
		jpll =new JPanel();
		URL transcurl =this.getClass().getClassLoader().getResource("Image/trans.gif");
		iic2 =new ImageIcon(transcurl);
		jtaaa = new JTextPane();	
		jtabb = new JTextPane();
		jtaaa.setPreferredSize(new Dimension(360, 200));
		jtabb.setPreferredSize(new Dimension(360, 100));
		JScrollPane scrollPanea = new JScrollPane(jtaaa);
		JScrollPane scrollPaneb = new JScrollPane(jtabb);
		jtabb.setForeground(Color.red);
		jbaa = new JButton("发送");		
		jbbb = new JButton("清空");		
		jbbc = new JButton("",iic2);
		jbc.setMnemonic(KeyEvent.VK_F);
		jtaaa.setFont(new Font("Serif",Font.BOLD,14));
		jtabb.setFont(new Font("Serif",Font.BOLD,14));
	    jbaa.setForeground(Color.BLACK);
		jbbb.setForeground(Color.BLACK);
		jbbc.setForeground(Color.BLACK);
		jfaa.add(jpaa,BorderLayout.NORTH);
		jfaa.add(jpp,BorderLayout.CENTER);
		jfaa.add(jpll,BorderLayout.SOUTH);
		jfaa.setIconImage(Toolkit.getDefaultToolkit().createImage(qqurl));
		jpaa.add(scrollPanea);
		jpp.add(scrollPaneb);
		jpll.add(jbaa);
		jpll.add(jbbc);
		jpll.add(jbbb);
		jf.setBackground(new Color(100, 253, 98));
		jpaa.setBackground(new Color(100, 253, 98));		
		jpp.setBackground(new Color(100, 253, 98));		 
		jpll.setBackground(new Color(100, 253, 98));		 
		jfaa.setSize(380, 400);
		jfaa.setLocation(500, 150);
		jfaa.setResizable(false);
		jfaa.setVisible(false);	
		 	   
		jbbb.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				jtabb.setText("");
			}
			
		});
		
//		初始化上线用户列表
		jfb = new JFrame();
		jpan = new JPanel();
		dlm = new DefaultListModel();
		jli = new JList(dlm);
		jb = new JButton(">>>群聊模式");
		jli.setForeground(Color.BLUE);
		jb.setSize(15, 20);
		jb.setForeground(Color.BLUE);
		jfb.add(jpan);
		jpan.setLayout(new BorderLayout());
		jpan.add(jli, BorderLayout.CENTER);
		jpan.add(jb, BorderLayout.SOUTH);
		jpan.add(jli);
		jfb.setIconImage(Toolkit.getDefaultToolkit().createImage(qqurl));
		jfb.setResizable(false);
		jfb.setLocation(500, 200);
		jfb.setSize(200, 450);
		jfb.setVisible(false);
		
	}
}

最近下载更多
cksndh  LV4 2023年8月16日
fuyouou  LV5 2023年6月29日
yuanchuang  LV22 2023年2月14日
liys1234  LV9 2022年6月21日
微信网友_6003487859068928  LV5 2022年6月15日
微信网友_5989987974549504  LV5 2022年6月5日
17岁的孩子想糖吃  LV7 2021年12月31日
111111255  LV2 2021年12月24日
Aoifee  LV4 2021年11月10日
pear_li  LV1 2021年10月13日
最近浏览更多
krispeng  LV6 4月15日
陈小灏  LV14 2023年12月26日
luamweise 2023年10月18日
暂无贡献等级
wertttak  LV1 2023年9月26日
小新Coding  LV9 2023年9月7日
cksndh  LV4 2023年8月16日
fuyouou  LV5 2023年6月29日
2017143155  LV12 2023年6月24日
漫步的海星  LV4 2023年5月9日
微信网友_6444139264921600  LV6 2023年4月29日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友