2016년 7월 7일 목요일

15day java

1
--프로시저 입력과 리턴값이 있는 경우
create or replace procedure callable3 (
 v_empno  in emp.empno%type,
 v_ename  out emp.ename%type,
 v_sal  out emp2.sal%type
)
is

begin
 select ename,sal
 into v_ename, v_sal
 from emp
 where empno=v_empno;

end;
/

--프로시저 확인
SQL> @c:\oracle\callable3
SQL> var g_ename varchar2(10)
SQL> var g_sal number
SQL> exec callable3(7788, :g_ename, :g_sal)
SQL> print :g_ename :g_sal

//자바에서 프로시저 실행 CallableStatement
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import oracle.jdbc.internal.OracleTypes;

public class jdbcEx12 {

 public static void main(String[] args) {
  String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
  String user = "scott";
  String password = "tiger";
  
  Connection conn = null;
  CallableStatement cstmt = null; //프로시저를 실행하기위함
  
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   System.out.println("데이터베이스 로딩 성공");
   
   conn = DriverManager.getConnection(url, user, password);
   System.out.println("데이터베이스 연결 성공");
   
   cstmt = conn.prepareCall("call callable3(?,?,?)");
   
   cstmt.setString(1, "7788");  //입력값을 넣음
   cstmt.registerOutParameter(2, OracleTypes.VARCHAR);
   cstmt.registerOutParameter(3, OracleTypes.VARCHAR);
   
   cstmt.executeUpdate();
   
   String ename = cstmt.getString(2); //출력값을 받음
   String sal = cstmt.getString(3);
   
   System.out.println(ename);
   System.out.println(sal);
   
   System.out.println("SQL 실행성공");
   
  } catch (ClassNotFoundException e) {
   System.out.println("[에러] : "+e.getMessage());
  } catch (SQLException e) {
   System.out.println("[에러] : "+e.getMessage());
  } finally {
   if(conn != null) try { conn.close(); } catch(SQLException e){}
   if(cstmt != null) try { cstmt.close(); } catch(SQLException e){}
  }
 }

}


2
--사원명을 입력받아서 사원번호, 사원급여, 부서번호, 호봉을 출력하는 프로그램을 프로시저를 사용해서 만듦
create or replace procedure callable4 (
 v_ename  in emp.ename%type,
 v_empno  out emp.empno%type,
 v_sal  out emp.sal%type,
 v_deptno out emp.deptno%type,
 v_grade  out salgrade.grade%type
)
is

begin
 select e.empno,e.sal,e.deptno,s.grade
 into v_empno, v_sal, v_deptno, v_grade
 from emp e
 join salgrade s
 on e.sal between s.losal and s.hisal
 where e.ename=v_ename;

end;
/

--sqlplus 프로시저 확인
SQL> @c:\oracle\callable4
SQL> var v_empno number
SQL> var v_sal number
SQL> var v_deptno number
SQL> var v_grade number
SQL> exec callable4('SCOTT',:v_empno, :v_sal, :v_deptno, :v_grade)
SQL> print :v_empno :v_sal :v_deptno :v_grade

//자바에서 프로시저 실행
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import oracle.jdbc.internal.OracleTypes;

public class jdbcEx13 {

