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

📄 jicq.java

📁 类似QQ一个用java开发出来的聊天工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                case 5 : //up clicked
                    if (min + canShow <= 0)
                        add = canShow;
                    e = friend.keys();
                    for (; e.hasMoreElements();)
                    {
                        icqNo = (String) e.nextElement();
                        icqid = (IcqID) friend.get(icqNo);
                        icqid.index += add;
                        friend.put(icqNo, icqid);
                    }
                    if (add != 0)
                        repaint();
                    break;
                case 6 : //down clicked
                    if (max - canShow >= 0)
                        add = -canShow;
                    e = friend.keys();
                    for (; e.hasMoreElements();)
                    {
                        icqNo = (String) e.nextElement();
                        icqid = (IcqID) friend.get(icqNo);
                        icqid.index += add;
                        friend.put(icqNo, icqid);
                    }
                    if (add != 0)
                        repaint();
                    break;
                case 7 :
                    //if(seek==null)seek=new Seek(myIcqID);
                    if (!seek.isShowing())
                        seek.setVisible(true);
                    else
                        seek.setVisible(false);
                    break;
                case 8 :
                    sysmsg();
                    break;
                case 9 :
                    modifyPM.show(this, area[9][2], area[9][1]);
                    break;
                case 10 :
                    SysInfo.bigIcon = !SysInfo.bigIcon;
                    repaintEvt = true;
                    if (mydialog == null)
                        mydialog =
                            new MyDialog(
                                "\n jICQ "
                                    + jICQ.ver
                                    + "\n\n   浙江温州虹桥计算机有限公司 张鹏\n   +86-577-62323761 62322773 62355632\n   http://www.ebsee.com\n   support@ebsee.com");
                    if (mydialog.isShowing())
                        mydialog.setVisible(false);
                    else
                        mydialog.setVisible(true);
                    break;
            }
        }
    }

    int getArea(int x, int y)
    {
        for (int i = 0; i < area.length; i++)
            if (y > area[i][1]
                && y < area[i][3]
                && x > area[i][0]
                && x < area[i][2])
                return i;
        return -1;
    }
    void help()//帮助信息方法
    {
        String helpMsg = "         欢迎使用jICQ帮助\n";
        helpMsg
            += "    一.简单易用是jICQ的最大特色,如果你能掌握一些技巧,那更能运用自如,由于本系统使用SUN公司的跨平台开发软件java编成,所以,不能使用一些Windows或UNIX的一些特性,比如系统热键,可能会对你的使用带来不便。当然,我们也模仿了热键功能:\n";
        helpMsg += "接收信息可按F4,但是你必须确定jICQ窗口是活动窗口。\n";
        helpMsg += "    二.其它的一切你都可用鼠标完成。";
        MyDialog dia = new MyDialog(helpMsg);
        dia.setVisible(true);
    }
    void sysmsg()
    {
        if (message.size() == 0)
            return;
        try
        {
            String msg = (String) message.elementAt(0);
            message.removeElementAt(0);
            repaint();
            if (msg.indexOf(' ') == -1)
                msg += " ";
            String cmd = msg.substring(0, msg.indexOf(' '));
            msg = msg.substring(msg.indexOf(' ') + 1);
            if (cmd.equalsIgnoreCase("JOIN"))
            {
                joinedFrame(msg);
            }
            else if (cmd.equalsIgnoreCase("JOINED"))
            {
                String icqNo = msg.substring(msg.indexOf("icqNo:") + 6);
                icqNo = icqNo.substring(0, icqNo.indexOf(' '));
                if (friend.get(icqNo) == null)
                {
                    IcqID icqid = new IcqID();
                    icqid.icqNo = icqNo;
                    setFriend(icqNo, icqid);
                    repaintEvt = true;
                }
                noteMsg(msg);
            }
            else if (cmd.equalsIgnoreCase("DUPLOGON"))
            {
                exitMsg(msg);
            }
            else
                noteMsg(msg);
        }
        catch (Exception e)
        {
            System.out.println("  MainFrame sysmsg() error:" + e);
        }
    }
}

