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

📄 jicq.java

📁 用java做的icq,不错的啊!大家看看啊!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		}
	}
	protected void processWindowEvent(WindowEvent e) {
		super.processWindowEvent(e);
		if (e.getID() == WindowEvent.WINDOW_CLOSING) {
			close();
			return;
		}
	}
	protected void processKeyEvent(KeyEvent evt)
	{
		super.processKeyEvent(evt);
		if(evt.getKeyCode()==KeyEvent.VK_F4){
			Enumeration e=friend.keys();
			currenticqid=null;
			IcqID icqid=null;
			while(e.hasMoreElements()){
				icqid=(IcqID)friend.get((String)e.nextElement());
				if(icqid!=null)if(icqid.newMsg){currenticqid=icqid;}
			}
			sendTo();
		}
	}
	protected void processMouseMotionEvent(MouseEvent e)
	{
		super.processMouseMotionEvent(e);
		if(!LOGED)return ;
		if(e.getID()==MouseEvent.MOUSE_MOVED)mouseMoved(e.getX(),e.getY());
	}
	public void mouseMoved(int x,int y)
	{
		try{
			currentarea=getArea(x,y);
			Graphics g=getGraphics();
			int zoom=0;

			if(currentarea==4){
				Enumeration e=friend.keys();
				IcqID icqid=null;
				while(e.hasMoreElements()){
					icqid=(IcqID)friend.get((String)e.nextElement());
					if(icqid.index>=0&&icqid.index<icqid.canShow)
						if(icqid.top<y&&icqid.bottom>y)icqid.mouseEnter(this);
						else icqid.mouseExit(this);
				}
			}
			if (pastarea==currentarea||currentarea==-1)return ;
			g.setColor(getBackground());
			if(pastarea<=area.length)
				for(int i=0;i<area.length;i++)if(i!=4)g.drawRect(area[i][0],area[i][1]+zoom,area[i][2]-area[i][0]-1,area[i][3]-area[i][1]-zoom);
			g.setColor(new Color(sysinfo.textcolor));
			pastarea=currentarea;
			if(currentarea==4)return;
			g.drawRect(area[currentarea][0],area[currentarea][1]+zoom,area[currentarea][2]-area[currentarea][0]-1,area[currentarea][3]-area[currentarea][1]-zoom);
		}catch(Exception e){}
	}

	protected void processMouseEvent(MouseEvent e)
	{
		super.processMouseEvent(e);
		if(!LOGED)return ;
		if(e.getID()==MouseEvent.MOUSE_PRESSED )mousePressed(e,e.getX(),e.getY());
		if(e.getID()==MouseEvent.MOUSE_CLICKED )mouseClicked(e,e.getX(),e.getY());
		if(e.isPopupTrigger())popupMenu(e,e.getX(),e.getY());	//right button
	}
	void popupMenu(MouseEvent evt,int x,int y)
	{
		int ca=getArea(x,y);
		IcqID icqid=null;
		switch(ca){
		case 4:
			pm.show(this,x,y);
			Enumeration e=friend.keys();
			//System.out.println("  more="+e.hasMoreElements());
			while(e.hasMoreElements()){
				icqid=(IcqID)friend.get((String)e.nextElement());
				if(icqid.index>=0&&icqid.index<icqid.canShow)
					if(icqid.top<y&&icqid.bottom>y)
					{currenticqid=icqid;}
			}
			//System.out.println("  currenticqid.icqNo="+currenticqid.icqNo);
			break;
		case 9:
			modifyPM.show(this,area[9][2],area[9][1]);
			break;
		default:
		}
	}
	public void mouseClicked(MouseEvent evt,int x,int y)
	{
		//System.out.println("   MouseClicked..."+evt.getClickCount());
		if(evt.getClickCount()==2){
			Enumeration e=friend.keys();
			currenticqid=null;
			IcqID icqid=null;
			while(e.hasMoreElements()){
				icqid=(IcqID)friend.get((String)e.nextElement());
				if(icqid.index>=0&&icqid.index<icqid.canShow)
					if(icqid.top<y&&icqid.bottom>y)
					{currenticqid=icqid;}
			}
			//System.out.println("  currenticqid.icqNo="+currenticqid.icqNo);
			if(currenticqid!=null)sendTo();
		}

		return ;
	}
	public void mousePressed(MouseEvent evt,int x,int y)
	{
		//System.out.println(" the l,m,r="+evt.modifiers);
		if(!LOGED)return ;
		mouseMoved(x,y);
		int ca=getArea(x,y);
		if (ca==-1)return ;
		int min=0,max=0;
		Enumeration e=friend.keys();
		IcqID icqid=null;
		for(;e.hasMoreElements();){
			icqid=(IcqID)friend.get((String)e.nextElement());
			if(icqid.index<min){min=icqid.index;}
			if(icqid.index>max){max=icqid.index;}
		}
		int canShow=0;
		if(icqid!=null)canShow=icqid.canShow;
		String icqNo=null;
		currenticqid=null;

		if(!evt.isPopupTrigger())	//left button
		{
			int add=0;
			switch(ca){
			case 0:Runtime r0=Runtime.getRuntime();try{r0.exec("explorer http://jicq.vicp.net/bbs ");}catch(Exception exp){}break;
			case 1:Runtime r1=Runtime.getRuntime();try{r1.exec("explorer http://jicq.vicp.net/reg/reg.htm ");}catch(Exception exp){}break;
			case 2:Runtime r2=Runtime.getRuntime();try{r2.exec("explorer http://jicq.vicp.net ");}catch(Exception exp){}break;
			case 3:help();break;
			case 4:break;
			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)
	{
		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)

⌨️ 快捷键说明

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