Subscribe: J2ME Setup
Added By: Feedage Forager Feedage Grade B rated
Language: English
cdc  color  cube  figure  home  jar  java  jdbc  light  material  midlet  myj meapp  myj  object  triangles  vertex  vertices 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: J2ME Setup

J2ME Setup

A blog of "Avatar_J2ME": special interest group for Java™ micro edition technology (J2ME). Containing news, tutorials, current issues, and others useful information! It's where developers seeks help, and share experience! Visit the J2ME discussion group

Updated: 2014-10-06T16:51:33.517-07:00


M3G - 3D Object Materials


Materials A light can cause different effects. A shiny silver ball reflects the light in a different way than a sheet of paper does. M3G models these material characteristics with the following attributes: Ambient reflection: The light that is reflected by an ambient light source.Diffuse reflection: The reflected light is scattered equally in all directions.Emissive light: An object can send out light to imitate glowing objects.Specular reflection: The light that reflects off objects with a shiny surface. You can set a color for each material attribute. The shiny silver ball's diffused color would be silver and its specular component white. To get the final object color, the material's color mixes with the light's color. If you point a blue light toward the silver ball, it would turn bluish. Listing 9 shows how to use materials: Listing 9. Setting a material// Create appearance and the material._cubeAppearance = new Appearance();_colorTarget = COLOR_DEFAULT;setMaterial(_cubeAppearance, _colorTarget);/*** Sets the material according to the given target.** @param appearance appearance to be modified.* @param colorTarget target color.*/protected void setMaterial(Appearance appearance, int colorTarget){Material material = new Material();switch (colorTarget){case COLOR_DEFAULT: break;case COLOR_AMBIENT: material.setColor(Material.AMBIENT, 0x00FF0000); break;case COLOR_DIFFUSE: material.setColor(Material.DIFFUSE, 0x00FF0000); break;case COLOR_EMISSIVE: material.setColor(Material.EMISSIVE, 0x00FF0000); break;case COLOR_SPECULAR: material.setColor(Material.SPECULAR, 0x00FF0000); material.setShininess(2); break;// no default}appearance.setMaterial(material);} setMaterial() creates a new Material object and sets the colors with setColor() using the respective color component identifier. The Material object is then assigned to an Appearance object, which is used in the call to Graphics3D.render(). Although not shown here, you can use Material.setVertexColorTrackingEnable() in order to use the vertex colors for ambient and diffuse reflection instead of using Material.setColor(). Both lights and materials are implemented in Using keys, you can combine different lights with materials to experiment with the effects. In Figure 9, the different material characteristics are displayed using an omnidirectional light. Each screenshot sets a single color component to red to demonstrate its effect in isolation. Figure 9. Different color components: a) Ambient, b) Diffuse, c) Emissive, and d) Specular The ambient reflection only reacts to ambient light; thus, using an omnidirectional light has no effect. The diffuse material component creates a matte surface, while the emissive component creates a glowing effect. The specular color component emphasizes the shininess. Again, you could improve the shading quality by using more triangles. (picked from IBM developer site)By Avatar[...]

Your first 3D object