class RMsg extends Thread
{
    IcqID myIcqID = null;
    DatagramSocket udpRSocket = null;
    int CONTMAX = 300;
    //int backport=0;
    //boolean udpback=false;

    RMsg(DatagramSocket udps, IcqID myicqid)
    {
        udpRSocket = udps;
        CONTMAX = jICQ.CONTMAX;
        myIcqID = myicqid;
        //backport=udpRSocket.getLocalPort();
    }

    public void run()
    {
        boolean exitwhile = false;
        byte[] rMsg = new byte[CONTMAX * 2];
        DatagramPacket dp = null;
        String rMsgs = null;
        System.out.println("  start listen UDP...");

        //udpSend("GETMYPORT icqNo:"+myIcqID.icqNo);

        dp = new DatagramPacket(rMsg, rMsg.length);
        while (jICQ.exitSystem == false && exitwhile == false)
        {
            try
            {
                udpRSocket.receive(dp);
            }
            catch (IOException e)
            {
                System.out.println("  RMsg.run() receive error:" + e);
                exitwhile = true;
            }
            rMsg = dp.getData();
            char c[] = new char[dp.getLength() / 2];
            for (int i = 0; i < dp.getLength() / 2; i++)
            {
                c[i] = (char) (rMsg[i * 2] << 8);
                c[i] = (char) ((c[i] & 0xff00) | (0x00ff & rMsg[i * 2 + 1]));
            }
            rMsgs = new String(c).trim();
            System.out.println("   UDP received:" + rMsgs);
            String cmd = "";
            if (rMsgs.indexOf(' ') != -1)
                cmd = rMsgs.substring(0, rMsgs.indexOf(' '));
            if (cmd.equalsIgnoreCase("MSG"))
                msg(rMsgs);
            if (cmd.equalsIgnoreCase("UDPOK"))
                udpok(rMsgs);
            //if(cmd.equalsIgnoreCase("UDPPORT"))udpport(rMsgs);
            //udpback=true;
        } //end while
        System.out.println("   RMsg.run() end.");
    }
    public void udpSend(String sMsgs)//UDP包发送
    {
        DatagramPacket dp = null;
        byte[] sMsg = new byte[CONTMAX * 2];
        try
        {
            for (int i = 0; i < sMsgs.length(); i++)
            {
                sMsg[i * 2] = (byte) (sMsgs.charAt(i) >> 8);
                sMsg[i * 2 + 1] = (byte) sMsgs.charAt(i);
            }
            //convert the String to byte and the 8bit
            dp =
                new DatagramPacket(
                    sMsg,
                    sMsg.length,
                    InetAddress.getByName(jICQ.URLstring),
                    7803);
            udpRSocket.send(dp);
        }
        catch (Exception e)
        {
            System.out.println("  UDP udpSend() error:" + e);
        }
        System.out.println(
            "   UDP send to " + jICQ.URLstring + ":7803 " + sMsgs);
    }
    /*	void udpport(String rMsgs)
    	{
    		String tmp=rMsgs.substring(rMsgs.indexOf("port:")+5).trim();
    		System.out.println(">"+tmp+"<");
    		int port=Integer.parseInt(tmp);
    		backport=port;
    		System.out.println("   RMsg.udpport() the port:"+port);
    	}*/
    void msg(String rMsgs)
    {
        String from = null;
        //System.out.println("   Rmsg.msg rMsgs:"+rMsgs);
        try
        {
            from = rMsgs.substring(rMsgs.indexOf("from:") + 5);
            from = from.substring(0, from.indexOf(' '));
            if (from.equals(myIcqID.icqNo))
                return;
            IcqID icqid = (IcqID) MainFrame.friend.get(from);
            if (icqid == null)
            {
                icqid = new IcqID();
                icqid.icqNo = from;
                icqid.isStranger = true;
                MainFrame.setFriend(from, icqid);
            }

            icqid.addInMsg(rMsgs);
        }
        catch (Exception e)
        {
            System.out.println("  RMsg.msg() error:" + e);
        }
    }
    void udpok(String rMsgs)
    {
        String from = null;
        try
        {
            from = rMsgs.substring(rMsgs.indexOf("from:") + 5);
            from = from.substring(0, from.indexOf(' '));
            if (from.equals(myIcqID.icqNo))
                return;
            //System.out.println("  Rmsg.udpok() from:"+from);
            IcqID icqid = (IcqID) MainFrame.friend.get(from);
            if (icqid != null)
                icqid.backId(rMsgs);
        }
        catch (Exception e)
        {
            System.out.println("  RMsg.udpok() error:" + e);
        }
    }
}

