import import import import import import import

java.awt.*; java.awt.event.*; java.util.*; java.net.*; java.io.*; javax.swing.*; javax.swing.event.*;

public class openurl { public static void main(string []args) { jframe frame = new simpleframe(); frame.show(); } } class simpleframe extends jframe implements actionlistener { private bufferedreader in; private printwriter out; private jtextfield urltext; private jtextarea text; private jlabel urllbl; private jeditorpane edit; public simpleframe() { settitle("url download demo"); setsize(200,300); addwindowlistener(new windowadapter() { public void windowclosing(windowevent e) { system.exit(0); } } ); getcontentpane().setlayout(new flowlayout(flowlayout.left)); urllbl = new jlabel("please enter a url to download"); getcontentpane().add(urllbl); urltext = new jtextfield(20); urltext.settext("http://"); getcontentpane().add(urltext); text = new jtextarea(10,50); getcontentpane().add(text); jscrollpane p1 = new jscrollpane(text);

getcontentpane().add(p1); jbutton downbutton = new jbutton("download url"); downbutton.addactionlistener(this); jpanel buttonpanel = new jpanel(); buttonpanel.add(downbutton); getcontentpane().add(downbutton); } public void actionperformed(actionevent evt) { swingutilities.invokelater(new runnable() { public void run() { downloadurl(); } } ); } public void downloadurl() { try { url url = new url(urltext.gettext()); inputstream uin = url.openstream(); bufferedreader in = new bufferedreader(new inputstreamreader(uin)); string line; while((line=in.readline())!=null) { text.settext(text.gettext() + " " + line); } } catch(exception e) { system.out.println("error: " +e); } } }

Sign up to vote on this title
UsefulNot useful