Skip to main content

problem with animation wait screen

No replies
iraqy2010
Offline
Joined: 2011-02-09
Points: 0

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class KeyPad extends MIDlet implements

CommandListener,Runnable{

Display display;

private Form container,f;

private Command exit;

List list;
StringItem st;

private TextField field;
InputStream is;
CustomGauge wait;
private Image select;
Image[] frames;Thread t;
public KeyPad() {
display = Display.getDisplay(this);
st=new StringItem(null,null);
container = new Form("");
wait =new CustomGauge();
f= new Form("");
t = new Thread(this);
f.append(st);
frames = new Image[7];
String[] options = {"Implicit", "Exclusive", "Multiple"};
list = new List("List Example", Choice.IMPLICIT, options,
null);
list.setCommandListener(this);
exit = new Command("خروج",Command.EXIT,1);
container.addCommand(exit);
for(int i = 0; i < 7; i++)
{
try {
frames[i] = Image.createImage("/frame" + (i+1) +
".png");
select= Image.createImage("/select.png");
}
catch (IOException e) {
e.printStackTrace();
}
}
}

public void startApp() {
display.setCurrent(list);
}
public void commandAction(Command c, Displayable d) {

if(c == List.SELECT_COMMAND )
{ st.setText(this.readHelpText(list.getSelectedIndex
()));
System.out.println(list.getSelectedIndex());
t.start();
display.setCurrent(wait);
}
if(c == exit) {
notifyDestroyed();
}
}public void run() {
display.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public String readHelpText(int mm)
{
{
is= getClass().getResourceAsStream(Integer.toString(mm
+1)+".txt");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] bufferByte = new byte[1];
while (is.read(bufferByte) != -1) {
baos.write(bufferByte);
}
return new String(baos.toByteArray(),"UTF-8");
} catch (Exception e) {
System.out.println("Unable to create stream");
}
return null;
}
public class CustomGauge extends Canvas implements Runnable
{
Thread thread;
int nextFrame;
public CustomGauge()
{
nextFrame = 0;
thread = new Thread(this);
thread.start();
}
protected void paint(Graphics g)
{
g.drawImage(frames[nextFrame], (getWidth() / 2) - 40, getHeight

()/2 - 40, Graphics.TOP|Graphics.LEFT);
}
public void run()
{
while (true) {
try {
if(nextFrame == 6) {
nextFrame = 0;
}
else {
nextFrame++;
}
repaint();
Thread.sleep(200);
}
catch (InterruptedException ee)
{
break;
}
}
}
}
}

but when I display the canvas class in methode startup

public void startApp() {

display.setCurrent(wait);

}

it work correctly

please any one Edit on my code
thanks for all