File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .awt .*;
2
+ import java .awt .event .*;
3
+ import java .io .InputStream ;
4
+ import java .net .*;
5
+ public class SourceGetter extends Frame implements ActionListener {
6
+ TextField tf ;
7
+ TextArea ta ;
8
+ Button b ;
9
+ Label l ;
10
+ SourceGetter (){
11
+ super ("Source Getter Tool - Javatpoint" );
12
+ l =new Label ("Enter URL:" );
13
+ l .setBounds (50 ,50 ,50 ,20 );
14
+
15
+ tf =new TextField ();
16
+ tf .setBounds (120 ,50 ,250 ,20 );
17
+
18
+ b =new Button ("Get Source Code" );
19
+ b .setBounds (120 , 100 ,120 ,30 );
20
+ b .addActionListener (this );
21
+
22
+ ta =new TextArea ();
23
+ ta .setBounds (120 ,150 ,250 ,150 );
24
+
25
+ add (l );add (tf );add (b );add (ta );
26
+ setSize (400 ,400 );
27
+ setLayout (null );
28
+ setVisible (true );
29
+ }
30
+ public void actionPerformed (ActionEvent e ){
31
+ String s =tf .getText ();
32
+ if (s ==null ){}
33
+ else {
34
+ try {
35
+ URL u =new URL (s );
36
+ URLConnection uc =u .openConnection ();
37
+
38
+ InputStream is =uc .getInputStream ();
39
+ int i ;
40
+ StringBuilder sb =new StringBuilder ();
41
+ while ((i =is .read ())!=-1 ){
42
+ sb .append ((char )i );
43
+ }
44
+ String source =sb .toString ();
45
+ ta .setText (source );
46
+ }catch (Exception ex ){System .out .println (e );}
47
+ }
48
+ }
49
+ public static void main (String [] args ) {
50
+ new SourceGetter ();
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments