Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1529284
  • 博文数量: 3500
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 43870
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-03 20:31
文章分类

全部博文(3500)

文章存档

2008年(3500)

我的朋友

分类:

2008-05-04 19:34:28

一起学习
小弟最近从网站上下了一个JICQ 可是不知道怎么回事,编译时没有问题!!就是运行不了!! 请各位高手指教!!! 谢谢!!!!!!!!!!!!!!! 分New.java Server.java MainWin.java Register.java 1.//New.java如下 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); } } 2.//Register.java如下 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[i]) } ); } } 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; } } 3.//MainWin.java如下 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 下载本文示例代码


小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事小弟最近从网站上下了一个JICQ 可是不知道怎么回事
阅读(119) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~