📄 qq_main.java
字号:
package myQQ;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class QQ_Main extends JFrame implements ActionListener
{
private boolean flag = true;
private boolean flag1 = false;
User u1[]; //好友列表
Adom ad = new Adom();
ImageIcon imBack = new ImageIcon("img/Main/1.png");
//上层/下层菜单
Image imBackground1 = Toolkit.getDefaultToolkit().getImage("img/Main/1.png");
ImageIcon imCai1 = new ImageIcon("img/Main/7.png");
ImageIcon imCai2 = new ImageIcon("img/Main/8.png");
JButton jbCaiDan = new JButton(imCai1);
MyPane mpTop = new MyPane(imBackground1,170,50);
MyPane mpBottom = new MyPane(imBackground1,170,50);
JLabel jlTop = new JLabel(imBack);
QQPhoto QQp;
//--------------------------------------------------------------------------
//最外部背景面板
Image imBackground = Toolkit.getDefaultToolkit().getImage("img/Main/2.png");
MyPane mp = new MyPane(imBackground,170,1024);
JLabel jlBottom = new JLabel(imBack);
//--------------------------------------------------------------------------
//手型面板组件
JPanel jpCard2 = new JPanel(new CardLayout());
JPanel jtp = new JPanel();
QQButton jbHY = new QQButton(new ImageIcon("img/Main/31.png"),null,"我的好友");
QQButton jbYY = new QQButton(new ImageIcon("img/Main/29.png"),null,"我的音乐");
QQButton jbYX = new QQButton(new ImageIcon("img/Main/23.png"),null,"我的邮箱");
JPanel jpYinYue = new JPanel();
JPanel jpYouXiang = new JPanel();
ImageIcon im1 = new ImageIcon("img/Main/1.gif");
//--------------------------------------------------------------------------
//外层卡片布局
JPanel jpCard1 = new JPanel();
JPanel jpHaoYou = new JPanel(new BorderLayout());
JPanel jpQun = new JPanel(new BorderLayout());
QQColony QQC = new QQColony();
JButton jbLabel[] = new JButton[2];
ImageIcon []imLabel = new ImageIcon[4];
//--------------------------------------------------------------------------
//内层卡片布局
JPanel jpanel = new JPanel();
ImageIcon imClosed = new ImageIcon("img/Main/1.jpg");
ImageIcon imOpen = new ImageIcon("img/Main/2.jpg");
JButton jlHaoYou = new JButton("我的好友",imOpen);
JButton jlMoShengRen = new JButton("陌生人 ",imClosed);
JButton jlHeiMingDan = new JButton("黑名单 ",imClosed);
JPanel jpHaoYou1 = new JPanel();
JScrollPane jspHaoYou = new JScrollPane(jpanel);
JPanel jpMoShengRen1 = new JPanel();
JScrollPane jspMoShengRen = new JScrollPane(jpMoShengRen1);
JPanel jpHeiMingDan1 = new JPanel();
JScrollPane jspHeiMingDan = new JScrollPane(jpHeiMingDan1);
//--------------------------------------------------------------------------
Dimension ds = Toolkit.getDefaultToolkit().getScreenSize();
int x = ds.width;
int y = ds.height;
//-----
QQClient client = null;
String selfId; //本人Id
String selfPn; //本人昵称
String selfHead; //本人头像
Vector friend = null; //好友集合---最后一项是本人信息
public QQ_Main(Vector v,QQClient client,String selfId)
{
this.client = client;
this.friend = v;
this.selfId = selfId;
ad.setAllFont(new Font("宋体",Font.PLAIN,12),Color.black);
this.setLocation(ad.setRight(165,670));
//JFrame
this.setTitle("QQ2006");
this.setIconImage(Adom.icon);
this.setSize(165,670);
this.setResizable(false);
Container c =this.getContentPane();
c.setLayout(null);
mpTop.setLayout(null);
//构件最内层组建
addHaoYou();//---------------添加好友列表
jspHaoYou.setBackground(Color.white);
jpanel.setLayout(null); jpanel.setBackground(Color.white);
jpHaoYou1.setBounds(2,25,110,400);
jlHaoYou.setBounds(2,3,110,20);
jlHaoYou.addActionListener(this);
jlMoShengRen.setBounds(2,435,110,20); jlMoShengRen.addActionListener(this);
jlHeiMingDan.setBounds(2,460,110,20); jlHeiMingDan.addActionListener(this);
jlHaoYou.setOpaque(false); jlHaoYou.setBorder(null);
jlMoShengRen.setBorder(null); jlMoShengRen.setOpaque(false);
jlHeiMingDan.setBorder(null); jlHeiMingDan.setOpaque(false);
jpanel.add(jpHaoYou1,null);
jpanel.add(jlHaoYou,null);jpanel.add(jlMoShengRen,null);jpanel.add(jlHeiMingDan,null);
//----------------------------------------------------------------------
//构件中层面板
jpCard1.setLayout(null);
for (int i = 0; i<imLabel.length; i++)
{
imLabel[i] = new ImageIcon("img/Main/"+(i+3)+".png");
}
for (int i = 0; i<jbLabel.length; i++)
{
jbLabel[i] = new JButton();
jbLabel[i].setBorder(null);
jbLabel[i].setOpaque(false);
jbLabel[i].addActionListener(this);
jbLabel[i].addMouseListener(new mm());
}
jpQun.setLayout(null);
jbLabel[0].setIcon(imLabel[0]); jbLabel[1].setIcon(imLabel[2]);
jpHaoYou.add(jbLabel[0],BorderLayout.NORTH); jpHaoYou.add(jpanel);
jpHaoYou.setBackground(Color.white);
jbLabel[1].setBounds(0,0,120,20);
QQC.setBounds(0,20,140,500);
jpQun.setBackground(Color.white);
jpQun.add(jbLabel[1],null);
jpQun.add(QQC,null);
jpQun.setBackground(Color.white);
jpHaoYou.setBounds(1,1,120,500); jpQun.setBounds(1,503,120,20);
jpHaoYou.setBackground(Color.white); jpHaoYou.setBackground(Color.white);
jpCard1.add(jpQun,null); jpCard1.add(jpHaoYou,null);
jpCard1.setBackground(Color.white);
//----------------------------------------------------------------------
//构件手型面板
jpCard2.add("Card1",jpCard1);//好友面板
jpCard2.add("Card2",jpYinYue);//音乐面板
jpCard2.add("Card3",jpYouXiang);//油箱面板
jpCard2.setBackground(Color.white);
jtp.setLayout(null); jtp.setOpaque(false);
jbHY.setBounds(0,2,27,37);
jbYY.setBounds(0,37,27,37);
jbYX.setBounds(0,72,27,37);
jpCard2.setBounds(28,2,120,530);
jtp.add(jbHY,null); jtp.add(jbYY,null); jtp.add(jbYX,null);
jtp.add(jpCard2,null);
//----------------------------------------------------------------------
//构件外部背景面板
mp.setLayout(new BorderLayout());
mp.add(jtp); mp.add(jlBottom,BorderLayout.SOUTH);
//----------------------------------------------------------------------
//构件下层彩旦
mpBottom.setLayout(new FlowLayout(FlowLayout.LEFT));
mpBottom.add(jbCaiDan);jbCaiDan.setBorder(null);
jbCaiDan.setOpaque(false); jbCaiDan.addActionListener(this);
jbCaiDan.addMouseListener(new mm());
QQp.setBounds(0,0,165,45);
mpTop.add(QQp,null);
mpTop.setBounds(0,0,165,50);
mp.setBounds(0,50,165,557); mpBottom.setBounds(0,607,165,53);
//----------------------------------------------------------------------
c.add(mp,null); c.add(mpBottom,null);
c.add(mpTop,null);
this.show();
}
//添加好友---------
private void addHaoYou()
{
if(friend.size()>0)
{
jpHaoYou1.setLayout(null);
jpHaoYou1.setBackground(Color.white);
int x1 = 0,y1 = 5;
u1 = new User[friend.size()];
for (int i = 0; i<u1.length; i++)
{
Vector x = (Vector)friend.elementAt(i);
String shead = x.elementAt(0).toString();
String spn = x.elementAt(1).toString();
String sid = x.elementAt(2).toString();
if(sid.equals(this.selfId))
{ //将本人信息置顶
this.selfHead = shead;
this.selfPn = spn;
QQp = new QQPhoto(spn,shead,sid);
}
else
{
u1[i] = new User(client,selfId,selfPn,shead,spn,sid);
u1[i].setBounds(x1,y1,130,50);
y1+=50;
jpHaoYou1.add(u1[i],null);
u1[i].jbFace.addActionListener(this);
}
}
}
}
public void actionPerformed(ActionEvent e)
{
//测试
/*for (int i = 0; i<u1.length; i++)
{
if(e.getSource().equals(u1[i].jbFace))
{
u1[i].sur();
}
}*/
//----------------------------------------------------------------------
if(e.getSource().equals(jlHaoYou))
{
if(flag)
{
jlHaoYou.setIcon(imClosed);
jpHaoYou1.show(false);
jlMoShengRen.setBounds(2,25,120,20);
jlHeiMingDan.setBounds(2,50,120,20);
flag = false;
}
else
{
jlHaoYou.setIcon(imOpen);
jpHaoYou1.show();
jlMoShengRen.setBounds(2,435,120,20);
jlHeiMingDan.setBounds(2,460,120,20);
flag = true;
}
}
for (int i = 0; i<jbLabel.length; i++)
{
if(e.getSource().equals(jbLabel[i]))
{
if(flag1)
{
jpHaoYou.setBounds(1,1,120,500);
jpQun.setBounds(1,503,120,20);
jpanel.show();
flag1 = false;
}
else
{
jpQun.setBounds(1,23,120,800);
jpQun.setBackground(Color.white);
jpanel.show(false);
flag1 = true;
}
}
}
if(e.getSource().equals(jbCaiDan))
{
}
}
class mm extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
if(e.getSource().equals(jbLabel[0]))
{
jbLabel[0].setIcon(imLabel[1]);
}
if(e.getSource().equals(jbLabel[1]))
{
jbLabel[1].setIcon(imLabel[3]);
}
if(e.getSource().equals(jbCaiDan))
{
jbCaiDan.setIcon(imCai2);
}
}
public void mouseReleased(MouseEvent e)
{
jbLabel[0].setIcon(imLabel[0]);
jbLabel[1].setIcon(imLabel[2]);
jbCaiDan.setIcon(imCai1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -