import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.URL;

import java.net.URLConnection;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.JTextField;


public class SourceView extends JFrame implements ActionListener{

JPanel p = new JPanel();

JLabel urlLbl = new JLabel("URL : ");

JTextField tf = new JTextField(20);

JButton okBtn = new JButton("확인");

JScrollPane sp;

JTextArea ta = new JTextArea();

public SourceView() {

p.add(urlLbl); p.add(tf); p.add(okBtn);

add(p, "North");

sp = new JScrollPane(ta);

add(sp, "Center");

setSize(500, 500);

setVisible(true);

tf.addActionListener(this);

okBtn.addActionListener(this);

}

public void actionPerformed(ActionEvent ae){

Object obj = ae.getSource();

if(obj==tf || obj==okBtn){

if(tf.getText() != null){

try{

URL url = new URL(tf.getText());

URLConnection conn = url.openConnection();

conn.connect();

InputStream is = conn.getInputStream();

//////

String contentType = conn.getContentType();

int idx = contentType.indexOf("charset=");

String unicode = contentType.substring(idx+8);

InputStreamReader isr = new InputStreamReader(is, unicode);

BufferedReader br = new BufferedReader(isr);

ta.setText("");

while(true){

String str = br.readLine();

if(str==null) break;

ta.append(str+"\n");

}

}catch(Exception e){

System.out.println(e.getMessage());

}

}

}

}

public static void main(String[] args) {

new SourceView();


}


}



'응용 SoftWare > JAVA' 카테고리의 다른 글

Chat  (0) 2016.12.28
SocketTest  (0) 2016.12.28
URL Test  (0) 2016.12.23
InetAddress Test  (0) 2016.12.23
Text Edit  (0) 2016.12.23
Posted by Hyun CHO
,

URL Test

응용 SoftWare/JAVA 2016. 12. 23. 17:35

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.URL;

import java.net.URLConnection;


public class URLTest {


public URLTest() {

try{

URL url = new URL("http://www.daum.net/index.html");

URLConnection conn = url.openConnection(); //server와 연결

conn.connect(); //총신채널 확보

InputStream is = conn.getInputStream();

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader(isr);

while(true){

String str = br.readLine();

if(str==null){

break;

}

System.out.println(str);

}

}catch(Exception e){

System.out.println(e.getMessage());

}

}


public static void main(String[] args) {

new URLTest();

}


}



'응용 SoftWare > JAVA' 카테고리의 다른 글

SocketTest  (0) 2016.12.28
[예제] Source View  (0) 2016.12.23
InetAddress Test  (0) 2016.12.23
Text Edit  (0) 2016.12.23
Thread Test 2  (0) 2016.12.23
Posted by Hyun CHO
,

import java.net.InetAddress;


public class InetAddressTest {


public InetAddressTest() {

try{

//내컴퓨터의 객체 생성

InetAddress ia1 = InetAddress.getLocalHost();

System.out.println("ia1(address) = "+ia1.getHostAddress());

System.out.println("ia1(name) = "+ia1.getHostName());

//

InetAddress ia2 = InetAddress.getByName("www.bycho.kr");

System.out.println("ia2(address) = "+ia2.getHostAddress());

System.out.println("ia2(name) = "+ia2.getHostName());

InetAddress ia3 = InetAddress.getByName("175.126.170.70");

System.out.println("ia3(address); = "+ia3.getHostAddress());

System.out.println("ia3(name); = "+ia3.getHostName());

InetAddress ia4[] = InetAddress.getAllByName("www.naver.com");

for(InetAddress ia:ia4){

System.out.println("ia4 = "+ia.getHostAddress());

}

}catch(Exception e){}

}


public static void main(String[] args) {

new InetAddressTest();


}


}



'응용 SoftWare > JAVA' 카테고리의 다른 글

[예제] Source View  (0) 2016.12.23
URL Test  (0) 2016.12.23
Text Edit  (0) 2016.12.23
Thread Test 2  (0) 2016.12.23
Thread Test 1  (0) 2016.12.23
Posted by Hyun CHO
,