JAVA------12.app Test API interface

Source: Internet
Author: User
Tags getmessage

Importjava.awt.BorderLayout;Importjava.awt.FlowLayout;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader;Importjava.net.MalformedURLException;ImportJava.net.URL;Importjava.net.URLConnection;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;ImportJavax.swing.JLabel;ImportJavax.swing.JPanel;ImportJavax.swing.JScrollPane;ImportJavax.swing.JTextArea;ImportJavax.swing.JTextField;Importjavax.swing.ScrollPaneConstants;/*** Call URL parsing *@authorCaipei **/ Public classUrlutilextendsjframe{/**     *      */    Private Static Final LongSerialversionuid = 1L; JTextField TF=NULL; JButton Button=NULL, clear=NULL; JTextArea Ta=NULL;  PublicUrlutil () {tf=NewJTextField (28); Button=NewJButton ("Submit"); Clear=NewJButton ("Clear"); Ta=NewJTextArea ();        Init (); Button.addactionlistener (NewMyactionlistener ()); Clear.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {//TODO auto-generated Method StubTf.settext (""); Ta.settext ("\t\t\tthis TextArea has been cleared! \n\n\t\t\tyou can begin your next test! ");            Tf.grabfocus ();    }        }); }     Public Static voidMain (String []args) {NewUrlutil (); } @SuppressWarnings ("Deprecation")     Public voidinit () { This. Settitle ("Json String Fetch tool");  This. SetSize (800,450);  This. setvisible (true);  This. Setdefaultcloseoperation (Exit_on_close);  This. Setlocationrelativeto (NULL); JScrollPane JS=NewJScrollPane (TA);        Js.setverticalscrollbarpolicy (scrollpaneconstants.vertical_scrollbar_as_needed); JPanel P=NewJPanel (); P.setlayout (NewFlowLayout ()); P.add (NewJLabel ("URL:"));        P.add (TF);        P.add (button);        P.add (Clear); Tf.setfocusable (true);        Button.setnextfocusablecomponent (TF);  This. Add (P,borderlayout.north);  This. Add (Js,borderlayout.center); }     Public Staticstring getjsonstring (string url) {string result=""; URLConnection Conn=NULL; BufferedReader Reader=NULL; Try{URL website=NewURL (Url.trim ()); Conn=(URLConnection) website.openconnection (); Reader=NewBufferedReader (NewInputStreamReader (Conn.getinputstream (), "Utf-8")); String Line=""; StringBuffer SB=NewStringBuffer ();  while((Line=reader.readline ())! =NULL) {sb.append (line); } result=sb.tostring (); }Catch(malformedurlexception urlexception) {result+=Urlexception.getmessage (); } Catch(IOException e) {//TODO auto-generated Catch blockresult+=E.getmessage ();        E.printstacktrace (); }Catch(Exception total) {result+=Total.getmessage ();        Total.printstacktrace (); }finally{            if(conn!=NULL) {Conn=NULL; }            if(reader!=NULL){                Try{reader.close (); } Catch(IOException e) {//TODO auto-generated Catch blockresult+=E.getmessage ();                E.printstacktrace (); } Reader=NULL; }        }        returnresult; }    classMyactionlistenerImplementsactionlistener{@Override Public voidactionperformed (ActionEvent e) {//TODO auto-generated Method StubString jsonstring=getjsonstring (Tf.gettext (). Trim (). toString ());        Ta.settext (jsonstring); }    }}

JAVA------12.app Test API interface

Related Article

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.