这是源码 需要做的是 右键点击在线好友和不在线的好友的子节点能弹出PopupMenu
有什么问题 马上题
public class FriendTree implements TreeSelectionListener
{
private DefaultTreeModel treemode;
private String nodenameAll;
private DefaultMutableTreeNode root=new DefaultMutableTreeNode( "我的好友 ");
private JTree tree=new JTree(root);
private DefaultMutableTreeNode online ;
private DefaultMutableTreeNode notonline;
private Client client=new Client();
FriendTree(Client client)
{
this.client=client;
}
public JTree chushi()//未加任何好友的情况
{
treemode=(DefaultTreeModel)tree.getModel();//得到DefaultTreeModel
online =new DefaultMutableTreeNode( "在线的好友 ");
notonline =new DefaultMutableTreeNode( "不在线的好友 ");
treemode.insertNodeInto(online , root,0);
treemode.insertNodeInto(notonline ,root,1);
tree.setRowHeight(20);
tree.scrollPathToVisible(new TreePath(notonline.getPath()));
tree.addMouseListener(new MouseListenerimp());
return tree;
}
public JTree onlinefriend(User user,int id)
{
treemode=(DefaultTreeModel)tree.getModel();//得到DefaultTreeModel
for(int i=0;i <user.getFriend().size();i++)
{
user=(User)user.getFriend().elementAt(0);
if(user.getStatus()==0)
{
System.out.println( "tree "+user.getID());//好于的ID
DefaultMutableTreeNode newNode=new DefaultMutableTreeNode(String.valueOf(user.getID()));
treemode.insertNodeInto(newNode , online, i);
tree.scrollPathToVisible(new TreePath(newNode.getPath()));
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);//只能选取一个节点
tree.addMouseListener(new MouseListenerimp());
System.out.println( "dsfasfa ");
}
}
return tree;
}
public void addonlinefriend(int id)
{
treemode=(DefaultTreeModel)tree.getModel();//得到DefaultTreeModel
DefaultMutableTreeNode newNode=new DefaultMutableTreeNode(String.valueOf(id));
treemode.insertNodeInto(newNode , online, 0);
tree.setRowHeight(20);
tree.scrollPathToVisible(new TreePath(newNode.getPath()));
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);//只能选取一个节点
tree.setRowHeight(20);
}
public void addnotonlinefriend(int id)
{
treemode=(DefaultTreeModel)tree.getModel();//得到DefaultTreeModel
DefaultMutableTreeNode newNode=new DefaultMutableTreeNode(String.valueOf(id));
treemode.insertNodeInto(newNode , notonline, notonline.getChildCount());
tree.scrollPathToVisible(new TreePath(newNode.getPath()));
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);//只能选取一个节点
tree.setRowHeight(30);
}
public void liveline(User user,int id)
{
delNode(user,id);//首先在在线的好友节点中 删除离线的那位好友
addNode(id);//再在不在线的好友节点中 添加离线的那位好友
}
public void shangxian(User user,int id)