 public static void main(String[] args) {
  String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
  String user = "scott";
  String password = "tiger";
  
  Connection conn = null;
  CallableStatement cstmt = null; //프로시저를 실행하기위함
  
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   System.out.println("데이터베이스 로딩 성공");
   
   conn = DriverManager.getConnection(url, user, password);
   System.out.println("데이터베이스 연결 성공");
   
   cstmt = conn.prepareCall("call callable4(?,?,?,?,?)");
   
   cstmt.setString(1, "SCOTT");
   cstmt.registerOutParameter(2, OracleTypes.VARCHAR);
   cstmt.registerOutParameter(3, OracleTypes.VARCHAR);
   cstmt.registerOutParameter(4, OracleTypes.VARCHAR);
   cstmt.registerOutParameter(5, OracleTypes.VARCHAR);
   
   cstmt.executeUpdate();
   
   String empno = cstmt.getString(2);
   String sal = cstmt.getString(3);
   String deptno = cstmt.getString(4);
   String grade = cstmt.getString(5);
   
   System.out.println(empno);
   System.out.println(sal);
   System.out.println(deptno);
   System.out.println(grade);
   
   System.out.println("SQL 실행성공");
   
  } catch (ClassNotFoundException e) {
   System.out.println("[에러] : "+e.getMessage());
  } catch (SQLException e) {
   System.out.println("[에러] : "+e.getMessage());
  } finally {
   if(conn != null) try { conn.close(); } catch(SQLException e){}
   if(cstmt != null) try { cstmt.close(); } catch(SQLException e){}
  }
 }

}


3
--프로시저 결과값이 여러 행일 경우 커서에 담아서 출력
create or replace procedure callable5 (
 v_result out sys_refcursor
)
is

begin
 open v_result for
  select * from dept;

end;
/

--sqlplus 프로시저 확인
SQL> @c:\oracle\callable5
SQL> var g_rc refcursor
SQL> exec callable5(:g_rc)
SQL> print :g_rc

//자바에서 프로시저 값을 커서로 출력함
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.jdbc.internal.OracleCallableStatement;
import oracle.jdbc.internal.OracleTypes;

public class jdbcEx14 {

 public static void main(String[] args) {
  String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
  String user = "scott";
  String password = "tiger";
  
  Connection conn = null;
  CallableStatement cstmt = null; //프로시저를 실행하기위함
  OracleCallableStatement ocstmt = null;
  ResultSet rs = null; //데이터를 가져오기 위함
  
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   System.out.println("데이터베이스 로딩 성공");
   
   conn = DriverManager.getConnection(url, user, password);
   System.out.println("데이터베이스 연결 성공");
   
   cstmt = conn.prepareCall("call callable5(?)");
   cstmt.registerOutParameter(1, OracleTypes.CURSOR);
   
   cstmt.executeUpdate();
   
   ocstmt = (OracleCallableStatement)cstmt;
   rs = ocstmt.getCursor(1);
   
   while(rs.next()){
    System.out.println(rs.getString("deptno"));
    System.out.println(rs.getString("dname"));
    System.out.println(rs.getString("loc"));
   }

   System.out.println("SQL 실행성공");
   
  } catch (ClassNotFoundException e) {
   System.out.println("[에러] : "+e.getMessage());
  } catch (SQLException e) {
   System.out.println("[에러] : "+e.getMessage());
  } finally {
   if(ocstmt != null) try { ocstmt.close(); } catch(SQLException e){}
   if(rs != null) try { rs.close(); } catch(SQLException e){}
   if(conn != null) try { conn.close(); } catch(SQLException e){}
   if(cstmt != null) try { cstmt.close(); } catch(SQLException e){}
  }
 }

}


4
--출력결과가 여러행일 경우 커서로 받는 프로시저 입력값 추가
create or replace procedure callable6 (
 v_deptno  in emp.deptno%type,
 v_result out sys_refcursor
)
is

begin
 open v_result for
  select *
  from emp
  where deptno = v_deptno;

end;
/


SQL> @c:\oracle\callable6
SQL> var g_rc refcursor
SQL> exec callable6(10, :g_rc)
SQL> print :g_rc


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.jdbc.internal.OracleCallableStatement;
import oracle.jdbc.internal.OracleTypes;

public class jdbcEx15 {

