메뉴 건너뛰기

조회 수 7751 추천 수 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 함수를 호출하는 구조이다.


List of Articles
번호 제목 날짜 조회 수
157 노티피케이션(Notification) 사용법 / Notification.Builder , NotificationManager file 2016.06.10 13467
156 어댑터 뷰(Adapter View) & 어댑터(Adapter) (1) file 2016.06.08 7852
155 Activity Data Transfor/ 액티비티 이동간에 데이터 전송하기 file 2016.06.07 7676
154 Activity Switching / 안드로이드 액티비티 전환 / 화면 전환 file 2016.06.07 8311
153 알아놓으면 좋은 내용정리 2016.06.07 7458
152 간단한 mp3 플레이어 만들기 , 음악넣기 , 노래재생 file 2016.06.07 14619
151 암시적 인텐트를 사용한 인터넷열기, 전화걸기, 문자보내기 [Intent (인텐트)] file 2016.06.07 7736
150 Intent (인텐트) 2016.06.07 7626
149 Android 와 JSP 간 파라미터 암복호화 (3) file 2016.05.26 8088
148 Android 와 JSP 간 파라미터 암복호화 (2) 2016.05.26 7735
147 Android 와 JSP 간 파라미터 암복호화 (1) file 2016.05.26 7474
146 카카오톡 대화내용 가져오기(sqlite3, chat_logs) file 2016.05.26 15087
145 카카오톡 분석하기 (2) - 카카오톡 암호화 함수 찾기 file 2016.05.26 9598
144 카카오톡 분석하기 (1) - sqlite 파해치기 file 2016.05.26 10060
143 안드로이드용 채팅프로그램 클라이언트(java), 서버(c#) 소스 file 2016.05.19 11720
142 네트워크 연결 상태 및 3G/WIFI 연결상태 체크하기 2016.03.18 7131
141 Android Push GCM 프로젝트 앱 적용 하기(2) file 2016.03.18 8945
140 안드로이드] 페이스북 같은 슬라이드 메뉴 만들기 file 2015.12.15 12534
139 Android TIP] strings.xml 에서 특수문자 사용하기 2015.12.15 6629
138 Android] Fragment 내부의adapter에서 startActivity 하기 2015.12.15 6487
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved