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