⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwin.java.bak

📁 本系统充分利用了Java语言的平台无关性等众多优点
💻 BAK
📖 第 1 页 / 共 3 页
字号:
  void list_mouseClicked(MouseEvent e) {
    jPopupMenu1.show(this, e.getX() + 20, e.getY() + 20);
  }

  void direct_mouseClicked(MouseEvent e) { //直接添加好友
    DirectAdd.setLocationRelativeTo(MainWin.this);
    DirectAdd.setSize(260, 160);
    DirectAdd.show();
// JOptionPane.showMessageDialog(this,":-(对不起,还有好多没做出来.hg","ok",JOptionPane.INFORMATION_MESSAGE);

  }

  void ok_mouseClicked(MouseEvent e) {
    about.dispose();
  }

  void cancel_mouseClicked(MouseEvent e) {
    senddata.dispose();
  }
  void sendmessage_mousePressed(MouseEvent e) { //发消息菜单
    senddata.setLocationRelativeTo(MainWin.this);
    senddata.setBounds(e.getX() + 50, e.getY() + 50, 400, 280);
    index = list.getSelectedIndex();
    System.out.println(index);
    nametext.setText(friendnames.get(index).toString());
    senddata.setTitle("与"+friendnames.get(index).toString()+"聊天");
    icqno.setText(friendjicq.get(index).toString());
    theip = friendips.get(index).toString(); //ip address
    System.out.println(theip);
    senddata.show();

  }
//具体实现按钮双击的功能的方法
public boolean checkClickTime() {
    Date d = new Date();
 long nowTime = d.getTime();

if ( (nowTime - clickTime) < 300) {
clickTime = nowTime;
return true;
}
clickTime = nowTime;
return false;

}
//双击事件
  void jList1_mouseReleased(MouseEvent e) {
//    判断是否双击,是的话写你要实现的功能
    if (checkClickTime()) {
      senddata.setLocationRelativeTo(MainWin.this);
    senddata.setBounds(e.getX() + 50, e.getY() + 50, 400, 280);
    index = list.getSelectedIndex();
    System.out.println(index);
    nametext.setText(friendnames.get(index).toString());
    senddata.setTitle("与"+friendnames.get(index).toString()+"聊天");
    icqno.setText(friendjicq.get(index).toString());
    theip = friendips.get(index).toString(); //ip address
    System.out.println(theip);
    senddata.show();


    }
  }
  void find_mouseClicked(MouseEvent e) { //显示查找好友窗口

    findf.show();
  } //find

  void send_mouseClicked(MouseEvent e) { //发送消息
//*********send message*********/
    try {
      String s = sendtext.getText().trim();
      // System.out.println(s);
      byte[] data = s.getBytes();
      System.out.println(theip);
      theip.trim();
      if (theip.equals("null") || theip.equals(" ") || theip.equals("0")) {
        JOptionPane.showMessageDialog(this, "对不起,不在线", "ok",
                                      JOptionPane.INFORMATION_MESSAGE);
      }
      else {
        sendPacket = new
            DatagramPacket(data, s.length(), InetAddress.getByName(theip),
                           sendPort);
        sendSocket.send(sendPacket);
      }

    }
    catch (IOException e2) {
      sendtext.append(sendtext.getText());
      e2.printStackTrace();
    }
    senddata.dispose();
//*******end send message
  }

  void getmessage_mousePressed(MouseEvent e) { //接受消息菜单
    System.out.println("zhy receiving1...." + received);
    String message = received.trim();
    System.out.println("zhy receiving2...." + received);
    index = list.getSelectedIndex();
    if (index == index4)
      getinfo.append(message);
    else
      getinfo.append(" ");
    getfromname.setText(friendnames.get(index).toString().trim());
    getfromjicq.setText(friendjicq.get(index).toString().trim());
    getdata.show();
  }

  void getok_mouseClicked(MouseEvent e) { //接受消息
    getinfo.setText(" ");
    getdata.dispose();
    received = " ";
  }

//update friend info;
  void update_mouseClicked(MouseEvent e) { //更新好友列表
    tempname = findf.tmpname;
    tempjicq = findf.tmpjicq;
    tempip = findf.tmpip;
    temppic = findf.tmppic;
    tempstatus = findf.tmpstatus;
    tempemail = findf.tmpemail;
    tempinfo = findf.tmpinfo;
    DefaultListModel mm2 = (DefaultListModel) list.getModel();
    int picid = 0;
    for (int p = 0; p < tempname.size(); p++) {
      picid = Integer.parseInt(temppic.get(p).toString());
      if (status.get(p).equals("1")) {
        mm2.addElement(new Object[] {tempname.get(p),
                       new ImageIcon(picsonline[picid])});
      }
      else {
        mm2.addElement(new Object[] {tempname.get(p),
                       new ImageIcon(picsonline[picid])});
      }
//picid=Integer.parseInt(temppic.get(p).toString());
//mm2.addElement(new Object[]{tempname.get(p),new ImageIcon(picsonline[picid])});

    } //for
//add to friendlist
    for (int k = 0; k < tempname.size(); k++) {
      friendnames.add(tempname.get(k));
      friendjicq.add(tempjicq.get(k));
      friendips.add(tempip.get(k));
      picno.add(temppic.get(k));
      status.add(tempstatus.get(k));
      friendemail.add(tempemail.get(k));
      friendinfo.add(tempinfo.get(k));
    } //for
//clean tmp
    for (int p = 0; p < tempname.size(); p++) {
      findf.tmpip.removeAllElements();
      findf.tmpjicq.removeAllElements();
      findf.tmpname.removeAllElements();
      findf.tmppic.removeAllElements();
      findf.tmpstatus.removeAllElements();
      findf.tmpemail.removeAllElements();
      findf.tmpinfo.removeAllElements();
    }
  }