 public static void main(String[] args) {
  String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
  String user = "scott";
  String password = "tiger";
  
  Connection conn = null;
  CallableStatement cstmt = null; //프로시저를 실행하기위함
  OracleCallableStatement ocstmt = null;
  ResultSet rs = null; //데이터를 가져오기 위함
  
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   System.out.println("데이터베이스 로딩 성공");
   
   conn = DriverManager.getConnection(url, user, password);
   System.out.println("데이터베이스 연결 성공");
   
   cstmt = conn.prepareCall("call callable6(?,?)");
   
   cstmt.setString(1, "10");
   cstmt.registerOutParameter(2, OracleTypes.CURSOR);
   
   cstmt.executeUpdate();
   
   ocstmt = (OracleCallableStatement)cstmt;
   rs = ocstmt.getCursor(2);
   
   while(rs.next()){
    System.out.println(rs.getString("empno"));
    System.out.println(rs.getString("ename"));
    System.out.println(rs.getString("sal"));
   }

   System.out.println("SQL 실행성공");
   
  } catch (ClassNotFoundException e) {
   System.out.println("[에러] : "+e.getMessage());
  } catch (SQLException e) {
   System.out.println("[에러] : "+e.getMessage());
  } finally {
   if(ocstmt != null) try { ocstmt.close(); } catch(SQLException e){}
   if(rs != null) try { rs.close(); } catch(SQLException e){}
   if(conn != null) try { conn.close(); } catch(SQLException e){}
   if(cstmt != null) try { cstmt.close(); } catch(SQLException e){}
  }
 }

}


5
--외부에서 sql자체를 받아드림
create or replace procedure callable7 (
 v_sql  in varchar2,
 v_result out sys_refcursor
)
is

begin
 open v_result for v_sql;

end;
/

--select 문장없이 프로시저 실행됨
SQL> @c:\oracle\callable7
SQL> exec callable7('select * from emp where deptno=10', :g_rc)
--select 문을 프로시저 안에 써줌
SQL> print :g_rc


6
//자바에서 동이름을 입력받고 데이터베이스 테이블로 바로 접속해서 주소정보 가져오기
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

import oracle.jdbc.internal.OracleCallableStatement;
import oracle.jdbc.internal.OracleTypes;

public class zipSearch {

 public static void main(String[] args) {
  //동이름 입력받기
  Scanner scan = new Scanner(System.in);
  System.out.println("동이름 입력: ");
  String dong = scan.next();
  scan.close();
  
  //데이터베이스 접속하기
  String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
  String user = "scott";
  String password = "tiger";
  
  Connection conn = null;
  PreparedStatement pstmt = null;
  ResultSet rs = null; //데이터를 가져오기 위함
  
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   System.out.println("데이터베이스 로딩 성공");
   
   conn = DriverManager.getConnection(url, user, password);
   System.out.println("데이터베이스 연결 성공");
   //sql문 준비하기
   String sql = "select * from zipcode where dong like ?";
   pstmt = conn.prepareStatement(sql);
   pstmt.setString(1, dong+"%");
   
   //여러행을 입력받아야 함으로 ResultSet 실행하기   
   rs = pstmt.executeQuery();
   while(rs.next()){
    System.out.print("["+rs.getString("zipcode")+"]\t");
    System.out.print(rs.getString("sido")+"\t");
    System.out.print(rs.getString("dong")+"\t");
    System.out.print(rs.getString("ri")==null?"":rs.getString("ri")+"\t");
    System.out.print(rs.getString("bunji")==null?"":rs.getString("bunji")+"\t");
    System.out.println(rs.getString("seq"));
   }

   System.out.println("SQL 실행성공");
   
  } catch (ClassNotFoundException e) {
   System.out.println("[에러] : "+e.getMessage());
  } catch (SQLException e) {
   System.out.println("[에러] : "+e.getMessage());
  } finally {
   if(rs != null) try { rs.close(); } catch(SQLException e){}
   if(conn != null) try { conn.close(); } catch(SQLException e){}
   if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
  }
 }

}


