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

📄 defaultclientframe.java

📁 类似于QQ的聊天程序
💻 JAVA
字号:
package client;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class DefaultClientFrame extends JFrame implements ActionListener,MouseListener{
	
	private static final long serialVersionUID = 1L;
	private TalkClient client;
	private JButton out = new JButton("群聊");
	private JButton friend = new JButton("我的好友");
	private JPanel friendPanel = new JPanel();
	private JLabel friend1 = new JLabel("我的好友");
	private ImageIcon maxImg = new ImageIcon(this.getClass().getClassLoader().getResource("img/plushover.gif"));
	private ImageIcon minImg = new ImageIcon(this.getClass().getClassLoader().getResource("img/minhover.gif"));
	public DefaultClientFrame(TalkClient client) {
		this.client = client;
		defaultFrame(true);
	}

	public void defaultFrame(boolean b) {
		
		this.setSize(230,700);
		this.setLocation(1000,0);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new BorderLayout());
		
		
		if(b) {
			friendPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			friend1.setIcon(maxImg);
			friendPanel.add(friend1);
			friendPanel.setVisible(true);
			
			this.add(friend,BorderLayout.NORTH);
			this.add(friendPanel,BorderLayout.CENTER);
			this.add(out,BorderLayout.SOUTH);
			
			friend1.addMouseListener(this);
			
		}
		else{
			this.add(friend,BorderLayout.SOUTH);
			friendPanel.removeAll();
			this.add(friendPanel,BorderLayout.CENTER);
			this.add(out,BorderLayout.NORTH);
		}
		
		out.addActionListener(this);
		friend.addActionListener(this);
		
		this.setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==out) {
			defaultFrame(false);
			new GroupFrame(client);
		}else if(e.getSource()==friend) {
			defaultFrame(true);
		}
	}

	public void mouseClicked(MouseEvent e) {
		if(e.getSource()==friend1) {
			if(friend1.getIcon() == maxImg){
				friend1.setIcon(minImg);
			}else {
				friend1.setIcon(maxImg);
			}
		}
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}

⌨️ 快捷键说明

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