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

📄 jicq.java

📁 用java做的icq,不错的啊!大家看看啊!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	{
		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_textValueChanged();}});
		chatta.addKeyListener(new java.awt.event.KeyAdapter() {public void keyPressed(KeyEvent e) {ta_keyPressed(e);}});
		logta=new TextArea("",8,46,TextArea.SCROLLBARS_VERTICAL_ONLY);
		logta.addKeyListener(new java.awt.event.KeyAdapter() {public void keyPressed(KeyEvent e) {ta_keyPressed(e);}});
		logta.setEditable(false);
		logta.append(icqid.chatrec);
		Button b1=new Button(b1s);
		Button b2=new Button(b2s);
		Button b3=new Button(b3s);
		b1.addActionListener(new java.awt.event.ActionListener(){public void actionPerformed(ActionEvent e) {b1Clicked();}});
		b2.addActionListener(new java.awt.event.ActionListener(){public void actionPerformed(ActionEvent e) {b2Clicked();}});
		b3.addActionListener(new java.awt.event.ActionListener(){public void actionPerformed(ActionEvent e) {b3Clicked();}});

		GridBagLayout  gridbag  =  new  GridBagLayout();
		GridBagConstraints  c  =  new  GridBagConstraints();
		c.insets=new Insets(0,1,0,1);
		c.fill  =  GridBagConstraints.HORIZONTAL;
		c.anchor=GridBagConstraints.NORTH;
		setLayout(gridbag);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		add(chatta,c);
		c.weightx=1.0;
		c.gridwidth=1;
		gridbag.setConstraints(b1,c);
		add(b1);
		gridbag.setConstraints(b2,c);
		add(b2);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		gridbag.setConstraints(b3,c);
		add(b3);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		ImagePanel imgp=new ImagePanel();
		add(imgp,c);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		gridbag.setConstraints(logta,c);
		add(logta);
		pack();
		setVisible(true);
	}
	public void paint(Graphics g)
	{
		//Dimension dm=getSize();
		//Image img=getToolkit().getImage("image/adv.jpg");
		//g.drawImage(img,10,dm.height-63,dm.width-20,55,this);//img.width=330;img.height=55
	}
	protected void processWindowEvent(WindowEvent e) {
		super.processWindowEvent(e);
		if (e.getID() == WindowEvent.WINDOW_CLOSING) {
			dispose();
			return;
		}
	}
	void b1Clicked()
	{
		if(!logta.isVisible())logta.setVisible(true);
		else logta.setVisible(false);
		pack();
	}
	void b2Clicked(){dispose();}
	
	void b3Clicked()
	{
		if(0!=chatta.getText().length()){
			icqid.sendOut(chatta.getText());
			dispose();
		}
	}

	protected void chatta_textValueChanged(){
		int sl=chatta.getText().length();
		if(sl>CONTMAX)chatta.replaceRange("",CONTMAX,sl);
	}

	protected void ta_keyPressed(KeyEvent evt)
	{
		if(evt.getKeyCode()==KeyEvent.VK_ENTER&&evt.isControlDown()){
			if(1<chatta.getText().length()){
				String s=chatta.getText();
				icqid.sendOut(s);
				dispose();
			}
		}
		if(evt.getKeyCode()==27)dispose();

	}
	public void refrush(){logta.setText(icqid.chatrec);}
}

class LogonFrame extends Frame
{
	Button b_logon,b_registy;
	TextField tf_icqNo,tf_password,tf_msg,tf_proxyIp,tf_proxyPort;
	String b_logons="登录",b_registys="注册";
	boolean exitfor=false;
	Result result=null;
	SubmitID submitid=null;
	Checkbox ch_proxy;
	Label l1,l2,l3;

