J2ME Programming
Java2 Micro edition Introduction 년 5 월 26 일 CLDC, MIDP 라이브러리 Reference : Reference : 두 Reference 싸이트에서 CLDC 와 MIDP 에 대 한 정보를 얻을 수 있고, 실행파일을 다운 로드 CLDC 는 바이너리 파일, APIs, KVM Source 파 일, API 소스 파일 MIDP 는 바이너리 파일과 APIs
Java2 Micro edition Introduction 년 5 월 26 일 CLDC, MIDP 라이브러리 KVM Source 파일을 이용하여 자신만의 실 행환경을 다시 생성가능 Visual C++ 의 C1 컴파일을 사용하여 컴파 일 컴파일할 때 API 들도 같이 컴파일 zip.exe 파일이 필요
Java2 Micro edition Introduction 년 5 월 26 일 CLDC Directory Java API Native
Java2 Micro edition Introduction 년 5 월 26 일 MIDP Directory
Java2 Micro edition Introduction 년 5 월 26 일 api Contains the Java library class source code that is provided with the release. bin Contains all the binary executables and compiled Java library classes. build Contains makefiles for building the KVM. doc Contains documentation. jam Contains the source code of the optional Java Application Manager (JAM) component that is provided with the KVM. Distribution directories
Java2 Micro edition Introduction 년 5 월 26 일 Directory kvm/VmCommon StartJVM.c Virtual machine startup and command line argument reading. cache.c Inline caching operations for speeding up method lookup. class.c Runtime data structures and operations for representing Java classes. events.c Implementation of a stream-based protocol for event handling. fields.c Runtime data structures and operations for representing fields of objects. frame.c Stack frame and exception handling operations. ETC…
Java2 Micro edition Introduction 년 5 월 26 일 Java code: static native void drawRectangle(int x, int y, int width, int height); Native implementation: C code static void Java_com_sun_kjava_Graphics_drawRectangle() { int height = popStack(); int width = popStack(); int y = popStack(); int x = popStack(); windowSystemDrawRectangle(x, y, width, height); } Example Accessing arguments from native methods
Java2 Micro edition Introduction 년 5 월 26 일 const NativeImplementationType [com_sun_midp_lcdui_DefaultDeviceCaps_natives] = { { "drawLine", Java_com_sun_midp_lcdui_DefaultDeviceCaps_drawLine}, { "drawRect", Java_com_sun_midp_lcdui_DefaultDeviceCaps_drawRect}, { "drawArc", Java_com_sun_midp_lcdui_DefaultDeviceCaps_drawArc}, { "drawChar", Java_com_sun_midp_lcdui_DefaultDeviceCaps_drawChar}, { "drawChars", Java_com_sun_midp_lcdui_DefaultDeviceCaps_drawChars}, { "drawString", Java_com_sun_midp_lcdui_DefaultDeviceCaps_drawString}, { "drawImage", Java_com_sun_midp_lcdui_DefaultDeviceCaps_drawImage}, } Example Accessing arguments from native methods
Java2 Micro edition Introduction 년 5 월 26 일 Kauai VM Architecture Class loader Sub system Runtime data areas Class files Native method interface Native method libraries, Code Execution engine >javac HelloWorld.java HelloWorld.class JNI
Java2 Micro edition Introduction 년 5 월 26 일 Where is target?
Java2 Micro edition Introduction 년 5 월 26 일 J2ME for Wireless Carriers Software Architecture
Java2 Micro edition Introduction 년 5 월 26 일 MIDlet 개발단계 Step 1: 코딩 Step 2: 컴파일 및 사전 검증 Step 3: Manifest 파일 작성 Step 4: 패키징 및 jad 생성 Step 5: 테스트
Java2 Micro edition Introduction 년 5 월 26 일 Hello World import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class HelloWorld extends MIDlet { private Display display; private TextBox mainScreen=null; public HelloWorld() { display=Display.getDisplay(this); mainScreen=new TextBox("TEXT BOX","Hello World",512,0); }
Java2 Micro edition Introduction 년 5 월 26 일 Hello World public void startApp() { display.setCurrent(mainScreen); } public void pauseApp() { } public void destroyApp(boolean unconditional) { }
Java2 Micro edition Introduction 년 5 월 26 일 ScreenText import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ScreenText extends MIDlet{ private Display display; private Form s1; private Form s2; public ScreenText(){ s1=new Form("Screen1"); s2=new Form("Screen2"); Ticker t=new Ticker("This is a test for switching screen."+"Screen 1 and 2 are switched every 5 seconds."); s1.setTicker(t); s2.setTicker(t); }
Java2 Micro edition Introduction 년 5 월 26 일 ScreenText public void startApp() throws MIDletStateChangeException{ display=Display.getDisplay(this); display.setCurrent(s1); new Thread(new ScreenTestRun()).start(); } public void pauseApp() {} public void destroyApp(boolean unconditional){ display=null; s1=null; s2=null; }
Java2 Micro edition Introduction 년 5 월 26 일 ScreenText class ScreenTestRun implements Runnable{ public void run(){ while(true){ try{ Thread.sleep(5000); if(display.getCurrent()==s1){ display.setCurrent(s2); } else{ display.setCurrent(s1); } catch(Exception e){} }
Java2 Micro edition Introduction 년 5 월 26 일 J2ME Wireless Toolkit J2ME MIDlet 의 개발을 지원하는 프로그램 과 API set urce/j2me/download.html 에서 다운로드 가 능 urce/j2me/download.html 설치된 디렉토리를 환경변수 J2ME 로 설정 해 준다.
Java2 Micro edition Introduction 년 5 월 26 일 컴파일 JDK 의 common Java Compiler 사용 javac -g:none -bootclasspath %J2ME%\lib\midpapi.zip -d. -classpath. 자바파일이름
Java2 Micro edition Introduction 년 5 월 26 일 사전검증 생성된 class 파일이 규격에 맞는가 검증 Class 파일을 약간 축소시킴 preverify -classpath %J2ME%\lib\midpapi.zip;. -d..
Java2 Micro edition Introduction 년 5 월 26 일 Manifest 파일 패키징시 필요한 정보를 저장 MIDlet-1: HelloWorld, /Icon.png, HelloWorld MIDlet-Name: KJava MIDlet-Vendor: Kim Insu MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0
Java2 Micro edition Introduction 년 5 월 26 일 패키징 Java 의 JAR (Java archive) 사용 Manifest 의 정보를 포함하여 각 class, resource 등을 압축 jar cmvf MANIFEST.MF 패키지이름 대상 파일
Java2 Micro edition Introduction 년 5 월 26 일 패키징
Java2 Micro edition Introduction 년 5 월 26 일 JAD (descriptor) 생성 JAR 파일의 내용을 설명 Manifest 파일과 유사한 형태를 가짐
Java2 Micro edition Introduction 년 5 월 26 일 JAD MIDlet-1: HelloWorld, /Icon.png, HelloWorld MIDlet-Jar-Size: 2890 MIDlet-Jar-URL: MIDlet-Name: Kjava MIDlet-Vendor: Kim Insu MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0
Java2 Micro edition Introduction 년 5 월 26 일 테스트 midp 에뮬레이터를 사용한 로컬테스트 midp -classpath JAR 파일명 –descriptor JAD 파일명
Java2 Micro edition Introduction 년 5 월 26 일 테스트 – MIDP (local)
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar MIDlet 의 컴파일, 사전검증, 패키징, 실행등 의 번거로운 작업을 관리 J2ME Wireless Toolkit 에 포함
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar 새로운 프로젝트 생성
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar MIDlet 수트의 필수 어트리뷰트 설정 Manifest, JAD 파일에 사용
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar 선택적 어트리뷰트 설정
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar 수트에 포함될 MIDlet 설정
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar 프로젝트의 ‘src’ 디렉토리에 소스코드 작성
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar ‘build’ 버튼으로 컴파일, 사전검사, 패키징
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar 생성된 JAD, JAR, Manifest 파일
Java2 Micro edition Introduction 년 5 월 26 일 KToolBar ‘run’ 버튼으로 MIDlet 의 실행