Download J2ME WheelItem CustomItem

October 6th, 2007 Posted in J2ME / JavaME

 

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!

 

Possibly Related Posts...


One Response to “Download J2ME WheelItem CustomItem”

  1. Nedal Says:

    Download example application with WheelItem source : WaitFormDemo.zip
    ——————-
    page not found !!



Leave a Reply

This blog is protected by dr Dave\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'s Spam Karma 2: 174430 Spams eaten and counting...