Java Turing Man Auto reply

Source: Internet
Author: User

First go to http://www.tuling123.com/to apply for key

 Packagecom.rjgc13.tuling;ImportOrg.apache.http.HttpResponse;ImportOrg.apache.http.client.methods.HttpGet;Importorg.apache.http.impl.client.HttpClients;Importorg.apache.http.util.EntityUtils; Public classHttpgetrequest { Public Staticstring get (string url) {Try{HttpGet Request=Newhttpget (URL); HttpResponse Response=Httpclients.createdefault (). Execute (Request); String result=""; if(Response.getstatusline (). Getstatuscode () ==200) {result=entityutils.tostring (Response.getentity ()); }            returnresult; } Catch(Exception e) {e.printstacktrace (); return""; }    }}
 Packagecom.rjgc13.tuling;ImportNet.sf.json.JSONObject; Public classTulingcontroller { Public Staticstring Gettulingre (String info) {String URL= "http://www.tuling123.com/openapi/api?key=********************************&info=" +info; String Tlresult=httpgetrequest.get (URL); Jsonobject JSON=Jsonobject.fromobject (Tlresult); Tlresult=json.getstring ("Text"); returnTlresult; }}
 Packagecom.rjgc13.tuling;Importjava.util.Properties;Importjavax.swing.*;Importjava.awt.*;Importjava.awt.event.*; Public classMainextendsJFrame {Private StaticJFrame frame; Private StaticJTextArea Viewarea; Private StaticJTextField ViewField; Private StaticJButton button1; Private StaticJButton button2; Private StaticJTextField MyName;  Public StaticString str= "";  Public Static voidMain (string[] args) {frame=NewJFrame ("Chat"); Viewarea=NewJTextArea (10, 30); ViewField=NewJTextField (50); Button1=NewJButton ("Send"); Button2=NewJButton ("Quit"); MyName=NewJTextField (); Myname.setcolumns (9); Myname.settext ("Saber_lily:"); JPanel Panel=NewJPanel (); Panel.setlayout (NewGridLayout (8, 1));        Panel.add (MyName);        Panel.add (button1);        Panel.add (button2); JScrollPane SP=NewJScrollPane (Viewarea); Viewarea.setlinewrap (true);        Sp.sethorizontalscrollbarpolicy (Jscrollpane.horizontal_scrollbar_never);        Sp.setverticalscrollbarpolicy (jscrollpane.vertical_scrollbar_always); Frame.add ("Center", SP); Frame.add ("East", panel); Frame.add ("South", ViewField); Viewfield.addkeylistener (NewKeyListener () { Public voidkeytyped (KeyEvent arg0) {if(Arg0.getkeychar () = = ' \ n ') {String message= ""; Message= Myname.gettext () +Viewfield.gettext (); STR=str+viewfield.gettext () + "\ n"; String ans= "Small U:"; Ans= ans +Tulingcontroller.gettulingre (Viewfield.gettext ()); Viewfield.settext (""); Viewarea.settext (Viewarea.gettext ()+ message + "\ n"); Viewarea.settext (Viewarea.gettext ()+ ans + "\ n"); Viewfield.setfocusable (true);                Viewfield.requestfocus (); }            }             Public voidkeyreleased (KeyEvent arg0) {//TODO auto-generated Method Stub            }             Public voidkeypressed (KeyEvent arg0) {//TODO auto-generated Method Stub            }        }); Frame.setsize (700, 500); Frame.setvisible (true); //Center DisplayFrame.setlocationrelativeto (NULL); Button1.addactionlistener (NewActionListener () { Public voidactionperformed (ActionEvent arg0) {String message= ""; Message= Myname.gettext () +Viewfield.gettext (); String ans= "Small U:"; Ans= ans +Tulingcontroller.gettulingre (Viewfield.gettext ()); Viewfield.settext (""); Viewarea.settext (Viewarea.gettext ()+ message + "\ n"); Viewarea.settext (Viewarea.gettext ()+ ans + "\ n"); Viewfield.setfocusable (true);            Viewfield.requestfocus ();        }        }); Button2.addactionlistener (NewActionListener () { Public voidactionperformed (ActionEvent arg0) {system.exit (0);        }        }); Viewfield.setfocusable (true);        Viewfield.requestfocus (); //frame.setfocusable (TRUE); //Frame.requestfocus ();    }}

Source code Download Link: http://pan.baidu.com/s/1kU7iQc3 Password: 4BBK

Java Turing Man Auto reply

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.