Your first 3D object As a first example, you'll create a cube as displayed in Figure 1. Figure 1. Sample cube: a) Front view with vertex indices, b) Side view with clipping planes (Front, Side) The cube lives in what M3G defines as a right-handed coordinate system. If you take your right hand and stretch out your thumb, index finger, and middle finger so that each finger is in a right angle to the other two fingers, then the thumb is your x axis, the index finger the y axis, and the middle finger the z axis. Try to align your thumb and index finger with the x and y axis in Figure 1a; your middle finger should then point toward you. I've used eight vertices (the cube's corner points) and placed the cube's center at the coordinate system's origin. As you can see in Figure 1, the camera that shoots the 3D scene looks toward the negative z axis, facing the cube. The camera's position and properties define what the screen later displays. Figure 1b shows a side view of the same scene so you can easily see what part of the 3D world is visible to the camera. One limiting factor is the viewing angle, which is comparable to using a camera lens: a telephoto lens has a narrower view than a wide-angle lens. The viewing angle thus determines what you can see to the sides. Unlike the real world, 3D computing gives you two more view boundaries: near and far clipping planes. Together, the viewing angle and the clipping planes define what is called the view frustum. Everything inside the view frustum is visible, everything outside is not. This is all implemented in the VerticesSample class, whose members you can see in Listing 1. Listing 1. Sample displaying a cube, Part 1: Class memberspackage m3gsamples1;import javax.microedition.lcdui.*;import javax.microedition.m3g.*;/*** Sample displaying a cube defined by eight vertices, which are connected* by triangles.** @author Claus Hoefele*/public class VerticesSample extends Canvas implements Sample{/** The cube's vertex positions (x, y, z). */private static final byte[] VERTEX_POSITIONS = {-1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1,-1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1};/** Indices that define how to connect the vertices to build* triangles. */private static int[] TRIANGLE_INDICES = {0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1};/** The cube's vertex data. */private VertexBuffer _cubeVertexData;/** The cube's triangles defined as triangle strips. */private TriangleStripArray _cubeTriangles;/** Graphics singleton used for rendering. */private Graphics3D _graphics3d;VerticesSample inherits from Canvas to be able to draw directly to the display. It also implements Sample, which I defined to help organize this article's different source code samples. VERTEX_POSITIONS defines eight vertices in the same order, as shown in Figure 1a. For example, vertex 0 is defined as position (-1, -1, 1). Remember that I placed the cube's center at the coordinate system's origin; therefore, the cube's edges will be two units long. The camera's position and viewing angle will later define the amount of pixels a unit will occupy on the screen. The vertex positions are not enough, however; you also have to say what geometry you want to build. Like in a dot-to-dot painting, you have to connect vertices with lines until you see the resulting drawing. M3G poses one restriction though: you must build the geometry from triangles. Triangles are popular with 3D implementations because you can define any polygon as a set of triangles. A triangle is a basic drawing operation on which you can build more abstract operations. Unfortunately, if you had to describe the cube with triangles alone, you would need 6 sides * 2 triangles * 3 vertices = 36 vertices; this would be a waste of memory as many vertices are duplicated. To reduce memory, you first separate the vertices from their triangle definitions. TRIANGLE_INDICES defines the geometry using the indices of the VERTEX_POSITIONS array and can thus reuse vertices. Next, you redu[...]

JSR-184 a.k.a. Micro3D a.k.a. Java Mobile 3D


What is Java Mobile 3D?

Definition from
Sony Ericsson developer site:
Java Mobile 3D Graphics (also known as JSR 184) is an API tailored for the generation and presentation of 3D
content on mobile platforms. This section discusses this API and an alternate 3D implementation, HI Corporation’s Mascot Capsule Micro3D version 3 (also known as Micro3D). Sony Ericsson has chosen to implement both API sets, allowing Mascot Capsule Micro3D serve as a migration path for 3D applications until Java Mobile 3D-enabled devices become widely available. Here, we’ll also briefly try to address any possible point of confusion related to the two implementations of 3D Java APIs in Sony Ericsson phones.

M3G is a fun technology to play around for developers, ever in history 3D developement got so easy (well if compared with Direct3D and OpenGL programming)!



ContentStep 1:Install JavaStep 2:Install J2ME ToolkitStep 3:Testing Installing JDK ...Firstly, goto "" and grab a copy of the latest JDK (notice: only J2RE will only allow you to run java apps, if you are going to developement MUST use a JDK). Unzip it and put it in a folder, here we use "c:/java/j2sdk" as a default directory! Then you have to setup an environment variable in order to make work.Setting up environment variable for Java ...Right click on "My Computer", select "properties"->"Advanced"->"Environment Variables", and you will see stuff like below:JAVA_HOME=C:\java\jdk1.2.4_01 (refer to path where you install the Java sdk)PATH= ... ;C:\java\jdk1.2.4_01\bin Installing J2ME Toolkit ...This may be as simple as it seems, just goto j2me download site, pick a copy of " Sun Java Wireless Toolkit" ... install it and start coding. Note that you may have a few choice either using an IDE like NetBean, JBuilder, and so on; to the build-in code writing module with the WirelessToolkit that you just downloaded or even start off with a Notepad!Well my personal favor, a Notepad will do, try compiling with command prompt also, had a better feel of the whole development process. Testing ...Kick StartSix simple Steps for writing a J2ME:Code a Java file.Compile with CLDC and MIDP library.Preverify it with "preverify.exe".Write a manifest file, then package it with every classes and resources in a JAR file.Write a JAD file for deploying purposes.Test it on emulator or real device, do some performance tweaking and fine tuning for portability.Some assumption: %J2ME_HOME%=C:\WTK22\%JAVA_HOME%=C:\Program Files\Java\jdk1.5.0_04Writing a simple CLDC app...import*;import*;public class TestInputOutput {public static void main( String[] args ){try { String uri ="socket://"; StreamConnection conn = (StreamConnection) uri ); // Send HTTP request... PrintStream out = new PrintStream(conn.openOutputStream() ); out.println( "GET /index.html HTTP/0.9\r\n" ); out.flush(); // Get raw HTTP reply... InputStream in = conn.openInputStream(); int ch; while( ( ch = ) != -1 ){ System.out.print( (char) ch ); } in.close(); out.close(); conn.close();}catch( ConnectionNotFoundException e ){ System.out.println( "Socket could not be opened" );}catch( IOException e ){ System.out.println( e.toString() );}System.exit( 0 );}}Writing a simple MIDP app...import javax.microedition.lcdui.*;import javax.microedition.midlet.*;public class HelloMIDlet extends MIDlet implements CommandListener {private Form mMainForm;public HelloMIDlet() { mMainForm = new Form("HelloMIDlet"); mMainForm.append(new StringItem(null, "Hello, MIDP!")); mMainForm.addCommand(new Command("Exit", Command.EXIT, 0)); mMainForm.setCommandListener(this);}public void startApp() { Display.getDisplay(this).setCurrent(mMainForm);}public void pauseApp() {}public void destroyApp(boolean unconditional) {}public void commandAction(Command c, Displayable s) { notifyDestroyed();}}To Compile your codes:%JAVA_HOME%\bin\javac -bootclasspath %J2ME_HOME%\lib\midpapi20.jar;%J2ME_HOME%\lib\cldcapi.jar MyJ2MEApp.javaTo Preverify your class:%J2ME_HOME%\bin\preverify.exe -classpath %J2ME_HOME%\lib\midpapi20.jar;%J2ME_HOME%\lib\cldcapi.jar MyJ2MEAppWriting a Menifest file:MIDlet-Name: MyJ2MEAppMIDlet-Version: 1.0.0MIDlet-Vendor: AvatarTo Package everything:%JAVA_HOME%\bin\jar cvfm MyJ2MEApp.jar MyJ2MEApp.classWriting a Java Application Describtion (JAD) file:MIDlet-1: MyJ2MEApp, , MyJ2MEAppMIDlet-Name: MyJ2MEAppMIDlet-Version: 1.0.0MIDlet-Vendor: AvatarMIDlet-Jar-URL: MyJ2MEApp.jarMIDlet-Jar-Size:MicroEdition-Profile: MIDP-2.0MicroEdition-Configuration: CLDC-1.1*Important notes - remember to fill in the MIDlet-Jar-Size with a correct file size of your jar (e.g.:MIDlet-Jar-Size: 1469)*To Test your application:%J2ME_HOME%\bin\emulator.exe -Xdescriptor MyJ2MEApp.jadHooray, it is working!!!Resources:Tutorial from[...]

JDBC comes to J2ME finally?


J2ME Brief IntroductionJ2ME is always comes with limitation, limited memory, limited processing power, limited storage ... . It's made out of MIDP (Mobile Information Device Profile) and CLDC (Connected Limited Device Configuration), CLDC as defined by it's term ... represent a limited resource device. It minimum equiped with 128kb Java memory, 32kb heap, low power and low battery, network/wireless connectivity with low bandwidth. In those days, we can't put too much fancy stuffs in these kind of device, like database for instance.A big brother of CLDC, the CDC (Connected Device Configuration) had far more capability than it's little brother (minimum 512kb memory, minimum 256kb heap, network persistent connectivity with high bandwidth).So where do we see CDC and CLDC? CLDC is common among any j2me phones, but CDC can only be seen on high-end PDA phones like Nokia S80 series, Sony Ericsson smart phones and others which compliant with JSR-82. The JDBC Optional Package The JDBC optional package has been defined to enable CDC developers to write applications that access relational databases. This package is a subset of the java.sql and javax.sql packages in JDBC 3.0 (it could be JDBC > version 3.0 by the time you read this), with the smaller footprint required by CDC-based applications. Note: As of this writing, no reference implementation of the JDBC optional package exists. When an RI is released, you'll be able to build it with the CDC/FP using the OPT_PKGS=jdbc build option of CDC/Foundation or any other CDC-based profile. To support the JDBC optional package, a device must meet the requirements for CDC/Foundation, plus an additional 256KB of RAM and 256KB of ROM. By Avatar.By Avatar[...]