//delete freind
  void delfriend_mousePressed(MouseEvent e) { //删除好友
    out.println("delfriend");
    int index2;
    index2 = list.getSelectedIndex();

    out.println(friendjicq.get(index2)); //the friendjicq to del
    out.println(myjicq); //my jicqno
    DefaultListModel mm = (DefaultListModel) list.getModel();
    mm.removeElementAt(index2);
    friendnames.removeElementAt(index2);
    friendips.removeElementAt(index2);
    friendjicq.removeElementAt(index2);
    picno.removeElementAt(index2);
    status.removeElementAt(index2);
    friendemail.removeElementAt(index2);
    friendinfo.removeElementAt(index2);
  } //////////////delfriend

//tell friend i am online
  void online_mouseClicked(MouseEvent e) {
    out.println("getwhoaddme");
    out.println(myjicq);

    String whoip = " ";
    do {
      try {
        whoip = in.readLine().trim();
        if (whoip.equals("over"))
          break;
        whoaddmesip.add(whoip);
      }
      catch (IOException s) {
        System.out.println("false getwhoaddme");
      }
    }
    while (!whoip.equals("over"));
    for (int i = 0; i < whoaddmesip.size(); i++) {
      System.out.println(whoaddmesip.get(i));
    }
    try {
      String whoips;
      String s = "online" + myjicq;
      s.trim();
      System.out.println(s);
      byte[] data = s.getBytes();
      for (int i = 0; i < whoaddmesip.size(); i++) {
        whoips = whoaddmesip.get(i).toString().trim();
        sendPacket = new
            DatagramPacket(data, s.length(), InetAddress.getByName(whoips),
                           sendPort);
        sendSocket.send(sendPacket);
      } //for
    }
    catch (IOException e2) {
      sendtext.append(sendtext.getText());
      e2.printStackTrace();
      System.exit(1);
    }

  } /////end tellfrienonline

  void myinfo_mouseClicked(MouseEvent e) { //陌生人消息
    if (fromunknow) {
      String message = received.trim();
      getinfo.append(message);
      getdata.show();
    }

  }

  void lookinfo_mousePressed(MouseEvent e) { //查看好友资料菜单
    hello.setLocationRelativeTo(MainWin.this);
    hello.setBounds(e.getX() + 50, e.getY() + 50, 380, 300);
    index = list.getSelectedIndex();
    helloname.setText(friendnames.get(index).toString());
    hellojicq.setText(friendjicq.get(index).toString());
    helloemail.setText(friendemail.get(index).toString());
    helloinfo.setText(friendinfo.get(index).toString().trim());
    hello.show();
  }

  void hellook_mouseClicked(MouseEvent e) { //查看好友资料关闭
    hello.dispose();
  }

//add the one who add me as friend
  void addit_mouseClicked(MouseEvent e) {
//如果有人加我,我就加它
    out.println("addnewfriend");
    out.println(tempgetjicq);
    out.println(myjicq);
    String thename = " ";
    try {
      String thejicqno, theip, thestatus, picinfo, email, infos;
      do {
        thename = in.readLine();
        if (thename.equals("over"))
          break;
        friendnames.add(thename);
        thejicqno = in.readLine();
        friendjicq.add(new Integer(thejicqno));
        theip = in.readLine();
        friendips.add(theip);
        thestatus = in.readLine();
        status.add(thestatus);
        picinfo = in.readLine();
        picno.add(new Integer(picinfo));
        email = in.readLine();
        friendemail.add(email);
        infos = in.readLine();
        friendinfo.add(infos);
      }
      while (!thename.equals("over"));
    }
    catch (IOException e1) {
      System.out.println("false");
    }
    int dddd = friendnames.size() - 1;
    DefaultListModel mm2 = (DefaultListModel) list.getModel();
    int picid;
    picid = Integer.parseInt(picno.get(dddd).toString());
    mm2.addElement(new Object[] {friendnames.get(dddd),
                   new ImageIcon(picsonline[picid])});
  }

  void iknow_mouseClicked(MouseEvent e) {
    OneAddyou.dispose();
  }

  void directaddok_mouseClicked(MouseEvent e) { //直接添加好友
    out.println("addnewfriend");
    out.println(friendid.getText().trim());
    out.println(myjicq);
    String thename = " ";
    try {
      String thejicqno, theip, thestatus, picinfo, email, infos;
      do {
        thename = in.readLine();
        if (thename.equals("over"))
          break;
        friendnames.add(thename);
        thejicqno = in.readLine();
        friendjicq.add(new Integer(thejicqno));
        theip = in.readLine();
        friendips.add(theip);
        thestatus = in.readLine();
        status.add(thestatus);
        picinfo = in.readLine();
        picno.add(new Integer(picinfo));
        email = in.readLine();
        friendemail.add(email);
        infos = in.readLine();
        friendinfo.add(infos);
      }
      while (!thename.equals("over"));
    }
    catch (IOException e1) {
      System.out.println("false");
    }
    int dddd = friendnames.size() - 1;
    DefaultListModel mm2 = (DefaultListModel) list.getModel();
    int picid;
    picid = Integer.parseInt(picno.get(dddd).toString());
    mm2.addElement(new Object[] {friendnames.get(dddd),
                   new ImageIcon(picsonline[picid])});
    DirectAdd.dispose();
  }; ////////end directadd friend

} //end class MainWin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -