继续完善功能,后面的路还很长。。。
今天还用这个小示例程序给别人讲了次课,发现自己的演讲天赋还是不错的,讲完后闻及感受,说我讲的听通俗易懂的,例子比喻也很不错,开心,呵呵。。。
clientMain.java
out.println( this .clientCmd);
this .serverMsg = in.readLine();
strTmp = this .serverMsg.split(spliter);
if (strTmp[ 0 ].equals( new String( " getbuddys " )))
{
this.creatBuddyList(strTmp); //用服务器传过来的好友数据建列表
}
private void creatBuddyList(String[] buddys)
{
DefaultMutableTreeNode buddy = null;
for(int i=1;i<buddys.length;i++)
{
buddy = new DefaultMutableTreeNode(buddys[i]);
root.add(buddy);
}
}
JPanel jPanel1 = new JPanel();
DefaultMutableTreeNode root = new DefaultMutableTreeNode( " 我的好友 " );
JTree buddyTree = new JTree(root);
JScrollPane jScrollPane1 = new JScrollPane(buddyTree);
SeverThread.java
else
if
(msgTmp[
0
].equals(
new
String(
"
getbuddys
"
)))
{//获取好友列表
String clientID = msgTmp[1];//获取客户id号
String buddyName;
com.vitamin.DataAccess.DBbase myDb = new DBbase();
this.sql = "select * from buddies where user = "+clientID;
this.rs = myDb.executeQuery(this.sql);
while(rs.next())
{
buddyName = rs.getString("buddy");
this.serverMsg += buddyName;
}
this.out.println(this.serverMsg);
}
{//获取好友列表
String clientID = msgTmp[1];//获取客户id号
String buddyName;
com.vitamin.DataAccess.DBbase myDb = new DBbase();
this.sql = "select * from buddies where user = "+clientID;
this.rs = myDb.executeQuery(this.sql);
while(rs.next())
{
buddyName = rs.getString("buddy");
this.serverMsg += buddyName;
}
this.out.println(this.serverMsg);
}
运行结果: