메뉴 건너뛰기

조회 수 7754 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

ActiveX를 만들때 javascript에서 ActiveX 객체의 메서드를 호출하고, 그 결과값을 받아오는 것과, ActiveX 객체에서 발생하는 이벤트를 javascript 에서 캡쳐하는 식의 코딩은 아주 많이 사용된다.

 

Java Applet에서 UI를 만들어서 모든 처리를 할 수도 있겠지만, Applet 자체에는 UI가 없이 html 의 UI를 사용해서 Applet에 값을 던져주고 받고 하는 식의 처리를 할 필요가 있다.

 

javascript에서 호출할 Applet 메서드는 간단히 public으로 메서드를 선언해주면 되고, Applet에서 javascript의 메서드를 호출해주는 것은 AppletContext 객체의 showDocument 메서드를 이용하면 된다.

 

1. test.html은 다음과 같이 준비한다. ( applet 태그에 mayscript 를 기입해주는 이유는 애플릿에서 웹페이지의 자바스크립트 객체를 사용할 수 있도록 허용해줌을 의미 )

<html>

<title>애플릿테스트</title>

<head>

<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript">

 function callFunc( param ) {

  $('#callResult_Event').text( s );

}


 $(function() {
  
  $('#btnResult').click(function() {

   $('#callResult_Return').text( document.myApplet.plusData( $('#firstParam').val() , $('#secondParam').val() ) );  
  });

});


</script>

</head>

<body>

<applet code="TestApplet.class" name="appletObject" width=0 height=0 mayscript>

</applet>

<input type="text" id="firstParam"> 연산 <input type="text" id="secondParam">
<input type="button" value="결과" id="btnResult"><br>
리턴결과(더하기) : <div id="callResult_Return"></div><br>
이벤트결과(곱하기) : <div id="callResult_Event"></div>
</body>

</html>

 

2. 이클립스로 Java 프로젝트를 하나 생성하여 Applet으로부터 상속받는 클래스 TestApplet 를 만든다.

 

public class TestApplet extends Applet {

 

public String plusData( String firstParam, String secondParam ) {

Integer result = Integer.parseInt(firstParam) + Integer.parseInt(secondParam);

Integer result2 = Integer.parseInt(firstParam) * Integer.parseInt(secondParam);

 

try {

getAppletContext().showDocument( new URL("javascript:callFunc(\"" + result2.toString() + "\")"));

} catch( MalformedURLException e ) {

// 예외처리

}

 

return result.toString();

}

}

 

3. 컴파일하여 TestApplet.class를 test.html 파일과 동일한 경로에 넣은 후 test.html 파일을 브라우져로 열어보면 결과를 확인할 수가 있다.

 

4. 즉, btnResult 버튼을 클릭하면, TestApplet 객체인 myApplet 객체의 plusData 메서드를 호출하고 그 결과를 String으로 받아서 callResult_Return의 값으로 설정하고,

 

5. plusData 함수 내부에서 AppletContext 객체의 showDocument 메서드를 호출하여 callFunc 이라는 javascript 함수를 호출하는 구조이다.


  1. JSON(JavaScript Object Notation) - jQuery Ajax - jQuery.getJSON() 메서드 (비동기적으로 JSON파일 로드)

    Date2014.10.16 Views6568
    Read More
  2. jQuery ajax post 요청 text 응답

    Date2014.10.16 Views6702
    Read More
  3. jQuery Ajax - jQuery.load() 메서드 (동적으로 원격 페이지 로드)

    Date2014.10.16 Views6417
    Read More
  4. Java에서 XML 불러와서 동적 변화 주기

    Date2021.03.31 Views288
    Read More
  5. JavaScript 맛보기

    Date2014.09.04 Views6589
    Read More
  6. JAVA JDBC를 사용하여 MySQL과 연동

    Date2015.11.21 Views8644
    Read More
  7. Java Applet과 javascript와의 통신

    Date2015.06.29 Views7754
    Read More
  8. Invalid project description 문제

    Date2015.07.01 Views7118
    Read More
  9. Intent (인텐트)

    Date2016.06.07 Views7626
    Read More
  10. ImageVeiw의 현재 리소스 비교하기

    Date2014.08.28 Views6750
    Read More
  11. HTML5로 비디오 보여주기 Video Tag

    Date2014.09.04 Views7062
    Read More
  12. HTML5로 나만의 비디오 플레이어 스킨 만들기 -3- JavaScript

    Date2014.09.04 Views6288
    Read More
  13. HTML5로 나만의 비디오 플레이어 스킨 만들기 -2- JavaScript

    Date2014.09.04 Views6312
    Read More
  14. HTML5로 나만의 비디오 플레이어 스킨 만들기 -1- CSS

    Date2014.09.04 Views6453
    Read More
  15. HTML5로 게임 만들기 워밍업

    Date2014.09.04 Views6063
    Read More
  16. HTML5 시작하기

    Date2014.09.04 Views5660
    Read More
  17. HTML5 드래그 앤 드롭 하기 Drag and Drop

    Date2014.09.04 Views7748
    Read More
  18. HTML5 Web Storage -01-

    Date2014.09.04 Views5587
    Read More
  19. HTML5 Speech Input (음성인식) API

    Date2014.09.04 Views6454
    Read More
  20. HTML5 Geolocation (구글 지도에 현위치 표시하기)

    Date2014.09.04 Views6810
    Read More
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved