欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

JAVA,

来源: javaer 分享于  点击 36683 次 点评:155

JAVA,


在ClientLogin中,创建好友列表对象 String friendString=mess.getContent(); FriendList friendList=new FriendList(userName,friendString);注:在FriendList中,改单参量类型为双参量类型2. 从数据库relation表中读取好友信息来更新好友列表2.利用服务器发送来的好友名字(friendString)更新好友列表 String[] friendName=friendString.split(" “); int count=friendName.length; myFriendListJPanel=new JPanel(new GridLayout(count,1));//网格布局 for(int i=1;i<count;i++){ myFriendJLabel[i]=new JLabel(friendName[i]+”",new ImageIcon(“images/duck.gif”),JLabel.LEFT);更改成字符串形式 //myFriendJLabel[i].setEnabled(false);注释掉为了激活好友图标 //if(Integer.parseInt(userName)==i) myFriendJLabel[i].setEnabled(true); myFriendJLabel[i].addMouseListener(this); myFriendListJPanel.add(myFriendJLabel[i]);数据库的封装把和数据库相关的处理放在一个单独的类(YychatDbUtil),使得我们的程序逻辑更清晰。将StartServer中的使用数据库来验证用户名何密码的五个步骤//使用数据库来验证用户名和密码 Class.forName(“com.mysql.jdbc.Driver”); / String url=“jdbc:mysql://127.0.0.1:3306/yychat?useUnicode=true&charaterEncoding=UTF-8”; String dbuser=“root”; String dbpass=""; Connection conn=DriverManager.getConnection(url,dbuser,dbpass); String user_Login_Sql=“select * from user where username=? and password=?”; PreparedStatement ptmt=conn.prepareStatement(user_Login_Sql); ptmt.setString(1, userName); ptmt.setString(2, passWord); ResultSet rs=ptmt.executeQuery(); boolean loginSuccess=rs.next();*/放到新建的类(YychatDbUtil)中,用boolean loginSuccess=YychatDbUtil.looginValidate(userName,passWord)替换将StartServer中的//从数据库 relation表中读取好友信息来更新好友列表1.服务器读好友数据出来。 /String friend_Relation_Sql=“select slaveuser from relation where majoruser=? and relationtype=‘1’”; ptmt=conn.prepareStatement(friend_Relation_Sql); ptmt.setString(1 ,userName); rs=ptmt.executeQuery(); String friendString=" “; while(rs.next()){ friendString=friendString+rs.getString(“slaveuser”)+” "; }/用String friendString=YychatDbUtil.getFriendString(userName);替换。

相关文章

    暂无相关文章
相关栏目:

用户点评