7
--동이름 입력받아 zipcode검색 프로시저
create or replace procedure zipsearchcall (
 v_dong  in varchar2,
 v_result out sys_refcursor
)
is
 --v_dong2 zipcode.dong%type
begin
 --v_dong2 := v_dong || '%';  --%처리를 프로시저에서 해도 되고 자바에서 해도 됨
 open v_result for
  select *
  from zipcode
  where dong like v_dong;

end;
/

--sqlplus 프로시저 실행확인
SQL> @c:\oracle\zipSearchCall
SQL> var g_rc refcursor
SQL> exec ZipSearchCall('개포4%', :g_rc)
SQL> print :g_rc

//자바에서 동이름 입력받고 데이터베이스 프로시저를 통해서 주소 가져오기
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

import oracle.jdbc.internal.OracleCallableStatement;
import oracle.jdbc.internal.OracleTypes;

public class zipSearchCallable {

 public static void main(String[] args) {
  //동이름 입력받기
  Scanner scan = new Scanner(System.in);
  System.out.println("동이름 입력: ");
  String dong = scan.next();
  scan.close();
  
  //데이터베이스 접속하기
  String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
  String user = "scott";
  String password = "tiger";
  
  Connection conn = null;
  CallableStatement cstmt = null; //프로시저를 실행하기위함
  OracleCallableStatement ocstmt = null;
  ResultSet rs = null; //데이터를 가져오기 위함
  
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   System.out.println("데이터베이스 로딩 성공");
   
   conn = DriverManager.getConnection(url, user, password);
   System.out.println("데이터베이스 연결 성공");
   //sql문 준비하기
   cstmt = conn.prepareCall("call ZipSearchCall(?,?)");
   cstmt.setString(1, dong+"%");
   cstmt.registerOutParameter(2, OracleTypes.CURSOR);
   
   //여러행을 입력받아야 함으로 CallableStatement, ResultSet 실행하기   
   cstmt.executeUpdate();
   ocstmt = (OracleCallableStatement)cstmt;
   rs = ocstmt.getCursor(2);
   
   while(rs.next()){
    System.out.print("["+rs.getString("zipcode")+"]\t");
    System.out.print(rs.getString("sido")+"\t");
    System.out.print(rs.getString("dong")+"\t");
    System.out.print(rs.getString("ri")==null?"":rs.getString("ri")+"\t"); //null일 경우 공백
    System.out.print(rs.getString("bunji")==null?"":rs.getString("bunji")+"\t");
    System.out.println(rs.getString("seq"));
   }

   System.out.println("SQL 실행성공");
   
  } catch (ClassNotFoundException e) {
   System.out.println("[에러] : "+e.getMessage());
  } catch (SQLException e) {
   System.out.println("[에러] : "+e.getMessage());
  } finally {
   if(rs != null) try { rs.close(); } catch(SQLException e){}
   if(conn != null) try { conn.close(); } catch(SQLException e){}
   if(cstmt != null) try { cstmt.close(); } catch(SQLException e){}
   if(ocstmt != null) try { ocstmt.close(); } catch(SQLException e){}
  }
 }

}


8
import java.net.InetAddress;
import java.net.UnknownHostException;

public class NetWorkEx01 {

 public static void main(String[] args) {
  // 자바 네트워크 Inet
  try {
   InetAddress address = InetAddress.getByName("www.google.co.kr");
   System.out.println(address.getHostName());
   System.out.println(address.getHostAddress());  //구글의 아이피 주소 가져오기
   
   InetAddress[] addresses = InetAddress.getAllByName("www.naver.com"); //아이피 주소가 여러개일 수 있음
   for(InetAddress address1 : addresses){
    System.out.println(address1.getHostName());
    System.out.println(address1.getHostAddress());
   }
  } catch (UnknownHostException e) {
   // 잘못된 주소일 경우 처리
   e.printStackTrace();
  }
 }

}


9
import java.net.MalformedURLException;
import java.net.URL;

