当前位置: 代码迷 >> Java相关 >> 怎样制作QQ好友列表的界面?
  详细解决方案

怎样制作QQ好友列表的界面?

热度:170   发布时间:2010-05-04 19:19:19.0
怎样制作QQ好友列表的界面?
现在在搞Socket通信,想做一个QQ类似的东西玩玩,
觉得那个好友列表的界面好简单,只是组件的显示隐藏就好了!
可是搞了好久都没出结果,布局出现了问题,
请高手指点一二!
搜索更多相关的解决方案: 界面  好友  列表  制作  

----------------解决方案--------------------------------------------------------

看看这个怎么样
----------------解决方案--------------------------------------------------------
swing做个QQ列表界面简直可以是轻而易举了,放一个没有边框的table就可以了

----------------解决方案--------------------------------------------------------
我写了一个简单的,自己改改,要睡觉了。

package qq;


public class Friend {

    //昵称
    private String displayName;
    //唯一标识
    private int id;
    //是否在线
    private boolean isOnLine;
   
    public Friend(String displayName, int id, boolean isOnLine) {
        this.displayName = displayName;
        this.id = id;
        this.isOnLine = isOnLine;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public boolean isOnLine() {
        return isOnLine;
    }

    public void setOnLine(boolean isOnLine) {
        this.isOnLine = isOnLine;
    }

}


package qq;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


public class FriendListPnl extends JPanel {
   
    private List<Friend> friends;
    private JButton[] friendList;
   
    public FriendListPnl(List<Friend> friends) {
        
        this.friends = friends;
        initFriendList();
        initGUI();
    }
   
    private void initGUI()
    {
        this.setLayout(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        constraints.gridx = 0;
        constraints.ipadx = 1;
        constraints.ipady = 1;
        constraints.anchor = GridBagConstraints.NORTHWEST;
        for (int i = 0; i < friendList.length; i++) {
            constraints.gridy = i;
            if (i == friendList.length - 1)
            {
                constraints.weighty = 1.0;
            }
            this.add(friendList[i], constraints);
        }
    }
   
    private void initFriendList()
    {
        friendList = new JButton[friends.size()];
        Dimension d = new Dimension(100, 22);
        JButton friend = null;
        Friend friendInfo = null;
        for (int i = 0; i < friendList.length; i++) {
            friend = new JButton();
            friend.addActionListener(new ActionListener() {
               
                @Override
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(null, "您好!");
                }
            });
            friend.setBorder(null);
            friendInfo = friends.get(i);
            friend.setText(new StringBuffer().append(friendInfo.getDisplayName())
                    .append("(").append(friendInfo.getId()).append(")").toString());
            friend.setPreferredSize(d);
            friend.setEnabled(friendInfo.isOnLine());
            friendList[i] = friend;
        }
        
    }

}


package qq;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JScrollPane;

public class TestFrame {
   
    public static void main(String[] args) {
        
        Friend f1 = new Friend("天下", 22, true);
        Friend f2 = new Friend("倚天", 21, false);
        Friend f3 = new Friend("屠龙", 20, true);
        
        List<Friend> list = new ArrayList<Friend>();
        list.add(f1);
        list.add(f2);
        list.add(f3);
        
        JFrame frame = new JFrame("QQ");
        frame.setSize(150, 350);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation(new Point(d.width - frame.getWidth() - 25, 10));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new JScrollPane(new FriendListPnl(list)));
        
        frame.setVisible(true);
        
    }

}

----------------解决方案--------------------------------------------------------
前来学习
----------------解决方案--------------------------------------------------------
谢谢各位!
----------------解决方案--------------------------------------------------------
来看看
----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽
2010-05-12 03:45:29
ljwei

等 级:论坛游侠
威 望:1
帖 子:46
专家分:192
注 册:2009-9-18
  得分:0 
.....
----------------解决方案--------------------------------------------------------
  相关解决方案