标题:
用java编写ICQ
[打印本页]
作者:
bigblock
时间:
2005-1-17 01:36
标题:
用java编写ICQ
面板的代码
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import java.util.Vector; import java.net.*; import java.io.*; class FindFriend2 extends JFrame {//查找好友类 JLabel jLabel1 = new JLabel(); JButton find2 = new JButton(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JButton jButton3 = new JButton(); JList list2; ///////////////////以下是好友的呢称,性别等信息 Vector nickname=new Vector(); Vector sex=new Vector(); Vector place=new Vector(); Vector jicq=new Vector(); Vector ip=new Vector(); Vector pic=new Vector(); Vector status=new Vector(); Vector emails=new Vector(); Vector infos=new Vector(); //以下临时保存好友的呢称,性别等信息 Vector tmpjicq=new Vector();//jicqid Vector tmpname=new Vector();//jicqname Vector tmpip=new Vector();//ip Vector tmppic=new Vector();//pic info Vector tmpstatus=new Vector();//status Vector tmpemail=new Vector(); Vector tmpinfo=new Vector(); //以下创建网络相关变量 Socket socket; BufferedReader in; PrintWriter out; int myid; String serverhost; int servport; DatagramPacket sendPacket; DatagramSocket sendSocket; int sendPort=5000; ////////////////// JPopupMenu findmenu = new JPopupMenu(); JMenuItem look = new JMenuItem(); JMenuItem add = new JMenuItem(); public FindFriend2(int whoami,String host,int port) {//查找好友类构造函数 enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { serverhost=host; servport=port; myid=whoami; jbInit(); } catch(Exception e) { e.printStackTrace(); }//以下与服务器连接 try{socket=new Socket(InetAddress.getByName(serverhost),servport); in=new BufferedReader(new InputStreamReader(socket.getInputStream())); out=new PrintWriter(new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true); sendSocket=new DatagramSocket(); }catch(IOException e1){} } private void jbInit() throws Exception {//以下是程序界面 jLabel1.setText("下面是在线的朋友"); jLabel1.setBounds(new Rectangle(11, 11, 211, 18)); this.getContentPane().setLayout(new FlowLayout()); find2.setText("查找"); find2.setBounds(new Rectangle(8, 289, 79, 29)); find2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { find2_mouseClicked(e); } }); jButton1.setText("next"); jButton1.setBounds(new Rectangle(110, 288, 79, 29)); jButton2.setText("up"); jButton2.setBounds(new Rectangle(211, 285, 79, 29)); jButton3.setText("cancel"); jButton3.setBounds(new Rectangle(317, 289, 79, 29)); // nickname=new Vector(); // sex=new Vector(); // place=new Vector(); ListModel model=new FindListModel(nickname,sex,place);//列表模型 ListCellRenderer renderer=new FindListCellRenderer(); list2=new JList(model); list2.setSize(200,200); list2.setBackground(new Color(255, 255, 210)); list2.setAlignmentX((float) 1.0); list2.setAlignmentY((float) 1.0); list2.setCellRenderer(renderer); list2.setVisibleRowCount(7); list2.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(MouseEvent e) { list2_mousePressed(e); } }); look.setText("查看资料"); add.setText("加为好友"); add.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(MouseEvent e) { add_mousePressed(e); } }); this.getContentPane().add(jLabel1, null); this.getContentPane().add(new JScrollPane(list2)); this.getContentPane().add(find2, null); this.getContentPane().add(jButton1, null); this.getContentPane().add(jButton2, null); this.getContentPane().add(jButton3, null); findmenu.add(look); findmenu.add(add); }//以下是关闭本窗口 protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { //this.dispose(); this.hide(); } } //以下向服务器发送查找好友请求 void find2_mouseClicked(MouseEvent e) { out.println("find"); DefaultListModel mm=(DefaultListModel)list2.getModel(); /////////////////find friend info try{ String s=" "; //从服务器读取好友信息 do{ s=in.readLine(); if(s.equals("over")) break; nickname.add(s); sex.add(in.readLine()); place.add(in.readLine()); ip.add(in.readLine()); emails.add(in.readLine()); infos.add(in.readLine()); }while(!s.equals("over")); /////////////end find info //read their jicqno int theirjicq,picinfo,sta; for(int x=0;x
=friendnames.size()){ fromunknow=true;//收到陌生人的消息 JOptionPane.showMessageDialog(this,"收到陌生人"+infofromip+"的消息","ok",JOptionPane.INFORMATION_MESSAGE); } }while(index4
)}); } } public String getName(Object object) { Object[] array=(Object[])object; return(String) array[0]; } public Icon getIcon(Object object) { Object[] array=(Object[]) object; return (Icon) array[1]; } } class NameAndPicListCellRenderer extends JLabel implements ListCellRenderer { private Border lineBorder=BorderFactory.createLineBorder(Color.red,2), emptyBorder =BorderFactory.createEmptyBorder(2,2,2,2); public NameAndPicListCellRenderer(){ setOpaque(true); } public Component getListCellRendererComponent(JList list,Object value,int index, boolean isSelected,boolean cellHasFocus) { NameAndPicListModel model=(NameAndPicListModel) list.getModel(); setText(model.getName(value)); setIcon(model.getIcon(value)); if(isSelected){setForeground(list.getSelectionForeground()); setBackground(list.getSelectionBackground()); } else { setForeground(list.getForeground()); setBackground(list.getBackground());} if(cellHasFocus) setBorder(lineBorder); else setBorder(emptyBorder); return this; } } class MainWin_list_mouseAdapter extends java.awt.event.MouseAdapter { MainWin adaptee; MainWin_list_mouseAdapter(MainWin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.list_mouseClicked(e); } } class MainWin_direct_mouseAdapter extends java.awt.event.MouseAdapter { MainWin adaptee; MainWin_direct_mouseAdapter(MainWin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.direct_mouseClicked(e); } } class MainWin_ok_mouseAdapter extends java.awt.event.MouseAdapter { MainWin adaptee; MainWin_ok_mouseAdapter(MainWin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.ok_mouseClicked(e); } } class MainWin_sendmessage_mouseAdapter extends java.awt.event.MouseAdapter { MainWin adaptee; MainWin_sendmessage_mouseAdapter(MainWin adaptee) { this.adaptee = adaptee; } public void mousePressed(MouseEvent e) { adaptee.sendmessage_mousePressed(e); } } class MainWin_cancel_mouseAdapter extends java.awt.event.MouseAdapter { MainWin adaptee; MainWin_cancel_mouseAdapter(MainWin adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.cancel_mouseClicked(e); } }
登陆窗口代码
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.net.*; import java.io.*; public class New extends JFrame {//登录窗口类 JPanel contentPane; //***************** String server;//服务器名 int serport;//端口 private Socket socket; private BufferedReader in;//输入输出流 private PrintWriter out; //***********//程序界面 JPanel jPanel1 = new JPanel(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JTextField jicq = new JTextField(); JLabel jLabel3 = new JLabel(); JPasswordField password = new JPasswordField(); JPanel jPanel2 = new JPanel(); JButton login = new JButton(); JButton newuser = new JButton(); JButton quit = new JButton(); JLabel jLabel6 = new JLabel(); JTextField servername = new JTextField(); JLabel jLabel7 = new JLabel(); JTextField serverport = new JTextField(); public New() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); server=servername.getText().toString().trim(); serport=Integer.parseInt(serverport.getText().trim()); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(null); this.setResizable(false); this.setSize(new Dimension(344, 245)); this.setTitle("New JICQ"); //contentPane.add(text, null); jPanel1.setBounds(new Rectangle(2, 3, 348, 110)); jPanel1.setLayout(null); jLabel1.setText("请输入你的信息"); jLabel1.setBounds(new Rectangle(5, 7, 103, 18)); jLabel2.setText("你的Jicq"); jLabel2.setBounds(new Rectangle(7, 66, 58, 18)); jicq.setBounds(new Rectangle(68, 65, 97, 22)); jLabel3.setText("你的密码"); jLabel3.setBounds(new Rectangle(173, 66, 67, 18)); password.setBounds(new Rectangle(237, 63, 94, 22)); jPanel2.setBounds(new Rectangle(8, 154, 347, 151)); jPanel2.setLayout(null); login.setText("登录"); login.setBounds(new Rectangle(5, 27, 79, 29)); login.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { login_mouseClicked(e); } }); newuser.setText("新建"); newuser.setBounds(new Rectangle(118, 28, 79, 29)); newuser.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { newuser_mouseClicked(e); } }); quit.setText("退出"); quit.setBounds(new Rectangle(228, 26, 79, 29)); quit.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { quit_mouseClicked(e); } }); jLabel6.setText("服务器"); jLabel6.setBounds(new Rectangle(20, 132, 41, 18)); servername.setText("hg"); servername.setBounds(new Rectangle(73, 135, 102, 22)); jLabel7.setText("端口"); jLabel7.setBounds(new Rectangle(191, 137, 41, 18)); serverport.setText("8080"); serverport.setBounds(new Rectangle(241, 131, 90, 30)); contentPane.add(jPanel1, null); jPanel1.add(jLabel1, null); jPanel1.add(jLabel2, null); jPanel1.add(jicq, null); jPanel1.add(jLabel3, null); jPanel1.add(password, null); contentPane.add(jPanel2, null); jPanel2.add(login, null); jPanel2.add(quit, null); jPanel2.add(newuser, null); contentPane.add(jLabel6, null); contentPane.add(servername, null); contentPane.add(jLabel7, null); contentPane.add(serverport, null); } protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public static void main(String[] args) {//主程序 New f=new New(); f.setVisible(true); } void login_mouseClicked(MouseEvent e) {//登录按扭 try{Socket socket=new Socket(InetAddress.getByName(server),serport);//连接服务器 BufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter out=new PrintWriter(new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true); out.println("login");//告诉服务器我要登录 out.println(jicq.getText()); out.println(password.getPassword()); String str=" "; //do{ str=in.readLine().trim();//从服务器读取消息 //如果失败就告诉出错 if(str.equals("false")) JOptionPane.showMessageDialog(this,"对不起,出错了:-(","ok",JOptionPane.INFORMATION_MESSAGE); else{//如果成功就打开主程序 this.dispose(); int g=Integer.parseInt(jicq.getText()); MainWin f2=new MainWin(g,server,serport); f2.setVisible(true); } //System.out.println("\n"); //}while(!str.equals("ok")); }catch(IOException e1){} } void newuser_mouseClicked(MouseEvent e) {//新建用户按纽 this.dispose(); JDialog d=new Register(server,serport);//打开新建窗口 d.pack(); d.setLocationRelativeTo(this); d.setSize(400,400); d.show(); } void quit_mouseClicked(MouseEvent e) {//关闭按扭 this.dispose(); System.exit(0); } }
注册窗口代码
import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.net.*; import java.io.*; import javax.swing.border.*; public class Register extends JDialog {//新建用户类 //以下创建程序界面 JPanel panel1 = new JPanel(); JLabel jLabel1 = new JLabel(); JTextField nickname = new JTextField(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JPasswordField password = new JPasswordField(); JLabel jLabel4 = new JLabel(); JTextField email = new JTextField(); JLabel jLabel5 = new JLabel(); JLabel jLabel6 = new JLabel(); JTextPane info = new JTextPane(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JLabel jLabel7 = new JLabel(); JRadioButton boy = new JRadioButton(); JRadioButton girl = new JRadioButton(); JLabel jLabel8 = new JLabel(); JComboBox place = new JComboBox(); JComboBox headpic = new JComboBox(); //*************************** private String[] pics = new String[] {//头像 "1.jpg", "3.jpg", "5.jpg", "7.jpg"}; String sername;//服务器名 int serverport;//服务器端口 public Register(String s,int port) {//构造函数 sername=s; serverport=port; try { jbInit();//创建窗口 pack(); } catch(Exception ex) { ex.printStackTrace();} //this(null, "", true); } void jbInit() throws Exception {//创建窗口 panel1.setLayout(null); this.getContentPane().setLayout(null); panel1.setMaximumSize(new Dimension(200, 200)); panel1.setMinimumSize(new Dimension(200, 100)); panel1.setBounds(new Rectangle(-2, 0, 419, 452)); this.setTitle("register"); jLabel1.setText("昵称"); jLabel1.setBounds(new Rectangle(9, 45, 41, 18)); nickname.setBounds(new Rectangle(50, 44, 128, 22)); jLabel2.setText("请填写以下内容"); jLabel2.setBounds(new Rectangle(9, 9, 103, 18)); jLabel3.setText("密码"); jLabel3.setBounds(new Rectangle(200, 44, 41, 18)); password.setBounds(new Rectangle(247, 42, 100, 22)); jLabel4.setText("电子邮件"); jLabel4.setBounds(new Rectangle(2, 102, 58, 18)); email.setBounds(new Rectangle(55, 96, 124, 22)); jLabel5.setText("头像"); jLabel5.setBounds(new Rectangle(193, 96, 51, 18)); //*************** ComboBoxModel model = new HeadPicCombobox(pics); ListCellRenderer renderer = new HeadpicCellRenderer(); jLabel6.setText("个人资料"); jLabel6.setBounds(new Rectangle(6, 189, 87, 18)); info.setBounds(new Rectangle(5, 208, 363, 103)); jButton1.setText("确定"); jButton1.setBounds(new Rectangle(147, 330, 79, 29)); jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { jButton1_mouseClicked(e); } }); jButton2.setText("取消"); jButton2.setBounds(new Rectangle(260, 329, 79, 29)); jLabel7.setText("性别"); jLabel7.setBounds(new Rectangle(9, 156, 41, 18)); boy.setText("男"); boy.setBounds(new Rectangle(43, 152, 38, 26)); girl.setText("女"); girl.setBounds(new Rectangle(80, 152, 36, 26)); jLabel8.setText("来自"); jLabel8.setBounds(new Rectangle(147, 154, 41, 18)); place.setToolTipText(""); place.addItem("四川"); place.addItem("重庆"); place.setBounds(new Rectangle(181, 153, 163, 22)); headpic.setBounds(new Rectangle(249, 91, 71, 28)); headpic.setModel(model); headpic.setRenderer(renderer); this.getContentPane().add(jButton1, null); this.getContentPane().add(panel1, null); panel1.add(jLabel2, null); panel1.add(jLabel1, null); panel1.add(nickname, null); panel1.add(jLabel3, null); panel1.add(password, null); panel1.add(jLabel4, null); panel1.add(email, null); panel1.add(jLabel5, null); panel1.add(info, null); panel1.add(jButton2, null); panel1.add(jLabel6, null); panel1.add(jLabel7, null); panel1.add(boy, null); panel1.add(jLabel8, null); panel1.add(girl, null); panel1.add(place, null); panel1.add(headpic, null); } void jButton1_mouseClicked(MouseEvent e) { try{ System.out.println(sername); System.out.println(serverport); Socket socket=new Socket(InetAddress.getByName(sername),serverport);//连接服务器 BufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter out=new PrintWriter(new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true); out.println("new");//发送新建用户请求 out.println(nickname.getText().trim());//发送呢称等信息 out.println(password.getPassword()); out.println(email.getText().trim()); out.println(info.getText().trim()); out.println(place.getSelectedItem()); out.println(headpic.getSelectedIndex());//head picindex int no; no=Integer.parseInt(in.readLine()); System.out.print(no); String str=" "; //do{ str=in.readLine().trim();//从服务器读取信息 //如果出错 if(str.equals("false")) JOptionPane.showMessageDialog(this,"对不起,出错了:-(","ok",JOptionPane.INFORMATION_MESSAGE); else{//如果成功就告诉用户其号码 JOptionPane.showMessageDialog(this,"your javaicq#is"+no,"ok",JOptionPane.INFORMATION_MESSAGE); this.dispose();//并打开主窗口 MainWin f2=new MainWin(no,sername,serverport); f2.setVisible(true);} //System.out.println("\n"); //}while(!str.equals("ok")); // socket.close(); }catch(IOException e1){} } } class HeadPicCombobox extends DefaultComboBoxModel {//头象列表类 public HeadPicCombobox(String[] pics) { for(int i=0; i < pics.length; ++i) { addElement(new Object[] { new ImageIcon(pics
) } ); } } public Icon getIcon(Object object) { Object[] array = (Object[])object; return (Icon)array[0]; } } class HeadpicCellRenderer extends JLabel implements ListCellRenderer { private Border lineBorder = BorderFactory.createLineBorder(Color.red, 2), emptyBorder = BorderFactory.createEmptyBorder(2,2,2,2); public HeadpicCellRenderer() { setOpaque(true); } public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) { HeadPicCombobox model =(HeadPicCombobox)list.getModel(); setIcon(model.getIcon(value)); if(isSelected) { setForeground(list.getSelectionForeground()); setBackground(list.getSelectionBackground()); } else { setForeground(list.getForeground()); setBackground(list.getBackground()); } if(cellHasFocus) setBorder(lineBorder); else setBorder(emptyBorder); return this; } }
服务器窗口代码
import java.io.*; import java.net.*; import java.sql.*; import java.util.Vector; class ServerThread extends Thread{//继承线程 private Socket socket;//定义套接口 private BufferedReader in;//定义输入流 private PrintWriter out;//定义输出流 int no;//定义申请的jicq号码 public ServerThread(Socket s) throws IOException {//线程构造函数 socket=s;//取得传递参数 in=new BufferedReader(new InputStreamReader(socket.getInputStream()));//创建输入流 out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);//创建输出流 start();//启动线程 } public void run(){//线程监听函数 try{ while(true){ String str=in.readLine();//取得输入字符串 if(str.equals("end"))break;//如果是结束就关闭连接 else if(str.equals("login")) {//如果是登录 try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//连接数据库 Connection c=DriverManager.getConnection("jdbc:odbc:javaicq"," "," "); String sql="select nickname,password from icq where icqno=?"; //准备从数据库选择呢称和密码 PreparedStatement prepare=c.prepareCall(sql);//设定数据库查寻条件 String icqno=in.readLine(); int g=Integer.parseInt(icqno);//取得输入的jicq号码 System.out.println(icqno); String passwd=in.readLine().trim();//取得输入的密码 System.out.println(passwd); prepare.clearParameters(); prepare.setInt(1,g);//设定参数 ResultSet r=prepare.executeQuery();//执行数据库查寻 if(r.next()){//以下比较输入的号码于密码是否相同 String pass=r.getString("password").trim(); System.out.println(pass); if(passwd.regionMatches(0,pass,0,pass.length())) { out.println("ok"); //如果相同就告诉客户ok //并且更新数据库用户为在线 //以及注册用户的ip 地址 //*************register ipaddress String setip="update icq set ip=? where icqno=?"; PreparedStatement prest=c.prepareCall(setip); prest.clearParameters(); prest.setString(1,socket.getInetAddress().getHostAddress()); prest.setInt(2,g); int set=prest.executeUpdate(); System.out.println(set); //*************ipaddress //set status online String status="update icq set status=1 where icqno=?"; PreparedStatement prest2=c.prepareCall(status); prest2.clearParameters(); prest2.setInt(1,g); int set2=prest2.executeUpdate(); System.out.println(set2); //set online } //否者告诉客户失败 else out.println("false");r.close();c.close();} else{ out.println("false"); System.out.println("false"); r.close(); c.close();} }catch (Exception e){e.printStackTrace();} socket.close(); }//end login //登录结束 //以下为处理客户的新建请求 else if(str.equals("new")){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//连接数据库 Connection c2=DriverManager.getConnection("jdbc:odbc:javaicq"," "," "); String newsql="insert into icq(nickname,password,email,info,place,pic) values(?,?,?,?,?,?)"; //准备接受用户的呢称,密码,email,个人资料,籍贯,头像等信息 PreparedStatement prepare2=c2.prepareCall(newsql); String nickname=in.readLine().trim(); String password=in.readLine().trim(); String email=in.readLine().trim(); String info=in.readLine().trim(); String place=in.readLine().trim(); int picindex=Integer.parseInt(in.readLine()); prepare2.clearParameters(); prepare2.setString(1,nickname); prepare2.setString(2,password); prepare2.setString(3,email); prepare2.setString(4,info); prepare2.setString(5,place); prepare2.setInt(6,picindex); int r3=prepare2.executeUpdate();//执行数据库添加 String sql2="select icqno from icq where nickname=?"; //以下告诉客户其注册的号码 PreparedStatement prepare3=c2.prepareCall(sql2); prepare3.clearParameters(); prepare3.setString(1,nickname); ResultSet r2=prepare3.executeQuery(); while(r2.next()){ //out.println(r2.getInt(1)); no=r2.getInt(1); System.out.println(no); } out.println(no); out.println("ok"); c2.close(); //完毕 }catch (Exception e){e.printStackTrace();out.println("false");} socket.close(); }//end new //新建用户结束 //以下处理用户查找好友 else if(str.equals("find")){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c3=DriverManager.getConnection("jdbc:odbc:javaicq"," "," "); //以下连接数据库,并且返回其他用户的呢称,性别,籍贯,个人资料等信息 String find="select nickname,sex,place,ip,email,info from icq"; Statement st=c3.createStatement(); ResultSet result=st.executeQuery(find); while(result.next()){ out.println(result.getString("nickname")); out.println(result.getString("sex")); out.println(result.getString("place")); out.println(result.getString("ip")); out.println(result.getString("email")); out.println(result.getString("info")); }//while end out.println("over"); ////////GET ICQNO int d,x; boolean y; //以下返回用户的jicq号码,头像号,及是否在线 ResultSet iset=st.executeQuery("select icqno,pic,status from icq"); while(iset.next()){ d=iset.getInt("icqno"); out.println(d); x=iset.getInt("pic");//pic info out.println(x); y=iset.getBoolean("status"); if (y){out.println("1");} else {out.println("0");} //System.out.println(d); } // end send jicqno iset.close(); /////////icqno end c3.close();result.close(); }catch (Exception e){e.printStackTrace();System.out.println("false");} //socket.close(); }//end find //查找好友结束 //以下处理用户登录时读取其好友资料 else if(str.equals("friend")){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c4=DriverManager.getConnection("jdbc:odbc:javaicq"," "," "); //以下连接好友表,返回用户的好友名单 String friend="select friend from friend where icqno=?"; PreparedStatement prepare4=c4.prepareCall(friend); prepare4.clearParameters(); int icqno=Integer.parseInt(in.readLine()); System.out.println(icqno); prepare4.setInt(1,icqno); ResultSet r4=prepare4.executeQuery(); Vector friendno=new Vector();//该矢量保存好友号码 while(r4.next()){ friendno.add(new Integer(r4.getInt(1))); } //read friend info //以下告诉客户其好友的呢称,号码,ip地址,状态,头像,个人资料等信息 out.println(friendno.size()); for(int i=0;i
欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/)
Powered by Discuz! 7.2