public class NetWorkEx02 {

 public static void main(String[] args) {
  // URL을 분석해서 내용 보여줌
  try {
   URL url = new URL("http://www.naver.com:80/index.html");
   //URL문장을 의미있는 단위로 나눠서 보여줌
   System.out.println(url.getDefaultPort());
   System.out.println(url.getPort());
   System.out.println(url.getFile());
   System.out.println(url.getHost());
   System.out.println(url.getPath());
   System.out.println(url.getProtocol());
   System.out.println(url.getQuery());
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

}


10
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class NetWorkEx03 {

 public static void main(String[] args) {
  // URL 연결하고 BufferedReader로 페이지 HTML문서 읽기
  BufferedReader br = null;
  try {
   URL url = new URL("http://m.naver.com:80/index.html");
   
   br = new BufferedReader(new InputStreamReader(url.openStream()));
   String line = "";
   while((line = br.readLine()) != null){
    System.out.println(line);
   }
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   if(br != null) try{ br.close();} catch(IOException e){}
  }
 }

}


11. 데이터를 제공해주는 사이트

  • OPEN API
    • 구글 - 맵데이터
      • 개발자 센터
      • developer.google.com
        • 지역명 입력→ 위도, 경도 , 주소
    • 공공데이터 포털
      • data.go.kr
    • 형태
      • XML
        • ex)https://developers.google.com/maps/documentation/geocoding/intro
        • https://maps.googleapis.com/maps/api/geocode/xml?address=서울시청
      • JSON
      • 라이브러리
    • MASHUP 사이트
      • API를 이용해서 부가가치가 있는 서비스를 만듦


12
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class NetWorkEx03 {

 public static void main(String[] args) {
  // OPEN API에 데이터를 받아오기
  BufferedReader br = null;
  try {
   //%EA%B0%95%EB%82%A8%EC%97%AD : 크롬에서는 강남역 자동인코딩 시켜줌
   URL url = new URL("https://maps.googleapis.com/maps/api/geocode/xml?address=강남역"); //xml은 HTML 태그로 표현 //json은 자바 객체 표현
   
   br = new BufferedReader(new InputStreamReader(url.openStream()));
   String line = "";
   while((line = br.readLine()) != null){
    System.out.println(line);
   }
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   if(br != null) try{ br.close();} catch(IOException e){}
  }
 }

}


13
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;

public class NetWorkEx04 {

