Offline Web page maker (beta1.0)

Source: Internet
Author: User

1  PackageHhuarongdao;2 /*3 * How to use: First select Save path, then enter the corresponding URL,4 * Then you'll get the offline version of that page .5  * */6 Importjava.awt.BorderLayout;7 ImportJava.awt.Container;8 Importjava.awt.FlowLayout;9 ImportJava.awt.Font;Ten Importjava.awt.event.ActionEvent; One ImportJava.awt.event.ActionListener; A ImportJava.io.File; - Importjava.io.FileNotFoundException; - ImportJava.io.FileOutputStream; the Importjava.io.IOException; - ImportJava.io.InputStream; - ImportJava.io.OutputStream; - Importjava.net.MalformedURLException; + ImportJava.net.URL; - ImportJava.util.Scanner; + ImportJavax.swing.ImageIcon; A ImportJavax.swing.JButton; at ImportJavax.swing.JFileChooser; - ImportJavax.swing.JFrame; - ImportJavax.swing.JLabel; - ImportJavax.swing.JOptionPane; - ImportJavax.swing.JPanel; - ImportJavax.swing.JTextField; in  -  Public classStu { to      Public Static voidMain (String args []) { +Setbjing mybe=Newsetbjing (); -     } the } *  $ classMywndowextendsJFramePanax Notoginseng  { - Mywndow (String title) { the Settitle (title); +SetBounds (200,100, 400,300); A          This. setresizable (false); the       } +  } - //set a background $ classSetbjingImplementsActionListener $ { - URL url;  -Look it=NewLook (); the Thread Readurl; - Container com;Wuyi JButton Button,button1; the JTextField Text,mytext; - setbjing () { WuMywndow hehe =NewMywndow ("Offline web maker 1.bate"); -Com=Hehe.getcontentpane (); AboutCom.setlayout (NewFlowLayout ()); $MyText =NewJTextField (20); -Mytext.seteditable (false);//settings become not -Mytext.setfont (NewFont ("Arial", font.bold,22)); -Button1 =NewJButton ("Select Path"); AButton1.addactionlistener ( This); +button =NewJButton ("Submitt"); theButton.addactionlistener ( This); -Text =NewJTextField (20); $Text.addactionlistener ( This); theJLabel label =NewJLabel ("Input URL, such as: http://www.baidu.com"); the com.add (label); the Com.add (text); the com.add (button); - Com.add (button1); in Com.add (mytext); theHehe.setvisible (true); the hehe.setdefaultcloseoperation (jframe.exit_on_close); About       //Text.settext ("Enter the URL, for example:http://www.baidu.com"); the     } the        Public  voidWork (String ss) { the               Try { +URL =NewURL (ss); - it.seturl (URL); theReadurl =NewThread (it);Bayi Readurl.start (); the              } the             Catch(Exception exp) -             { -                 //TODO auto-generated Catch block theJoptionpane.showmessagedialog (Text,exp, "offline web maker 1.bate", joptionpane.error_message); the             } the              } the @Override -      Public voidactionperformed (ActionEvent e) { the         //TODO auto-generated Method Stub the         if(E.getsource () = =button) { theString ss=Text.gettext (). toString (). Trim (); 94 Work (ss); theText.settext (NULL); the         } the         Else if(E.getsource () = =button1) {98JFileChooser chooser =NewJFileChooser (); AboutChooser.setcurrentdirectory (NewFile ("d:/"));//The default path is D drive -Chooser.setfileselectionmode (jfilechooser.directories_only);//file selection mode, read-only101             intindex = Chooser.showdialog (NULL, "OK");102             if(index==Chooser. Approve_option) {103 It.setpath (Chooser.getselectedfile (). GetAbsolutePath ());104 Mytext.settext (Chooser.getselectedfile (). GetAbsolutePath (). toString ()); the              //validate ();106             }107         }108     }109 } the classLookImplementsRunnable111 { the URL url;113      PublicFile fwrite =NewFile ("url.html"); the    voidSetPath (String Road) the    { theFwrite =NewFile (road+ ". html");117    }118      Public voidseturl (url url) {119          This. url=URL;  -     }121 @Override122      Public voidrun () {123         //TODO auto-generated Method Stub124       Try{ theOutputStream out =NewFileOutputStream (Fwrite,true);126InputStream in=Url.openstream ();127           byte[] A=New byte[1024]; -           intN=-1;129           while((N=in.read (a))!=-1 ){ theOut.write (A, 0, n);131          } the out.close ();133Joptionpane.showmessagedialog (NULL, "Saved successfully! "," offline Web maker 1.bate ", joptionpane.error_message);134       }135      Catch(IOException e) {136Joptionpane.showmessagedialog (NULL, "File Save failed!" "," offline Web maker 1.bate ", joptionpane.error_message);137        };138     }139}

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.