	LogonFrame()
	{
		enableEvents(AWTEvent.WINDOW_EVENT_MASK);
		enableEvents(AWTEvent.KEY_EVENT_MASK);
		result=new Result();
		tf_icqNo=new TextField(10);	
		tf_icqNo.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(KeyEvent e) {tf_icqNo_keyPressed(e); }});
		tf_password=new TextField(10);
		tf_password.setEchoChar('*');
		tf_password.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(KeyEvent e) {tf_password_keyPressed(e); }});

		b_logon=new Button(b_logons);
		b_logon.addActionListener(new java.awt.event.ActionListener(){public void actionPerformed(ActionEvent e) {b_logonClicked();}});
		b_registy=new Button(b_registys);
		b_registy.addActionListener(new java.awt.event.ActionListener(){public void actionPerformed(ActionEvent e) {b_registyClicked();}});
		tf_msg=new TextField(30);
		tf_proxyIp=new TextField(10);tf_proxyIp.setEditable(false);
		tf_proxyPort=new TextField(2);tf_proxyPort.setEditable(false);
		tf_msg.setText("jicq.vicp.net 张鹏设计");tf_msg.setEditable(false);
		ch_proxy=new Checkbox("代理服务器",false);
		ch_proxy.addItemListener(new java.awt.event.ItemListener() {public void itemStateChanged(ItemEvent e) {enableProxy();}});

		l1=new Label("jICQ登录    "+jICQ.getver(),Label.CENTER);
		l2=new Label("用户号码:",Label.RIGHT);
		l3=new Label("用户密码:",Label.RIGHT);
		setTitle("jICQ 登录");
		Dimension dm=getToolkit().getScreenSize();
		setBounds(dm.width/2-130,dm.height/2-100,260,200);
		setResizable(false);
		setIconImage(jICQ.icqImage);
		GridBagLayout  gridbag  =  new  GridBagLayout();
		GridBagConstraints  c  =  new  GridBagConstraints();
		//c.fill  =  GridBagConstraints.BOTH;
		c.insets=new Insets(1,1,1,1);
		setBackground(new Color(13947080)) ;
		setLayout(gridbag);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		add(l1,c);
		c.gridwidth  =  1;
		add(l2,c);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		add(tf_icqNo,c);
		c.gridwidth  =1;
		add(l3,c);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		add(tf_password,c);
		c.weightx=.5;
		c.gridwidth  = 1;
		add(b_logon,c);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		add(b_registy,c);
		c.fill  =  GridBagConstraints.BOTH;
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		add(tf_msg,c);
		c.gridwidth  = 1;
		add(ch_proxy,c);
		c.gridwidth  = 1;
		add(tf_proxyIp,c);
		c.gridwidth  =  GridBagConstraints.REMAINDER;
		add(tf_proxyPort,c);
		pack();
		setVisible(true);
	}
	protected void tf_password_keyPressed(KeyEvent evt){if(evt.getKeyCode()==KeyEvent.VK_ENTER){b_logonClicked();}}
	protected void tf_icqNo_keyPressed(KeyEvent evt){if(evt.getKeyCode()==KeyEvent.VK_ENTER){tf_icqNo.transferFocus();}}
	protected void processWindowEvent(WindowEvent e) {
		super.processWindowEvent(e);
		if (e.getID() == WindowEvent.WINDOW_CLOSING) {
			dispose();System.exit(0);
			return;
		}
	}
	void setProxy()
	{
		if(jICQ.isApplet)return;
		if(ch_proxy.getState()){
			Properties sys = System.getProperties();
			sys.put("socksProxySet","true");
			sys.put("socksProxyHost",tf_proxyIp.getText());
			sys.put("socksProxyPort",tf_proxyPort.getText());
			System.setProperties(sys);
			System.out.println("   Use proxy:"+tf_proxyIp.getText()+":"+tf_proxyPort.getText());
		}else{
			Properties sys = System.getProperties();
			//sys.put("socksProxySet","false");
			//sys.put("socksProxyHost","");
			//sys.put("socksProxyPort","");
			
			//if use up 3 sentens,can't logon when no proxy,but fllow Ok.
			sys.remove("socksProxySet");
			sys.remove("socksProxyHost");
			sys.remove("socksProxyPort");
			System.setProperties(sys);
		}
			Properties sys = System.getProperties();
			System.out.println("   sys.socksProxySet:"+sys.get("socksProxySet"));
			System.out.println("   sys.socksProxyHost:"+sys.get("socksProxyHost"));
			System.out.println("   sys.socksProxyPort:"+sys.get("socksProxyPort"));
	}
	void b_logonClicked()
	{
		setProxy();
		login();
	}
	void b_registyClicked()
	{
		setProxy();
		if(submitid==null)submitid=new SubmitID(new IcqID(),"注册jICQ",true,false);
		else if(submitid.isValid())submitid.toFront();
		else submitid=new SubmitID(new IcqID(),"注册jICQ",true,false);
		//System.out.println("   end reg.");
	}

	void enableProxy()
	{
		if(ch_proxy.getState()){tf_proxyIp.setEditable(true);tf_proxyPort.setEditable(true);}
		else {tf_proxyIp.setEditable(false);tf_proxyPort.setEditable(false);}
	}
	void login()
	{
		try{	//System.out.println("  begin to logon..."+s1+s2);
			String s1=tf_icqNo.getText().trim();
			String s2=tf_password.getText();
			if(s1.equals("")||s2.equals("")){tf_msg.setText("icq 号码或密码没有输入.");return;}

			tf_msg.setText("正在连接...");
			//Thread.sleep(100);
			Sender sender=new Sender("LOGON icqNo:"+s1+" password:"+s2);
			sender.start();
			result=sender.getReturn();
			if(result.getCode()==200){jICQ.setID(s1);dispose();}
			else{tf_msg.setText(result.getMsg());}
		}catch(Exception e){System.out.println("   LogonFrame.login() error:"+e);}
	}
}

