Hi,
I did it. It's very simple. Actually for animation in LWUIT you have to crate a class that did animation. Then you have to register it. I found animation example form LWUIT 1.1 for java me developer. So i used it as it is. Here is the code for this class
[code]
class HelloForm extends Form
{
private String helloString = "Hello!";//string to display
private int index = -1;//index to access characters from string
//private HelloMIDlet midlet;
private Mobilang midlet;
private Label textLabel;
//create new instance
//public HelloForm(HelloMIDlet m, String helloText)
public HelloForm(Mobilang m, String helloText)
{
super("Loading...");
midlet = m;
helloText = helloText.trim();
if(!(helloText.equals("")))
{
helloString = helloText;
}
setLayout(new BorderLayout());
//font for writing on textLabel
Font font = Font.createSystemFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_LARGE);
// Create textLabel and set attributes
textLabel = new Label(" ");
textLabel.setAlignment(Label.CENTER);
textLabel.getStyle().setBorder(Border.createBevelRaised());
textLabel.getStyle().setBgColor(0xcccc99);
textLabel.getStyle().setFgColor(0x000000);
textLabel.getStyle().setFont(font);
addComponent(BorderLayout.NORTH, textLabel);
}
//reset the index to start a new cycle
//and erase text
public void resetIndex()
{
index = -1;
textLabel.setText("");
}
public void updateText()
{
System.out.println("index in HelloForm updatText() is: " + index );
System.out.println("helloString.length() in HelloForm updatText() is: " + helloString.length() );
if(index == helloString.length() -2)
//if(txtArea2.)
{
//only one more character left
//display entire message
//textLabel.setText(helloString);
//and stop animation
// midlet.stopAnimation();
// form2.show();
// timer.cancel();
// helloForm.removeAll();
}
else
{
//whole string not yet written
//update text and restart animation on anim_label
//textLabel.setText(getUpdatedText());
textLabel.setText("Please wait...");
midlet.restartAnimation();
}
}
//called to get the next substring of helloString
//if the next character is a space then the substring
//keeps expanding until a non-space character is found
private String getUpdatedText()
{
System.out.println("index in HelloForm getUpdatText() before index ++ is: " + index );
index++;
//if index points to space character
//recurse until non-space character is found
if(helloString.charAt(index) == ' ')
{
return getUpdatedText();
}
return helloString.substring(0, index+1);
}
} //HelloForm
class HelloLabel extends Label
{
//decides which circle is to be drawn
public int state;
//time when previous repaint was done
public long prevTime;
public boolean done;
public boolean initialized;
//nominal interval between two successive repaints
public final int interval = 150;
//width of the label
public int width;
//height of the label
public int height;
//radius of first circle
public int rad1 = 10;
//radii of other three circles
public int rad2, rad3, rad4;
//top left corners of bounding rectangles - smallest to largest
public int x1, y1, x2, y2, x3, y3, x4, y4;
//create a new HelloLabel
public HelloLabel()
{
super();
}
//if this object is registered for animation
//then this method will be called once for every frame
public boolean animate()
{
System.out.println("initialized in HelloLabel animate is: " + initialized );
//painting parameters not set up
//so don't repaint
if(!initialized)
{
return false;
}
//get current time
long currentTime = System.currentTimeMillis();
System.out.println("currentTime in HelloLabel animate is: " + currentTime );
//check if it's 'interval' milliseconds or more since last repaint
//also see if all circles have been drawn
System.out.println("prevTime in HelloLabel animate is: " + prevTime );
System.out.println("done in HelloLabel animate is: " + done );
if (!done && (currentTime - prevTime> interval))
{
//it's more than 'interval' milliseconds
//so save current time for next check
prevTime = currentTime;
//increment state to draw next larger circle
System.out.println("state in HelloLabel animate is: " + state );
System.out.println();
state++;
//check if all circles drawn
if (state == 5)
{
//all finished so set done flag
done = true;
//and ask for string display to be updated
((HelloForm)getComponentForm()).updateText();
// new HelloForm(null, msgReceived).updateText();
}
//request repaint
return true;
}
//either too soon for next repaint
//or all circles drawn
//no repaint to be done
return false;
}
//reinitialize to start animation for next (non-space) character
public void resumeAnimation()
{
state = 0;
done = false;
}
//will be called whenever 'animate' method returns true
public void paint(Graphics g)
{
//save the present color
int color = g.getColor();
//set color for drawing circles
//g.setColor(0xff8040);
g.setColor(0xFFFFFF);
//act as per state value
switch(state)
{
//draw smallest circle
case 1:
//translate to draw relative to label origin
g.translate(getX(), getY());
//paint the circle
g.fillArc(x1, y1, 2*rad1, 2*rad1, 0, 360);
//restore original co-ordinate settings
g.translate(-getX(), -getY());
break;
//draw next larger circle
case 2:
g.translate(getX(), getY());
g.fillArc(x2, y2, 2*rad2, 2*rad2, 0, 360);
g.translate(-getX(), -getY());
break;
//draw next larger cirle
case 3:
g.translate(getX(), getY());
g.fillArc(x3, y3, 2*rad3, 2*rad3, 0, 360);
g.translate(-getX(), -getY());
break;
//draw largest circle
case 4:
g.translate(getX(), getY());
g.fillArc(x4, y4, 2*rad4, 2*rad4, 0, 360);
g.translate(-getX(), -getY());
}
//restore color
g.setColor(color);
}
public void initialize()
{
//get dimensions of label
width = getWidth();
height = getHeight();
System.out.println("width in initialize is: " + width );
System.out.println("height in initialize is: " + height );
//size of largest circle to be determined by
//the shorter of the two dimensions
int side = width < height? width : height;
System.out.println("side in initialize is: " + side );
//find the center of the circle
int centerX = width / 2;
int centerY = height/2;
System.out.println("CenterX in initialize is: " + centerX );
System.out.println("CenterY in initialize is: " + centerY );
//radius of largest circle
//5 less than than half the shorter side
rad4 = side/2 - 5;
System.out.println("rad4 in initialize is: " + rad4 );
System.out.println("rad1 in initialize is: " + rad1 );
//difference between successive radii
int radStep = (rad4 - rad1)/3;
System.out.println("radStep in initialize is: " + radStep );
//radii of second and third circles
rad2 = rad1 + radStep;
System.out.println("rad2 in initialize is: " + rad2 );
rad3 = rad2 + radStep;
System.out.println("rad3 in initialize is: " + rad3 );
//top left corners of the four bounding rectangles
x1 = centerX - rad1;
y1 = centerY - rad1;
x2 = centerX - rad2;
y2 = centerY - rad2;
x3 = centerX - rad3;
y3 = centerY - rad3;
x4 = centerX - rad4;
y4 = centerY - rad4;
initialized = true;
}
} //HelloLabel
[/code]
Then you have to register it in your midlet like this
[code]
helloForm = new HelloForm(this, "Please Wait...");
helloForm.addCommand(cmdStop);
helloForm.addCommandListener(this);
//set form background image
// helloForm.getContentPane().getStyle().setBgTransparency((byte)0);
// try {
// helloForm.getStyle().setBgImage(Image.createImage("/sdsym2.png"));
// } catch(java.io.IOException ioe) {
// }
//font for title and menu bars
Font font = Font.createSystemFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_LARGE);
//set title bar background and foreground
// helloForm.getTitleStyle().setBgTransparency(0);
// helloForm.getTitleStyle().setFgColor(0x99cc00);
// helloForm.getTitleStyle().setFont(font);
//set menu bar background and foreground
//// Style s = new Style();
//// s.setBgTransparency(25);
//// s.setBgColor(0x663366);
//// s.setFgColor(0x99cc00);
//// s.setFont(font);
//// helloForm.setSoftButtonStyle(s);
//Create animLabel and set attributes
animLabel = new HelloLabel();
animLabel.getStyle().setBgColor(0xd5d5d5);
animLabel.getStyle().setBgTransparency(0);
//add label to form
helloForm.addComponent(BorderLayout.CENTER, animLabel);
helloForm.setTransitionInAnimator(CommonTransitions.createFade(1));
[/code]
Now the thing is how to use it with your event. So on send button click i started a thread which call this class and after a delay of 3 sec(for this i use timre) i start make connection to the url. So when you click send the animation starts and when result come i simply replace this form wit my result form and do stop animation. Same goes for sms part. Actaully i receive sms in my application so i replace animation form when result come to my application.
Thanks :)