Posts Tagged ‘j2me’
Download J2ME WheelItem CustomItem
This is an example of J2ME / JavaME CustomItem called WheelItem. It does nothing beside showing a spinning wheel on the phone screen. WheelItem is a perfect candidate to be displayed on a wait form screen replacing Gauge class while your application is performing lengthy operating.
WheelItem Screenshot
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class WheelItem extends CustomItem
{
private int mCount,mMaximum;
private int mInterval;
private int mWidth,mHeight,mX,mY,mRadius;
private String mMessage;
public WheelItem(String title)
{
super(title);
mCount=0;
mMaximum = 36;
mInterval = 100;
TimerTask task = new TimerTask() {
public void run() {
mCount = (mCount+1) % mMaximum;
repaint();
}
};
Timer timer = new Timer();
timer.schedule(task,0,mInterval);
}
public void setString(String string)
{
mMessage = string;
repaint();
}
public void paint(Graphics g, int iWidth, int iHeight) {
mWidth = iWidth;
mHeight = iHeight;
int halfWidth = mWidth/2;
int halfHeight = mHeight/2;
mRadius = Math.min(halfWidth,halfHeight);
mX = halfWidth - mRadius/2;
mY = halfHeight - mRadius/2;
int theta = -(mCount*360/mMaximum);
g.setColor(255,255,255);
g.fillRect(0,0,mWidth,mHeight);
g.setColor(0,0,0);
g.drawArc(mX,mY,mRadius,mRadius,0,360);
g.fillArc(mX,mY,mRadius,mRadius,theta+90,90);
g.fillArc(mX,mY,mRadius,mRadius,theta+270,90);
if (mMessage !=null)
{
g.drawString(mMessage,mWidth/2,mHeight,Graphics.BOTTOM | Graphics.HCENTER);
}
}
public int getMinContentWidth() { return 80; }
public int getMinContentHeight() { return 80; }
public int getPrefContentWidth(int width) {return getMinContentWidth();}
public int getPrefContentHeight(int height) {return getMinContentHeight();}
}
Download example application with WheelItem source : WaitFormDemo.zip
Ported (rather poorly) from Wheel canvas written by Jonathan Knudsen from his article – Networking, User Experiences and Threads.
Any suggestions or improvements are welcomed!
iPhoneCanvas – Fancy List component class for J2ME
I found a really nice but simple to use fancy list chooser class that emulates an iPhone display. The class requires MIDP 2.0 supported phones and can replace the default and boring List chooser class into a stunning, smooth scrolling graphical menu (includes reflections) for your users to see
Here’s example screenshot of iPhoneCanvas demo in action :
These menu icons are generated from flat and boring thumbnails like these :


Download
iPhoneCanvas is licensed under the GNU General Public License and can be downloaded from listchooser Google Code project page
Demo
The iPhoneCanvas demo featured in above screenshot can be downloaded here – fancylist.jar, fancylist.zip (demo source code)
Please submit bug reports or suggestions at Google Code listchooser page
How to generate Random Numbers in J2ME application
One of the popular question asked in this blog is ways to generate random numbers in J2ME application.
As most people probably realized, the JavaME CLDC does not include the Math.Random class to generate random numbers. However one can generate a series of random numbers in JavaME/J2ME application by using the included java.util.Random class.
Here’s a sample usage
import java.util.Random;
...
Random generator = new Random();
generator.setSeed(System.currentTimeMillis());
float f = generator.nextFloat();
System.out.println(""+(f*100.0f)%100);
...
The sample code above will produce a random floating-point number between 0..100 (exclusive)
Here’s the source code for the full Random Number Demo application : RandomDemo.java,
Foxrate – Open Source J2ME Currency Converter Mobile Application
Foxrate mobile is a currency converter application for mobile devices. It is a relatively small application which supports converting from/to 35 different currencies used around the world.
Foxrate lifts you from the burden of updating currency rate by automatically retrieving latest currency information from remote server. The best part about foxrate is — it is available for free and open source!
Download Foxrate Mobile Currency Converter
Foxrate can downloaded from- Google Code’s Foxrate page and Getjar.com