class SMsg extends Frame
{
    TextArea chatta, logta;
    String b1s = "聊天记录", b2s = "取消(ESC)", b3s = "发送(Ctrl+Enter)";
    boolean LOG = true;
    IcqID icqid;
    int CONTMAX = 300;
    IcqID myIcqID = null;
    int bwidth = 350, bheight = 320, swidth = 350, sheight = 210;

    private class ImagePanel extends Panel
    {
        SubmitID submitid = null;
        int l, t, w, h;
        String http = null;
        Image thisImg = null;

        ImagePanel()
        {
            setLayout(new FlowLayout(FlowLayout.LEFT));
            Button b1 = new Button("用户资料");
            add(b1);
            b1.addActionListener(new java.awt.event.ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    b1Clicked();
                }
            });
            addMouseMotionListener(new MouseMotionAdapter()
            {
                public void mouseMoved(MouseEvent e)
                {
                    mMoved(e);
                }
            });
            addMouseListener(new MouseAdapter()
            {
                public void mouseClicked(MouseEvent e)
                {
                    mClicked(e);
                }
            });
        }
        public void paint(Graphics g)
        {
            try
            {
                Dimension dm = getSize();
                thisImg = MainFrame.httpimage.getImage();
                http = MainFrame.httpimage.getHttp();

                l = 75;
                t = 3;
                w = dm.width - 80;
                h = dm.height - 6;
                g.drawRect(l - 1, t - 1, w + 2, h + 2);
                g.drawImage(thisImg, l, t, w, h, this);
            }
            catch (Exception e)
            {
            }
            //System.out.println(http);
        }

        void b1Clicked()
        {
            if (submitid == null)
                submitid = new SubmitID(icqid, icqid.getNick(), false, false);
            else
                submitid.setVisible(true);
        }
        protected void mClicked(MouseEvent e)
        {
            if (e.getX() > l
                && e.getX() < l + w
                && e.getY() > t
                && e.getY() < t + h)
            {
                Runtime r = Runtime.getRuntime();
                try
                {
                    r.exec("explorer " + http);
                }
                catch (Exception exp)
                {
                }
            }
        }
        protected void mMoved(MouseEvent e)
        {
            if (e.getX() > l
                && e.getX() < l + w
                && e.getY() > t
                && e.getY() < t + h)
            {
                setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
            else
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            //System.out.println("   mouse entered...");
        }
    }

    SMsg(IcqID toIcqid, IcqID my)
    {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);

        icqid = toIcqid;
        CONTMAX = jICQ.CONTMAX;
        myIcqID = my;

        setTitle(icqid.getNick() + "(" + toIcqid.icqNo + ")");
        Dimension dm = getToolkit().getScreenSize();
        setBounds(
            dm.width / 2 - bwidth / 2,
            dm.height / 2 - bheight / 2,
            bwidth,
            bheight);
        setResizable(false);
        setBackground(new Color(13947080));
        setIconImage(icqid.getImg(getToolkit()));
        chatta = new TextArea("", 9, 46, TextArea.SCROLLBARS_VERTICAL_ONLY);
        chatta.addTextListener(new java.awt.event.TextListener()
        {
            public void textValueChanged(TextEvent e)
            {
                chatta_te

⌨️ 快捷键说明

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