 public static void main(String[] args) {
  // 이미지 소스복사후 정보 가져오기
  try {
   URL url = new URL("http://img.naver.net/static/newsstand/up/2014/0715/326.gif");
   URLConnection conn = url.openConnection();
   System.out.println(conn.getContentType());  //이미지 타입
   System.out.println(new Date(conn.getLastModified()).toLocaleString());  //마지막 수정일
   System.out.println(conn.getContentLength());
   System.out.println(conn.getContentEncoding());
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

}


14
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;

public class NetWorkEx05 {

 public static void main(String[] args) {
  // 이미지 소스로 이미지 저장  //다른이름으로 사진저장과 똑같은 기능 만들기
  BufferedInputStream bis = null;
  BufferedOutputStream bos = null;
  try {
   URL url = new URL("http://img.naver.net/static/newsstand/up/2014/0715/326.gif");
   URLConnection conn = url.openConnection();
   
   bis = new BufferedInputStream(conn.getInputStream());
   bos = new BufferedOutputStream(new FileOutputStream("c:/java/020.gif"));
   
   int data =0;
   while((data = bis.read())!=-1){
    bos.write(data);
   }
   System.out.println("전송이 완료되었습니다");
   
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   if(bis != null) try{ bis.close();} catch(IOException e){}
   if(bos != null) try{ bos.close();} catch(IOException e){}
  }
 }

}


15
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class MapSearch extends JFrame {

 private JPanel contentPane;
 private JTextField textField;
 private JTextField textField_1;
 private JTextField textField_2;
 private JTextField textField_3;
 private JLabel label;
 private JLabel label_1;
 private JLabel label_2;

 /**
  * Launch the application.
  */
 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   public void run() {
    try {
     MapSearch frame = new MapSearch();
     frame.setVisible(true);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  });
 }

 /**
  * Create the frame.
  */
 
 String juso = null;
 String lat = null;
 String lng = null;
 
 public MapSearch() {
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setBounds(100, 100, 470, 262);
  contentPane = new JPanel();
  contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  setContentPane(contentPane);
  contentPane.setLayout(null);
  
  textField = new JTextField();
  textField.setBounds(12, 10, 216, 21);
  contentPane.add(textField);
  textField.setColumns(10);
  
  JButton btnNewButton = new JButton("검색");
  btnNewButton.addMouseListener(new MouseAdapter() {
   @Override
   public void mouseClicked(MouseEvent arg0) {
    //텍스트에서 검색어 가져오기
    String el = textField.getText();
    BufferedReader br = null;
    
    try {
     //검색어로 URL검색후 HTML문서 가져오기  //한글주소로 가져오기위해 +"&language=ko"
     URL url = new URL("https://maps.googleapis.com/maps/api/geocode/xml?address="+el+"&language=ko");
     
     br = new BufferedReader(new InputStreamReader(url.openStream()));
     String line = "";
     while((line = br.readLine()) != null){
      if (line.indexOf("") != -1){ //주소 라인 읽기
       juso = line.replaceAll("","").replaceAll("", "").trim();
      }else if(line.indexOf("") != -1){//위도 라인 읽기
       lat = line.replaceAll("","").replaceAll("", "").trim();
      }else if(line.indexOf("") != -1){//경도 라인 읽기
       lng = line.replaceAll("","").replaceAll("", "").trim();
      }
     }
    } catch (MalformedURLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    } finally {
     if(br != null) try{ br.close();} catch(IOException e){}
    }
    //주소, 위도, 경도 텍스트 적기
    textField_1.setText(juso);
    textField_2.setText(lat);
    textField_3.setText(lng);
   }
  });
  btnNewButton.setBounds(240, 9, 97, 23);
  contentPane.add(btnNewButton);
  
  JButton btnNewButton_1 = new JButton("지도 보기");
  btnNewButton_1.addMouseListener(new MouseAdapter() {
   @Override
   public void mouseClicked(MouseEvent e) {
    try {
     //위도,경도 가져와서 지도 URL 만들기
     String url = String.format("https://www.google.co.kr/maps/@%s,%s,15z", lat, lng);
     //ProcessBuilder로 익스플로러 창 켜기
     new ProcessBuilder("C:/Program Files/Internet Explorer/iexplore.exe", url).start();
    } catch (IOException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    }
   }
  });
  btnNewButton_1.setBounds(349, 9, 97, 23);
  contentPane.add(btnNewButton_1);
  
  textField_1 = new JTextField();
  textField_1.setBounds(12, 71, 430, 21);
  contentPane.add(textField_1);
  textField_1.setColumns(10);
  
  textField_2 = new JTextField();
  textField_2.setColumns(10);
  textField_2.setBounds(12, 129, 430, 21);
  contentPane.add(textField_2);
  
  textField_3 = new JTextField();
  textField_3.setColumns(10);
  textField_3.setBounds(12, 187, 430, 21);
  contentPane.add(textField_3);
  
  label = new JLabel("주소");
  label.setBounds(12, 46, 57, 23);
  contentPane.add(label);
  
  label_1 = new JLabel("위도");
  label_1.setBounds(12, 102, 57, 23);
  contentPane.add(label_1);
  
  label_2 = new JLabel("경도");
  label_2.setBounds(12, 160, 57, 23);
  contentPane.add(label_2);
 }
}


댓글 없음:

댓글 쓰기