출처 : http://blog.naver.com/tyboss/70097410517
Java SE Autodownload Files
http://www.oracle.com/technetwork/java/javase/autodownload-140472.html
Applet 을 만들 때 package를 적용하고 싶으면 java 프로젝트를 별도로 만들어 jar로 배포를 하고 class 파일 단위로 처리할 경우에는 pacakge 없이 컴파일을 해야 한다.
Applet을 refresh 하고 싶다면 새로고침 시 나오는 java 보안 경고 창에서 실행/취소 중 취소를 클릭하고 Applet 표시 부분에 마우스 우클릭 Reload Applet 클릭하면 됨. Java 콘솔도 우클릭 메뉴에 있음.
1. Applet 만들기
package com.maruara.applet;
import java.applet.Applet; import java.awt.TextField; import java.util.Date;
import netscape.javascript.JSObject;
public class TestApplet extends Applet implements Runnable {
/** * */ private static final long serialVersionUID = -176201962325630072L; JSObject window; Thread clockThread; Date date; boolean running = true; TextField tf = new TextField(30);
public void init() { window = JSObject.getWindow(this); clockThread= new Thread(this); clockThread.start(); add(tf);
/* JSObject window = JSObject.getWindow(this); JSObject document = (JSObject)window.getMember("document"); JSObject location = (JSObject)document.getMember("location"); String s = (String)location.getMember("href"); window.call("doAlert", null); */ } public void doStart(String msg) { System.out.println(msg); tf.setText(msg); running = true; clockThread= new Thread(this); clockThread.start(); } public void doStop(String msg) { System.out.println(msg); tf.setText(msg); running = false; clockThread = null; } public void run() { // loop until told to stop while (running) { date = new Date(); window.call("view", new Object[] {date}); try { // Wait 500milliseconds before continuing clockThread.sleep(1000); } catch (InterruptedException e) { System.out.println(e); } // he has wait and will now restart his actions. } } public void destroy() { // will cause thread to stop looping running = false; // destroy it. clockThread = null; } } |
2. Applet Jar로 묶어서 Web 서버에 올리기
jar 묶을 때 src class folder만 체크한 후 export 한다.
이미지처럼 웹에서 접근할 수 있는 경로로 이동한다.
3. HTML 적용
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Insert title here</title>
</head> <body>
<%-- <object id="myApplet" name="myApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" archive="${pageContext.request.contextPath }/myApplet.jar" width="200" height="200" codebase="http://java.sun.com/update/1.7.0/jinstall-7u17-windows-i586.cab"> --%> <%-- <param name="archive" value="${pageContext.request.contextPath }/myApplet.jar" /> --%> <!-- <param name="code" value="com.maruara.applet.TestApplet.class" /> --> <!-- <param name="codebase" value="." /> --> <!-- <param name="type" value="application/x-java-applet;version=1.6" /> --> <!-- No JDK 1.3 support for APPLET!! --> <!-- </object> -->
<!-- <embed id="testapplet" --> <!-- type="application/x-java-applet;version=1.7" --> <!-- width="256" height="256" --> <%-- archive="${pageContext.request.contextPath }/myApplet.jar" --%> <!-- code="com.maruara.applet.TestApplet.class" --> <!-- pluginspage="http://java.com/download/" /> -->
<object id="myApplet" name="myApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" archive="${pageContext.request.contextPath }/myApplet.jar" width="200" height="200" codebase="http://java.sun.com/update/1.7.0/jinstall-7u17-windows-i586.cab"> <param name="archive" value="${pageContext.request.contextPath }/myApplet.jar" /> <param name="code" value="com.maruara.applet.TestApplet.class" /> <param name="codebase" value="." /> <param name="type" value="application/x-java-applet;version=1.6" /> <comment> <embed id="myApplet" type="application/x-java-applet;version=1.7" width="256" height="256" archive="${pageContext.request.contextPath }/myApplet.jar" code="com.maruara.applet.TestApplet.class" pluginspage="http://java.com/download/" /> </comment> </object>
<div id="view"></div> <button type="button" id="btnStart">시작</button> <button type="button" id="btnStop">정지</button>
<script> function view(time) { $('#view').text(time); }
$('#btnStart').on('click', function() { $('#myApplet').get(0).doStart('stop'); });
$('#btnStop').on('click', function() { document.getElementById('myApplet').doStop('stop'); }); </script>
</body> </html> |
<script language="Javascript">
var _app = navigator.appName;
if (_app == 'Netscape') { document.write('<embed code="Applet1.class"', 'width="200"', 'height="200"', 'type="application/x-java-applet;version=1.5.0">'); } else if (_app == 'Microsoft Internet Explorer') { document.write('<OBJECT ', 'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"', 'width="200"', 'height="200">', '<PARAM name="code" value="Applet1.class">', '</OBJECT>'); } else { document.write('<p>Sorry, unsupported browser.</p>'); }
</script> |