Site Map Mail This To A Friend PrivacyPolicy Subscribe to MakeLogic RSS Feed

Examples

If you have J2ME installed in your desktop computer, you can run this example by clicking on the following link. After clicking the link if you are prompted with the question "Would you like to open the file or save it to your compter ?", your answer should be "open". And you should see the emulator windowing showing up and running the example. (Emulators for some devices are distributed along with the J2ME )

These are the same examples that you get along with the microGraphs download. You can build the examples by running the build.bat that comes in the examples folder of the download. Please note that this explanation is made assuming that you have downloaded the microGraphs. All the folder names in this explanation are taken from the download folder structure itself.

  • In the java code you write import the classes com.makeLogic.mg.*
  • Extend your class from the MIDlet class of J2ME MIDP API
  • Implement the three functions that are needed
  • startApp, pauseApp and destroyApp
  • In the constructor of the class create the microGraph object you want
  • In the startApp function set that microGraph object as the current displayable
  • After you finish coding the java file, compile it using the regular javac of j2sdk1.4.0 or jdk1.3.0

    javac -d tempout -classpath tempout;lib -bootclasspath c:\j2mewtk\lib\midpapi.zip src/LineGraphTest.java
  • lib is the folder which contains the class files of microGraphs (not the microGraphs.jar in this case)
  • tempout is the folder where the compiled classes will be copied
  • The bootclasspath will point to the MIDP API
  • Now you should preverify (preverify is a j2mewtk utility) the classes just created using

    preverify -classpath c:\j2mewtk\lib\midpapi.zip;tempout;lib -d out tempout
  • The preverified classes will be copied into the folder out
  • Jar the the class files - your class file/s (in this case example) and the microGraph classes - into XXXX.jar along with the manifest file from the conf folder. The manifest file should look something like this

Manifest file contents:

MIDlet-1: MakeLogic, makelogic.png, XXXGraphTest
MIDlet-Name: microGraphs
MIDlet-Vendor: MakeLogic
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0

Now your XXXX.jar file is ready

Create a XXXX.jad file as following

XXXX.jad file contents:

MIDlet-1: XXXXGraph, makelogic.png, XXXXGraphTest
MIDlet-Jar-Size: 3678
MIDlet-Jar-URL: XXXX.jar
MIDlet-Name: GraphXXXX
MIDlet-Vendor: MakeLogic
MIDlet-Version: 1.0


In windows machines just double clicking on the XXXX.jad file should launch the Emulator which runs your MIDlet

For transfering the MIDlet into your handheld device please look into the documentation of your device



Example code is shown below:

The following is a LineGraphExample:

/*
* @(#)LineGraphTest.java 1.00
*
* Author : Madanu Ujjwal Kumar
* Copyright 2002 MakeLogic. All Rights Reserved.
*
* This software is the proprietary information of MakeLogic.
* Use is subject to license terms.
*
*/


import javax.microedition.midlet.MIDlet;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Display;
import java.util.Random;

import com.makeLogic.mg.LineGraph;

/**
*
* @author Madanu Ujjwal Kumar
* @version 1.0
* @see com.makeLogic.mg
* @since MWDK1.0
*/


public class LineGraphTest extends MIDlet{

LineGraph lineGraph;
private Display display;
int x[];
int y[];
long start = System.currentTimeMillis();


public LineGraphTest(){

int size = 21;

x = new int[size];
y = new int[size];

Random random = new Random(4);

for(int i = 0; i <size;i++){
x[i] = i;
y[i] = i*i +3;//(int)(System.currentTimeMillis()-start);//Math.abs(random.nextInt());
start = (int)System.currentTimeMillis();
}

lineGraph = new LineGraph(x,y,"MakeLogic","Stock $",
LineGraph.ZOOM_IN,"NASDAQ");
display = Display.getDisplay(this);

}



public void startApp(){

//play with all the possible property settings of the LineGraph

//gridStyle
//possible values are
//LineGraph.X_ONLY
//LineGraph.Y_ONLY
//LineGraph.X_AND_Y
//LineGraph.NONE
lineGraph.setGridStyle(LineGraph.X_AND_Y);

//border
lineGraph.setBorder(false);

//nodeRings
lineGraph.setNodeRings(false);


//xGridStyle
//possible values are
//LineGraph.DOTTED
//LineGraph.SOLID
lineGraph.setXGridStyle(LineGraph.DOTTED);

//yGridStyle
//possible values are
//LineGraph.DOTTED
//LineGraph.SOLID
lineGraph.setYGridStyle(LineGraph.DOTTED);

//borderStyle
//possible values are
//LineGraph.DOTTED
//LineGraph.SOLID
lineGraph.setBorderStyle(LineGraph.DOTTED);

//nodeRingsStyle
//possible values are
//LineGraph.DOTTED
//LineGraph.SOLID
lineGraph.setNodeRingsStyle(LineGraph.DOTTED);

//xLabel
//lineGraph.setXLabel("MakeLogic");

//yLabel
//lineGraph.setYLabel("Stock Value $");

//lineGraph.setTitle("DOW");

//xValuesDisplayType
//possible values are
//LineGraph.NONE
//LineGraph.END_VALUES
//LineGraph.ALL_VALUES
lineGraph.setXValuesDisplayType(LineGraph.ALL_VALUES);

//yValuesDisplayType
//possible values are
//LineGraph.NONE
//LineGraph.END_VALUES
//LineGraph.ALL_VALUES
lineGraph.setYValuesDisplayType(LineGraph.ALL_VALUES);

//xAxis
lineGraph.showXAxis(true);

//yAxis
lineGraph.showYAxis(true);

//xLabel
lineGraph.showXLabel(true);

//yLabel
lineGraph.showYLabel(true);

//viewType
//LineGraph.ZOOM_IN
//LineGraph.ZOOM_OUT
lineGraph.setViewType(LineGraph.ZOOM_IN);



//show the graph on the device now :-)
//display.setCurrent(lineGraph);
display.setCurrent(lineGraph);
}

public void pauseApp(){
}

public void destroyApp(boolean unconditional){

}
}