class Result
{
	int resultCode=-1;
	String resultMsg="";
	Result(){}
	int getCode(){return resultCode;}
	String getMsg(){return resultMsg;}
	void setResult(int code,String msg){resultCode=code;resultMsg=msg;}
}
class IcqID extends Thread
{
	boolean isOnline=false;
	String icqNo="";
	String nick="";
	String sex="男";
	String check="否";
	String picNo="0";
	String info="想了解我吗?自已来问我";
	String tel="";
	String addr="";
	String http="";
	String mobile="";
	String email="";
	String pass="";
	String age="20";
	String rport=null;
	String ip=null;
	String integral="0";

	int left=10,top=100,right=150,bottom=135;
	int canShow=0;
	int index;
	boolean mouseEntered=false;
	boolean newMsg=false;
	boolean checked=false;
	String chatrec="";
	boolean isStranger=false,updated=false;
	SMsg smsg=null;
	Image headImg=null,newHeadImg=null;
	String rMsgID="";
	Vector outMsg=null,inMsg=null;
	int udpTimeout=10*1000;
	int CONTMAX=300;
	Frame mainFrame=null;
	boolean isShowing=true,stopRun=false;
	
	IcqID()
	{
		outMsg=new Vector();
		inMsg=new Vector();
		CONTMAX=jICQ.CONTMAX;
	}

	public void run()
	{
		long outTime=0;
		String s=null;
		while(!stopRun)
			try{
				long thisTime=new Date().getTime();
				for(int i=0;i<outMsg.size();i++){
					s=(String)outMsg.elementAt(i);
					outTime=getMsgTime(s);
					//System.out.println("   outTime="+outTime);
					String from=s.substring(s.indexOf("from:")+5);
					from=from.substring(0,from.indexOf(' '));
					if(thisTime>outTime+udpTimeout){      //if timeout then forward
						Sender sender=new Sender("FORWARD from:"+from+" to:"+icqNo+" "+s);
						sender.start();
						Result r=sender.getReturn();
						if (r.getCode()!=200){System.out.println("  通过服务器转发未成功。");}
						else outMsg.removeElementAt(i);
					}
				}
				if(newMsg&&index>=0&&index<canShow){
					Graphics g=mainFrame.getGraphics();
					int imgh=0,imgw=0;
					imgw=imgh=bottom-top-4;
					if(isShowing){
						Color c=g.getColor();
						g.setColor(mainFrame.getBackground());
						g.drawImage(newHeadImg,left+5,top+2,imgw,imgh,mainFrame);
						//g.fillRect(left+5,top+2,imgw,imgh);
						g.setColor(c);
						isShowing=false;
					}
					else {g.drawImage(headImg,left+5,top+2,imgw,imgh,mainFrame);isShowing=true;}
				}
				sleep(400);
				//System.out.println("   IcqID run() running...");
			}catch(Exception e){}
	}

	long getMsgTime(String s)
	{
		try{
			s=s.substring(s.lastIndexOf("id:")+3);
			return new Long(s).longValue();
		}
		catch(Exception e){return 0;}
	}
	void backId(String s)
	{
		if (s.indexOf("id:")!=-1)
		try{
			
			String id=s.substring(s.indexOf("id:")).trim();
			for(int i=0;i<outMsg.size();i++){
				String tmps=(String)outMsg.elementAt(i);
				//System.out.println("  temps:"+tmps);
				//System.out.println("  ins:"+id);
				if(tmps.indexOf(id)!=-1)outMsg.removeElementAt(i);
			}
		}
		catch(Exception e){System.out.println("  IcqID.backId() error:"+e);}
	}

	void draw(Frame f)
	{
		try{
			mainFrame=f;
			if (top==bottom)return;

⌨️ 快捷键说明

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