`

基于JavaEye-API实现的Gerry-聊天QQ版v1.0 (全)

阅读更多

目录结构如下:

--bean
----------MessageBean.java
----------ReceiveBean.java
----------SenderBean.java

---gerry
----------ClientViewMain.java
----------IconThread.java

----------ShowThread.java

---images

----------pmt.gif

----------pmtwhite.gif

---lib
----------commons-beanutils-1.8.0.jar
----------commons-codec-1.3.jar
----------commons-collections-3.2.1.jar
----------commons-lang-2.4.jar
----------commons-logging-1.1.1.jar
----------ezmorph-1.0.6.jar

----------httpclient-4.0-beta2.jar

----------httpcore-4.0-beta3.jar
----------json-lib-2.3-jdk15.jar

---tools
----------ClientUtils.java
----------Native2AsciiUtils.java
----------TimeUtil.java

 

1.
json-lib-2.3-jdk15.jar
http://sourceforge.net/projects/json-lib/files

2.
http-client , http-core
http://hc.apache.org/

3.ezmorph-1.0.3.jar,commons-lang.jar,commons-logging.jar,commons-beanutils.jar,commons-collections-3.2.jar
可以下载jar包的网站http://www.docjar.com/

 

 

 

 

MessageBean.java


package bean;   
  
public class MessageBean {   
  
        private String system_notice ;   
        private String created_at ;   
        private String plain_body ;   
        private String title ;   
        private String id ;   
        private String has_read ;   
        private String attach ;   
        private SenderBean sender ;   
        private ReceiveBean receiver ;   
           
           
        public String getAttach() {   
            return attach;   
        }   
        public void setAttach(String attach) {   
            this.attach = attach;   
        }   
        public String getCreated_at() {   
            return created_at;   
        }   
        public void setCreated_at(String created_at) {   
            this.created_at = created_at;   
        }   
        public String getHas_read() {   
            return has_read;   
        }   
        public void setHas_read(String has_read) {   
            this.has_read = has_read;   
        }   
        public String getId() {   
            return id;   
        }   
        public void setId(String id) {   
            this.id = id;   
        }   
        public String getPlain_body() {   
            return plain_body;   
        }   
        public void setPlain_body(String plain_body) {   
            this.plain_body = plain_body;   
        }   
        public ReceiveBean getReceiver() {   
            return receiver;   
        }   
        public void setReceiver(ReceiveBean receiver) {   
            this.receiver = receiver;   
        }   
        public SenderBean getSender() {   
            return sender;   
        }   
        public void setSender(SenderBean sender) {   
            this.sender = sender;   
        }   
        public String getSystem_notice() {   
            return system_notice;   
        }   
        public void setSystem_notice(String system_notice) {   
            this.system_notice = system_notice;   
        }   
        public String getTitle() {   
            return title;   
        }   
        public void setTitle(String title) {   
            this.title = title;   
        }   
           
     
}  

 

   

ReceiveBean.java


package bean;   
  
public class ReceiveBean {   
  
        private String name ;   
        private String logo ;   
        private String domain ;   
         
         
        public String getDomain() {   
            return domain;   
        }   
        public void setDomain(String domain) {   
            this.domain = domain;   
        }   
        public String getLogo() {   
            return logo;   
        }   
        public void setLogo(String logo) {   
            this.logo = logo;   
        }   
        public String getName() {   
            return name;   
        }   
        public void setName(String name) {   
            this.name = name;   
        }   
         
         
         
}   

 

SenderBean.java

package bean;   
  
public class SenderBean {   
  
        private String name ;   
        private String logo ;   
        private String domain ;   
         
         
        public String getDomain() {   
            return domain;   
        }   
        public void setDomain(String domain) {   
            this.domain = domain;   
        }   
        public String getLogo() {   
            return logo;   
        }   
        public void setLogo(String logo) {   
            this.logo = logo;   
        }   
        public String getName() {   
            return name;   
        }   
        public void setName(String name) {   
            this.name = name;   
        }   
         
         
         
}   

 

ClientViewMain.java

package gerry;   
  
import java.awt.Container;   
import java.awt.GridLayout;   
import java.awt.Image;     
import java.awt.Label;   
import java.awt.MenuItem;   
import java.awt.PopupMenu;   
import java.awt.SystemTray;   
import java.awt.TextArea;
import java.awt.TextField;   
import java.awt.Toolkit;     
import java.awt.event.ActionEvent;   
import java.awt.event.ActionListener;   
import java.io.IOException;   
import java.net.URL;
import java.sql.Timestamp;   
import java.util.ArrayList;   
import java.util.List;   
import javax.swing.BoxLayout;   
import javax.swing.JButton;   
import javax.swing.JFrame;   
import javax.swing.JOptionPane;
import net.sf.json.JSONArray;   
import org.apache.http.client.ClientProtocolException;   
import tools.ClientUtils;   
import tools.Native2AsciiUtils;   
import tools.TimeUtil;   
import bean.MessageBean;   
    
  
/**  
 * @author   Gerry Cheung(V1.0)  
 * @version  2010-09-03  (恋爱三个月纪念版) 
 */   
 public class ClientViewMain {     
        
     /*User param setting*/        
     private static String  user_name = "111" ;        
     private static String  user_pass = "111" ;        
     private static String  receive_name = "111" ;        
     private static boolean isproxy = false ;        
        
     /*System param*/        
     //The JE only can show fifteen rows by api         
     public  static List<MessageBean> listBean = new ArrayList<MessageBean>();        
     public  static String last_update_time = "2000/01/01 00:00:00.00" ;        
     private static URL pmt_url = ClientViewMain.class.getClass().getResource("/images/pmt.gif"); 
     private static URL pmt_urlwhite = ClientViewMain.class.getClass().getResource("/images/pmtwhite.gif");
     private static Image image = Toolkit.getDefaultToolkit().getImage(pmt_url);    
     private static java.awt.TrayIcon ti = new java.awt.TrayIcon(image);     
     private static int count  = 0 ;   
     private static ShowThread showThread = new ShowThread();   
     private static IconThread iconThread = new IconThread();   
     private static int screenWidth =Toolkit.getDefaultToolkit().getScreenSize().width;
     private static int screenHeight=Toolkit.getDefaultToolkit().getScreenSize().height;
     
     //Login Frame   
     private static JFrame f1 = new JFrame("Login");   
     private static TextField  tName = new TextField();   
     private static TextField  tPass = new TextField();   
     private static TextField  tReceive = new TextField(); 
     private static JButton b_login = new JButton("Login");  
     //Send Frame
     private static JFrame f2 = new JFrame("Send");
     private static TextArea sContent = new TextArea("",10,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
     private static JButton s_send = new JButton("Send"); 
     
     //Show Last Message
     private static JFrame f3 = new JFrame("Show");
     private static TextArea textareashow = new TextArea("",10,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
     
     //Show History 
     private static JFrame f4 = new JFrame("History");
     private static TextArea textareahistory = new TextArea("",10,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
     
     
     public static void systemTray(){     
    	 
         try{     
             if (SystemTray.isSupported()){    
                    SystemTray  st = SystemTray.getSystemTray();     
                    PopupMenu menu = new PopupMenu();   
                       
                    menu.add("O(∩_∩)O From:2010-06-03 To forever...  O(∩_∩)O");   
                    menu.add("O(∩_∩)O Ling:Gerry in your heart !            O(∩_∩)O");   
                    menu.add("O(∩_∩)O GerryLing  [恋爱三个月纪念版]  O(∩_∩)O");
                    
                    MenuItem item0 = new MenuItem();   
                    item0.setLabel("Send");   
                    item0.addActionListener( new ActionListener(){   
                        public void actionPerformed( ActionEvent ae ){   
                        	  sendMessage();
                        }   
                    });   
                    menu.add(item0);   
                       
                    MenuItem item1 = new MenuItem();   
                    item1.setLabel("Refresh");   
                    item1.addActionListener( new ActionListener(){   
                        public void actionPerformed( ActionEvent ae ){   
                              receiveNewMessage();   
                        }   
                    });   
                    menu.add(item1);   
                       
                    MenuItem item3 = new MenuItem();   
                    item3.setLabel("History");   
                    item3.addActionListener( new ActionListener(){   
                        public void actionPerformed( ActionEvent ae ){   
                        	receiveMessage();
                        }   
                    });   
                    menu.add(item3);   
                       
                    menu.add("About   Version1.0  2010-09-03");   
                       
                    MenuItem item2 = new MenuItem();   
                    item2.setLabel("Quit");   
                    item2.addActionListener( new ActionListener(){   
                        public void actionPerformed(ActionEvent ae){   
                              showThread.stop();   
                              iconThread.stop();   
                              System.exit(0);   
                        }   
                    });   
                    menu.add(item2);   
                    //show last message   
                    ti.addActionListener( new ActionListener(){   
                        public void actionPerformed(ActionEvent ae){   
                               showLastListMsg();   
                        }   
                    });   
                    ti.setToolTip ("["+user_name+"]"+"You have 0 message to Read !");     
                    ti.setPopupMenu (menu);       
                    st.add(ti);        
                }     
          }catch (Exception e){   
                   System.exit(0);   
          }            
                 
  }     
     
     
  public static String receiveMessage(){        
         
      String strResult = null;        
      try {        
          strResult = ClientUtils.getJsonContent("api.iteye.com","api/messages/inbox", user_name,user_pass,isproxy);        
      } catch (ClientProtocolException e) {        
          e.printStackTrace();        
      } catch (IOException e) {        
          e.printStackTrace();        
      }        
      //Use JSON-LIB parse data         
      JSONArray jsonArray = JSONArray.fromObject(Native2AsciiUtils.ascii2Native(strResult));        
      MessageBean[] beans = (MessageBean[])JSONArray.toArray(jsonArray, MessageBean.class); 
      String strMsg = "" ;
      for(int i=0;i<beans.length;i++){        
    	  strMsg = strMsg + "No."+(i+1)+": ["+beans[i].getCreated_at()+"] "+beans[i].getSender().getName()+" :"+beans[i].getPlain_body()+"\n";        
      }
      if(null!=strMsg && !"".equals(strMsg)){
    	  textareahistory.setText(strMsg);
          f4.setSize(550, 200);
          f4.setLocation((screenWidth-f4.getWidth())/2, (screenHeight-f4.getHeight())/2);
          f4.setResizable(true);
          Container contentPane = f4.getContentPane();   
          contentPane.setLayout(new BoxLayout(contentPane,2)); 
          contentPane.add(textareahistory);
          f4.show();
      }
      return Native2AsciiUtils.ascii2Native(strResult);        
  }        
	  /**  
	   * Get the new msg  
	   * @return  
	   */   
	  public static List<MessageBean> showLastListMsg(){        
         
		  String strMsg = "" ;
          for(int i=0;i<listBean.size();i++){        
              MessageBean bean = listBean.get(i);        
              Timestamp stamp1 = TimeUtil.getTimeFromString(bean.getCreated_at());        
              Timestamp stamp2 = TimeUtil.getTimeFromString(last_update_time);        
              long diff = TimeUtil.timeDiff2Timestamp(stamp1, stamp2);        
              if(diff>0){        
                  last_update_time = bean.getCreated_at();//取最后一条记录的时间        
              }        
              strMsg = strMsg + "No."+(i+1)+": ["+bean.getCreated_at()+"] "+bean.getSender().getName()+" :"+bean.getPlain_body()+"\n";        
          }   
          //Show List on the Window
          if(null!=strMsg && !"".equals(strMsg)){
	          textareashow.setText(strMsg);
	          f3.setSize(550, 200);
	          f3.setLocation((screenWidth-f3.getWidth())/2, (screenHeight-f3.getHeight())/2);
	          f3.setResizable(true);
	          Container contentPane = f3.getContentPane();   
	          contentPane.setLayout(new BoxLayout(contentPane,2)); 
	          contentPane.add(textareashow);
	          f3.show();
          }
          for(int i=0;i<listBean.size();i++){        
              listBean.remove(i);        
              i--;        
          }   
          ti.setToolTip ("["+user_name+"]"+"You have "+listBean.size()+" message to Read !");     
          return listBean ;        
      }   
     
     
       public static int receiveNewMessage(){   
              
              String strResult = null;        
              try {        
                      strResult = ClientUtils.getJsonContent("api.iteye.com","api/messages/inbox", user_name,user_pass,isproxy);        
                      strResult = Native2AsciiUtils.ascii2Native(strResult);        
                      JSONArray jsonArray = JSONArray.fromObject(Native2AsciiUtils.ascii2Native(strResult));        
                      MessageBean[] beans = (MessageBean[])JSONArray.toArray(jsonArray, MessageBean.class);        
                              
                      for(int i=0;i<listBean.size();i++){        
                          listBean.remove(i);        
                          i--;        
                      }        
                      for(int i=0;i<beans.length;i++){        
                          Timestamp stamp1 = TimeUtil.getTimeFromString(beans[i].getCreated_at());        
                          Timestamp stamp2 = TimeUtil.getTimeFromString(last_update_time);        
                          long diff = TimeUtil.timeDiff2Timestamp(stamp1, stamp2);        
                          if(diff > 0){        
                             listBean.add(beans[i]);        
                          }        
                      }        
              } catch (Exception e) {        
                   Label label1 = null;   
                   JFrame f = new JFrame("Error");   
                   f.setLocation((screenWidth-250)/2, (screenHeight-80)/2);
                   f.setSize(250, 80);
                   f.setResizable(true);
                   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   label1 = new Label("username/password is incorrect!"+"or Error:"+e.getMessage());   
                   Container contentPane = f.getContentPane();   
                   contentPane.setLayout(new GridLayout(1,1));   
                   contentPane.add(label1);   
                   //f.pack();   
                   f.show();   
            }   
              return 1 ;   
       }   
       
      public static int receiveNewMessageIcon(){   
      
	      // If have new msg ,there must to change the status of the program!   
	      if(listBean.size()>0){        
	            ti.setToolTip ("["+user_name+"]"+"You have "+listBean.size()+" message to Read !");     
	            if(count%2==0){   
	                ti.setImage(Toolkit.getDefaultToolkit().getImage(pmt_urlwhite));     
	            }else{   
	                ti.setImage(Toolkit.getDefaultToolkit().getImage(pmt_url));     
	            }   
	      }else{   
	          count = 0 ;   
	          ti.setImage(Toolkit.getDefaultToolkit().getImage(pmt_url));   
	      }        
	         
	      if(count==1000000000){count=0;}                 
	      count++ ;   
	      return 1 ;     
     }   
 
  
     public static String sendMessage(){   

    	 f2.setSize(500, 180);
         f2.setLocation((screenWidth-f2.getWidth())/2, (screenHeight-f2.getHeight())/2);
         f2.setResizable(true);
         Container contentPane = f2.getContentPane();   
         contentPane.setLayout(new BoxLayout(contentPane,2)); 
         s_send.addActionListener( new ActionListener(){   
             public void actionPerformed(ActionEvent ae){   
            	 String str=null;   
                 String strResult = null;   
                 str = sContent.getText();    
                 try {   
                     //The third param is true for proxy,false for no proxy .   
                	 f2.hide();
                	 str = str.replaceAll("\r", "[Line]");
                	 str = str.replaceAll("\n", "");
                	 //str = str.replaceAll(" ", "");
                	 str = str.replaceAll("\"", "“");
                     strResult = ClientUtils.getJsonContent("api.iteye.com","api/messages/create?title=Message:&receiver_name="+receive_name+"&body="+str, user_name,user_pass,isproxy);
                     JOptionPane pane = new JOptionPane();
            	     pane.showMessageDialog(null, "Message sent successfully!");
                 } catch (Exception e) {   
                	 f2.hide();
                	 JOptionPane pane = new JOptionPane();
            	     pane.showMessageDialog(null, "Message failed,Please try again!");
                 }
                 
             }   
         }); 
         contentPane.add(sContent);
         contentPane.add(s_send);
         f2.show();
         
         return "" ;
         
     }   
     
     
    public static void main(String[] args){     
         
       Container contentPane = f1.getContentPane();   
       contentPane.setLayout(new BoxLayout(contentPane,3));   
       Label label1 = new Label("please input the username,userpass,receivename by order !");   
       tPass.setEchoChar('*');
       b_login.addActionListener( new ActionListener(){   
           public void actionPerformed(ActionEvent ae){   
                 user_name = tName.getText();   
                 user_pass  = tPass.getText();   
                 receive_name = tReceive.getText();   
                 showThread.start();   
                 iconThread.start();   
                 f1.hide();
                 systemTray();
           }   
       });   
         
       f1.setSize(350, 150);
       f1.setLocation((screenWidth-f1.getWidth())/2, (screenHeight-f1.getHeight())/2);
       f1.setResizable(false);
       f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       contentPane.add(label1);   
       contentPane.add(tName);   
       contentPane.add(tPass);   
       contentPane.add(tReceive);   
       contentPane.add(b_login); 
       //f1.pack();   
       f1.show();   
          
    }    
 
  }   

 

 

 

   

IconThread.java

package gerry;   
  
public class IconThread extends Thread{        
       
    public long times = 500L ; //500ms        
            
    public IconThread(){}        
            
    @SuppressWarnings("static-access")        
    public void run()  {        
        while(true){        
            ClientViewMain.receiveNewMessageIcon();//图标闪动      
            try {        
                this.sleep(times);        
            } catch (InterruptedException e) {        
                e.printStackTrace();        
            }        
        }        
    }        
            
            
}        

 

 

 

ShowThread.java

package gerry;   
  
public class ShowThread extends Thread{        
       
    public long times = 30000L ; //30000ms        
            
    public ShowThread(){}        
            
    @SuppressWarnings("static-access")        
    public void run()  {        
        while(true){        
            ClientViewMain.receiveNewMessage();//程序后台接收数据        
            try {        
                this.sleep(times);        
            } catch (InterruptedException e) {        
                e.printStackTrace();        
            }        
        }        
    }        
            
}      

 

 

  

images 文件夹

两个图片文件:pmt.gif 托盘图标
pmtwhite.gif  16X16透明图片

 

 

  

ClientUtils.java

package tools;   
  
import java.io.IOException;   
import org.apache.http.HttpEntity;   
import org.apache.http.HttpException;   
import org.apache.http.HttpHost;   
import org.apache.http.HttpRequest;   
import org.apache.http.HttpRequestInterceptor;   
import org.apache.http.HttpResponse;   
import org.apache.http.auth.AuthScheme;   
import org.apache.http.auth.AuthScope;   
import org.apache.http.auth.AuthState;   
import org.apache.http.auth.Credentials;   
import org.apache.http.auth.UsernamePasswordCredentials;   
import org.apache.http.client.ClientProtocolException;   
import org.apache.http.client.CredentialsProvider;   
import org.apache.http.client.methods.HttpGet;   
import org.apache.http.client.protocol.ClientContext;   
import org.apache.http.conn.params.ConnRoutePNames;   
import org.apache.http.impl.auth.BasicScheme;   
import org.apache.http.impl.client.DefaultHttpClient;   
import org.apache.http.protocol.BasicHttpContext;   
import org.apache.http.protocol.ExecutionContext;   
import org.apache.http.protocol.HttpContext;   
import org.apache.http.util.EntityUtils;   
  
public class ClientUtils {   
    /**  
     * 基于Basic认证的httpclient 连接  
     * @param hostUrl 要请求的host name    如:http://api.iteye.com/api/twitters/list -> api.iteye.com  
     * @param getUrl  要请求的get url     如:http://api.iteye.com/api/twitters/list -> api/twitters/list  
     * @param userName  username  
     * @param password  password  
     * @param isProxy   isProxy  
     * @return javaeye api 返回的json字符串  
     * @throws IOException   
     * @throws ClientProtocolException   
     */   
    public static String getJsonContent(String hostUrl,String getUrl,String userName,String password,boolean isProxy) throws ClientProtocolException, IOException{   
        String jsonStr="";   
        getUrl = getUrl.replaceAll(" ", ",");   
           
        DefaultHttpClient httpclient = new DefaultHttpClient();   
           
        httpclient.getCredentialsProvider().setCredentials(new AuthScope(hostUrl, 80), new UsernamePasswordCredentials(userName, password));   
        BasicHttpContext localcontext = new BasicHttpContext();   
  
        BasicScheme basicAuth = new BasicScheme();   
        localcontext.setAttribute("preemptive-auth", basicAuth);   
        httpclient.addRequestInterceptor((HttpRequestInterceptor) new PreemptiveAuth(), 0);   
           
        HttpHost targetHost = new HttpHost(hostUrl);   
        //Set proxy    
        if(isProxy){   
          HttpHost proxy = new HttpHost("openproxy.xxx.com",8080);   
          httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);   
        }   
        HttpGet httpget = new HttpGet("/" + getUrl);   
           
        HttpResponse response = httpclient.execute(targetHost, httpget, localcontext);   
        HttpEntity entity = response.getEntity();   
  
        if (entity != null) {               
            jsonStr = EntityUtils.toString(entity);   
            //System.out.println(jsonStr);               
            entity.consumeContent();   
        }   
        httpclient.getConnectionManager().shutdown();    
        return jsonStr;   
    }   
       
    static class PreemptiveAuth implements HttpRequestInterceptor {   
  
        public void process(final HttpRequest request,final HttpContext context) throws HttpException, IOException {   
               
            AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);   
            // If no auth scheme avaialble yet, try to initialize it preemptively   
            if (authState.getAuthScheme() == null) {   
                AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");   
                CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);   
                HttpHost targetHost = (HttpHost) context.getAttribute(   
                        ExecutionContext.HTTP_TARGET_HOST);   
                if (authScheme != null) {   
                    Credentials creds = credsProvider.getCredentials(   
                            new AuthScope(   
                                    targetHost.getHostName(),    
                                    targetHost.getPort()));   
                    if (creds == null) {   
                        throw new HttpException("No credentials for preemptive authentication");   
                    }   
                    authState.setAuthScheme(authScheme);   
                    authState.setCredentials(creds);   
                }   
            }   
               
        }   
    }   
       
}   

 

 

  

Native2AsciiUtils.java

package tools;   
  
/**    
 * 仿照JDK-native2ascii.exe功能实现的(Java源代码)  
 * Unicode编码转码  
 * 2010-08-06  
 * @author  Gerry   
 * @version 1.0    
 */     
public class Native2AsciiUtils {      
  
    /**    
     * prefix of ascii string of native character    
     */     
    private static String PREFIX = "\\u";      
     
    /**    
     * Native to ascii string. It's same as execut native2ascii.exe.    
     * @param str    
     *        native string    
     * @return ascii string    
     */     
    public static String native2Ascii(String str) {      
        char[] chars = str.toCharArray();      
        StringBuilder sb = new StringBuilder();      
        for (int i = 0; i < chars.length; i++) {      
            sb.append(char2Ascii(chars[i]));      
        }      
        return sb.toString();      
    }      
     
    /**    
     * Native character to ascii string.    
     * @param c    
     *            native character    
     * @return ascii string    
     */     
    private static String char2Ascii(char c) {      
        if (c > 255) {      
            StringBuilder sb = new StringBuilder();      
            sb.append(PREFIX);      
            int code = (c >> 8);      
            String tmp = Integer.toHexString(code);      
            if (tmp.length() == 1) {      
                sb.append("0");      
            }      
            sb.append(tmp);      
            code = (c & 0xFF);      
            tmp = Integer.toHexString(code);      
            if (tmp.length() == 1) {      
                sb.append("0");      
            }      
            sb.append(tmp);      
            return sb.toString();      
        } else {      
            return Character.toString(c);      
        }      
    }      
     
    /**    
     * Ascii to native string. It's same as execute native2ascii.exe -reverse.    
     * @param str    
     * ascii string    
     * @return native string    
     */     
    public static String ascii2Native(String str) {      
        StringBuilder sb = new StringBuilder();      
        int begin = 0;      
        int index = str.indexOf(PREFIX);      
        while (index != -1) {      
            sb.append(str.substring(begin, index));      
            sb.append(ascii2Char(str.substring(index, index + 6)));      
            begin = index + 6;      
            index = str.indexOf(PREFIX, begin);      
        }      
        sb.append(str.substring(begin));      
        return sb.toString();      
    }      
     
    /**    
     * Ascii to native character.    
     * @param str    
     * ascii string    
     * @return native character    
     */     
    private static char ascii2Char(String str) {      
        if (str.length() != 6) {      
            throw new IllegalArgumentException("Ascii string of a native character must be 6 character.");      
        }      
        if (!PREFIX.equals(str.substring(0, 2))) {      
            throw new IllegalArgumentException("Ascii string of a native character must start with \"\\u\".");      
        }      
        String tmp = str.substring(2, 4);      
        int code = Integer.parseInt(tmp, 16) << 8;      
        tmp = str.substring(4, 6);      
        code += Integer.parseInt(tmp, 16);      
        return (char) code;      
    }      
     
}     

 

 

  

TimeUtil.java

package tools;   
  
import java.sql.Timestamp;   
import java.text.ParseException;   
import java.text.SimpleDateFormat;   
import java.util.Date;   
import java.util.GregorianCalendar;   
import java.util.Locale;   
  
public class TimeUtil {   
  
       
    /**  
     *   
     * Notes: 格式转换  
     * @param strTime  
     * @return  
     * Created:2010-8-11  
     * @author:Gerry  
     */   
    public static Timestamp getTimeFromString(Object strTime) {   
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ENGLISH);   
           
        Date date = new Date();   
        if (!strTime.equals("")) {   
            try {   
                String s=strTime.toString();   
                if(s.indexOf(".")!=-1){   
                    if(s.substring(s.indexOf(".")).length()>4){   
                        s=s.substring(0, s.indexOf(".")+4);   
                    }   
                }   
                date = format.parse(s);   
            } catch (ParseException e) {   
                e.printStackTrace();   
            }   
        }   
        Timestamp t = new Timestamp(date.getTime());    
        return t;   
    }   
       
       
    /**  
     * 计算指定的两个时间的时间差数值  
     * @param time  
     * @param anotherTime "2009-12-12 00:55:25.000 "  
     * 前面的时间减去后面的时间  
     * @return  
     */   
    public static long timeDiff2Timestamp(Timestamp time, Timestamp anotherTime) {   
        long timeDiff = 1000;// 时间的差数值   
        timeDiff = time.getTime()-anotherTime.getTime();   
        return timeDiff;   
    }   
       
       
    /**  
     * 当前时间  
     * Notes:TODO Please specify the functions of the method.  
     * @return  
     * Created:2010-8-11  
     * @author:Gerry  
     */   
    public static String getCurrentTimeString() {   
        return getCurrentTimeByFormat("yyyy/MM/dd HH:mm:ss");   
    }   
       
       
    private static String getCurrentTimeByFormat(String format) {   
        GregorianCalendar calendar = new GregorianCalendar();   
        java.util.Date date = calendar.getTime();   
        SimpleDateFormat sformat = new SimpleDateFormat(format);   
        String currentDate = sformat.format(date);   
        return currentDate;   
    }   
       
}   

 

分享到:
评论
4 楼 ling520 2010-09-06  
问题描述:
发送消息时点右键send出现输入框,输入内容后点send发送,第一次弹出一个发送成功的提示确认框,但第二次发送时弹出一个发送确认的提示框后,点确定,又出现一个,第三次出现3个,每次都需点确定,随着发送次数的增加确认次数也在增加,导致一条消息发送多次的情况。
3 楼 ling520 2010-09-06  
亲爱的总结:
1.查看消息后,加一个回复按钮,方便回复;2.发送消息时可以用键盘Enter发送;3.发送消息后致按钮为灰,以免重复提交数据!

看着这段话,我突然第一次感觉你真的是个程序员,呵呵~
2 楼 ling520 2010-09-03  
Mybeautiful 写道
这样就能聊天了,开玩笑吧?另外哪里用javaeye的api了。

的却是可以哦,我们都用好久了,没试过犯不着就怀疑吧??
1 楼 Mybeautiful 2010-09-03  
这样就能聊天了,开玩笑吧?另外哪里用javaeye的api了。

相关推荐

    基于JavaEye-API实现的Gerry-聊天Dos版v1.0-lib库

    NULL 博文链接:https://ago520.iteye.com/blog/814571

    backport-util-concurrent-3.1.jar和geronimo-stax-api_1.0_spec-1.0.1.jar

    "geronimo-stax-api_1.0_spec-1.0.1.jar"则是Geronimo项目的STAX API规范实现,STAX(Streaming API for XML)是一种处理XML的API,它允许开发者以流式的方式读取和写入XML数据,比DOM解析更高效,因为它不需要一次...

    JavaEye的API使用帮助.rar

    JavaEye的API使用帮助是一个针对JavaEye开发框架的详细指南,旨在帮助开发者更好地理解和应用这个框架。这个压缩包包含了三个文件:一个PDF文档,一个TXT文本文件,以及一个URL链接。接下来,我们将深入探讨JavaEye ...

    Java学习网站---API手册下载---开发工具---项目源码---学习资料汇总

    - **JDK 5.0 API**:官方中文版,帮助开发者理解和使用Java 5.0的类库和接口。 - **JDK 1.6 API**:CHM格式的中文版,适用于Java 1.6版本。 4. **Java源码下载**: - **源码爱好者-JAVA专区**:提供各种Java项目...

    httpClient调用javaeye API验证用户

    在这个场景中,我们使用HttpClient来调用JavaEye API来验证用户。JavaEye可能是一个提供用户认证服务的平台,而API则提供了验证用户身份的功能。 以下是一个关于如何使用HttpClient调用JavaEye API的基本步骤: 1....

    java 棋盘覆盖V1.0版

    寒假花了3、4天改进了一下棋盘覆盖游戏,支持电脑演示,也可自己过关,具体可自己玩 ...呵呵 有安装程序 我放在javaeye上别人说有毒,真是无语,结果版主还给我屏蔽了。。。 我用的是Smart Install Maker安装软件打包的

    JavaEye论坛热点_-_2008年11月_-_总第6期

    - JEECMS是一个基于Java的企业级内容管理系统,版本v1.1和v2.0的发布,展示了开源社区对内容管理系统的贡献,并提供了更多的功能如评论和投票。 11. **正则表达式实现的讨论** - Sun的Regexpr实现可能成为讨论的...

    javaeye api [java httpclient版] 简单封装

    JavaEye API 的简单封装主要基于 Java 的 HttpClient 库,提供了更方便、易用的接口来执行 HTTP 请求。HttpClient 是一个成熟的 Java 库,用于执行 HTTP 协议的客户端请求,而 JavaEyeClient 则是对这个库进行了一层...

    JavaEye新闻月刊 - 2009年09月 - 总第19期.pdf

    这个预览版包含了一系列新特性和改进,为即将发布的正式版奠定了基础。 - 后续的Eclipse 3.5.1 Galileo SR1版本则是对3.5版本的一次重要更新,修复了若干问题并提升了整体稳定性。 6. **Spring框架的更新** - ...

    Jsp-Servlet复习笔记-----第3章 Servlet技术 - 堕落天使 - JavaEye技术网站.mht

    Jsp-Servlet复习笔记-----第3章 Servlet技术 - 堕落天使 - JavaEye技术网站.mhtJsp-Servlet复习笔记-----第3章 Servlet技术 - 堕落天使 - JavaEye技术网站.mht

    javaeye 基于android客户端

    JavaEye是一个基于Android平台的应用程序,它展示了在移动设备上构建功能丰富的软件的可能性。这个小应用旨在为开发者提供灵感和指导,帮助他们更好地理解和实践Android应用开发。让我们深入探讨一下这个应用背后的...

    JavaEye新闻月刊 - 2010年01月 - 总第23期.pdf

    Xmappr是一个用Java实现的XML处理工具,它可能提供了高效且易于使用的API,帮助开发者更便捷地处理XML文档。 7. **2010年JFreeChart图表的新功能**: JFreeChart,一个流行的Java图表库,发布了新版本,增加了新...

    网站Android客户端制作帮助文档

    - 实现了JavaEye闲聊功能,允许用户进行即时聊天。 - 支持站内短信功能,方便用户发送和接收站内消息。 - 集成了收藏功能,让用户能够收藏感兴趣的内容。 - **发布情况**:该应用已经成功上线Android Market,即...

    基于SNMP的网络拓扑发现 -------------

    基于SNMP的网络拓扑发现 - 我的未来不是梦! - JavaEye技术网站.files基于SNMP的网络拓扑发现 - 我的未来不是梦! - JavaEye技术网站.files

    JavaEye Client SourceCode

    2. **Android SDK**:作为基于Android平台的应用,JavaEye Client SourceCode必然使用了Android SDK,包括Android API的各种类库,例如视图(View)和布局(Layout)系统,以及用于网络通信、数据库操作、文件I/O等...

    JavaEye新闻月刊_-_2009年3月_-_总第13期

    JavaEye新闻月刊2009年3月第13期内容涉及了当时软件开发领域内的一系列重要话题,包括IBM拟收购Sun Microsystems公司的新闻报道、Java社区对此的看法以及各种编程语言、开发工具和技术的新动态。 首先,新闻月刊...

    javaeye热点阅读

    13. Excel Report:这是一个基于Java实现的轻量级Excel报表生成工具,适合快速生成和导出数据报表。 14. Spring与Hibernate的声明式事务管理:Spring的声明式事务管理简化了事务控制,与Hibernate集成后能有效处理...

Global site tag (gtag.js) - Google Analytics