Javawebstudio 2005 Development J2me method

Source: Internet
Author: User
Tags file size file url mkdir prepare
The web Javawebstudio 20052005 supports J2ME development, with the WTK2.2 version, which provides 15 J2ME development project templates. The steps to develop mobile gaming via the J2ME template provided by Javawebstudio 2005 are as follows:

(1) Start Javawebstudio



(2) using J2ME template to build new mobile game project

Create a new project from the file-new Project menu.



In the New Project dialog box, select the project type JME application project, the template name Select Implement Menu Template, and the project name is "Jmemenu".




The resulting new project directory structure is as follows:




(3) The main entrance and implementation code of this project are included in the Firstmidlet.java file, which reads as follows:

Package my;

Import javax.microedition.midlet.*;

Import javax.microedition.lcdui.*;



public class Firstmidlet extends MIDlet

{

private display display;



Public Firstmidlet ()

{

display = Display.getdisplay (this);

}



public void startApp ()

{

Form f = new form ("Test");

Command c1=new command ("Back_1", command.back,2);

Command c2=new command ("Back_2", command.back,1);

Command c3=new command ("Back_3", command.back,3);

F.addcommand (C1);

F.addcommand (C2);

F.addcommand (C3);



Display.setcurrent (f);

}



public void Pauseapp ()

{

}



public void Destroyapp (Boolean unconditional)

{

}

}



(4) The project description document Myfirst.jad content as follows:

Midlet-name:helloworld

midlet-version:1.0.0

Midlet-vendor:sun Microsystems, Inc.

Midlet-description:sample Hello World MIDlet

midlet-info-url:http://java.sun.com/j2me/

Midlet-jar-url:the Jar File URL

Midlet-jar-size:the Jar File Size

microedition-profile:midp-1.0

microedition-configuration:cldc-1.0

MIDlet-1: Myfirstmidlt, My. Firstmidlet



In the Myfirst.jad file, one particular note, Midlet-jar-size, describes the size of the Jar wrapper file generated by the project, which is changed after the program is modified. In Javawebstudio, at compile time ant invokes the size of the SetJarSize.exe file in the \javawebstudio\bin directory to extract the project jar file, which is automatically filled in.



(5) In this project, the obfuscation is Retroguard, and the class file is contained in the Retroguard.jar library. In addition, Javawebstudio also provides the source program for the Retroguard obfuscation, which is called "Retroguard template" under the \javawebstudio\bin\ template \JME application project \ Directory.



(6) Compiling, running

The compiled and run configurations are all in the Build.xml file, and compile-time Javawebstudio will be compiled and run through an ant call Build.xml file. The contents of the Build.xml file are as follows:

<?xml version= "1.0" encoding= "GB2312"?>

<project name= "First MIDP program" default= "All" basedir= "." >



<!--introduction of common attributes in Build.properties-->

<property file= "Build.properties"/>



<target name= "Prepare" description= "ready to Work" >

<mkdir dir= "${build.dir}"/>

<mkdir dir= "${build.dir.classes}"/>

<mkdir dir= "${build.dir.obfused}"/>

<mkdir dir= "${build.dir.preverified}"/>

<mkdir dir= "${build.dir.bin}"/>

</target>



<target name= "Cleandir" description= "Clear Catalog" >

<delete dir= "${build.dir}"/>

</target>



<target name= "Compile" description= "compiling source code" depends= "Prepare" >

<javac debug= "Off"

Classpath= "${midp.api0};${midp.api1};${midp.api2};."

Bootclasspath= "${midp.api}"

Srcdir= "${src.dir}"

Destdir= "${build.dir.classes}"

Source= "1.3"

/>

</target>



<target name= "Beforeobfuse" description= "packaged into jars before mixing" depends= "compile" >

<jar basedir= "${build.dir.classes}"

Jarfile= "${build.dir.bin.jarunobfus}"

/>

</target>



<target name= "obfuscate" description= "use obfuscation" depends= "Beforeobfuse" >

<java fork= "yes" classname= "Retroguard" classpath= "${obfuscator.lib};${midp.emptyapi}" >

<arg line= "${build.dir.bin.jarunobfus}"/>

<arg line= "${build.dir.bin.jarobfused}"/>

<arg line= "${obfuscator.script}"/>

</java>

</target>



<target name= "Afterobfuse" description= "mixed and then packaged into jars" depends= "obfuscate" >

<unzip src= "${build.dir.bin.jarobfused}"

Dest= "${build.dir.obfused}"

/>

<delete dir= "${build.dir.obfused}/meta-inf"/>

</target>



<target name= "preverify" description= "pre-Audit" depends= "Afterobfuse" >

<exec executable= "${midp.home}/bin/preverify" >

<arg line= "-classpath ${midp.api};${midp.api1}"/>

<arg line= "-D ${build.dir.preverified}"/>

<arg line= "${build.dir.obfused}"/>

</exec>

</target>



<target name= "Package" description= "packaged into jars and Jad" depends= "Preverify" >

<jar basedir= "${build.dir.preverified}"

Jarfile= "${build.dir.bin.jar}"

Manifest= "manifest. MF ">

<fileset dir= "${res.dir}"/>

</jar>

<copy file= "${jad}" tofile= "${build.dir.bin}/${jad}"/>

</target>



<target name= "runpreverify" description= "Execute with Emulator" >

<exec executable= ". /.. /bin/setjarsize.exe ">

<arg line= "${build.dir.bin.jar} ${build.dir.bin}/${jad}"/>

</exec>

</target>



<target name= "Run" description= "Execute with Emulator" >

<exec executable= "${midp.home}/bin/emulator" >

<arg line= "-xdescriptor:${build.dir.bin}/${jad}"/>

</exec>

</target>



<target name= "All" description= "complete all Steps" depends= "Cleandir,package,runpreverify,run"/>



</project>





In addition, the property profile Build.properties is loaded in the Build.xml file, which is used to set some common properties, as follows:

#此文件用来设定一些常用属性

#项目名称

Name=myfirst



#JAD与JAR的文件名

Jar=${name}.jar

Jad=${name}.jad



#源文件所在路径

Src.dir=src

#资源文件所在路径

Res.dir=res

#建构产物放置位置

Build.dir=build



#编译后类文件的放置位置

Build.dir.classes=${build.dir}/classes

#未经过混淆的JAR文件名

Build.dir.bin.jarunobfus=${build.dir.bin}/${name}-unobfus.jar

#经过混淆的JAR文件名

Build.dir.bin.jarobfused=${build.dir.bin}/${name}-obfused.jar

#混淆后类的放置目录

Build.dir.obfused=${build.dir}/obfused

#经过预先审核之后的类文件放置位置

Build.dir.preverified=${build.dir}/preverified

#JAD与JAR的放置位置

Build.dir.bin=${build.dir}/bin

#最终的JAR文件名

Build.dir.bin.jar=${build.dir.bin}/${jar}



The path where the #J2ME Wireless Toolkit

Midp.home=.. /.. /wtk/

#MIDP程序库所在路径

Midp.api=${midp.home}/lib/midpapi20.jar

Midp.api1=${midp.home}/lib/rt1.42.jar



#空白MIDP程序库所在路径

Midp.emptyapi=${midp.home}/wtklib/emptyapi.zip





#混淆器与控制文件

Obfuscator.lib=retroguard.jar

Obfuscator.script=script.rgs





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.