The following is a BarGraph Example:

/*
* @(#)BarGraphTest.java 1.00
*
* Author : Madanu Ujjwal Kumar
* Copyright 2002 MakeLogic. All Rights Reserved.
*
* This software is the proprietary information of MakeLogic.
* Use is subject to license terms.
*
*/


import javax.microedition.midlet.MIDlet;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Display;
import java.util.Random;

import com.makeLogic.mg.BarGraph;

/**
*
* @author Madanu Ujjwal Kumar
* @version 1.0
* @see com.makeLogic.mg
* @since MWDK1.0
*/


public class BarGraphTest extends MIDlet{

BarGraph barGraph;
private Display display;
int x[];
int y[];

// private Command exitCommand;

public BarGraphTest(){

int size = 4;

x = new int[size];
y = new int[size];

Random random = new Random(4);

for(int i = 0; i <size;i++){
x[i] = 1991+i;
y[i] = i*10+4;//Math.abs(random.nextInt());

}

barGraph = new BarGraph(x,y,"MakeLogic","Share:$",BarGraph.VERTICAL,
BarGraph.ZOOM_IN,"NASDAQ");
display = Display.getDisplay(this);

}



public void startApp(){

//play with all the possible property settings of the BarGraph


//gridStyle
//possible values are
//BarGraph.X_ONLY
//BarGraph.Y_ONLY
//BarGraph.X_AND_Y
//BarGraph.NONE
barGraph.setGridStyle(BarGraph.X_AND_Y);

//border
barGraph.setBorder(false);

//xGridStyle
//possible values are
//BarGraph.DOTTED
//BarGraph.SOLID
barGraph.setXGridStyle(BarGraph.DOTTED);

//yGridStyle
//possible values are
//BarGraph.DOTTED
//BarGraph.SOLID
barGraph.setYGridStyle(BarGraph.DOTTED);

//borderStyle
//possible values are
//BarGraph.DOTTED
//BarGraph.SOLID
barGraph.setBorderStyle(BarGraph.DOTTED);


//xLabel
//barGraph.setXLabel("MakeLogic");

//yLabel
//barGraph.setYLabel("Stock Value $");

//title
//barGraph.setTitle("DOW");

//xValuesDisplayType
//possible values are
//BarGraph.NONE
//BarGraph.END_VALUES
//BarGraph.ALL_VALUES
barGraph.setXValuesDisplayType(BarGraph.ALL_VALUES);

//yValuesDisplayType
//possible values are
//BarGraph.NONE
//BarGraph.END_VALUES
//BarGraph.ALL_VALUES
barGraph.setYValuesDisplayType(BarGraph.ALL_VALUES);

//xAxis
barGraph.showXAxis(true);

//yAxis
barGraph.showYAxis(true);

//xLabel
barGraph.showXLabel(true);

//yLabel
barGraph.showYLabel(true);

//showTitle
barGraph.showTitle(true);

//viewType
//BarGraph.ZOOM_IN
//BarGraph.ZOOM_OUT
barGraph.setViewType(BarGraph.ZOOM_IN);



//show the graph on the device now :-)
//display.setCurrent(barGraph);
display.setCurrent(barGraph);
}

public void pauseApp(){
}

public void destroyApp(boolean unconditional){

}
}
Was this information helpful to you?
Rock The Vote Next Poll Question

RSS Feeds
Subscribe to MakeLogic RSS Feed Add to My Yahoo! Add to Google
NewsLetter