Java me 如何在移动应用程序中设置动画的开始、停止条件-java me
希望你们都会好起来。实际上,我刚刚做了一个应用程序,其中发生了三件事Java me 如何在移动应用程序中设置动画的开始、停止条件-java me,java-me,Java Me,希望你们都会好起来。实际上,我刚刚做了一个应用程序,其中发生了三件事 连接是通过Http进行的,然后结果会出现在应用程序文本区域中 2.发短信 在应用程序文本区域接收短信 现在我想做动画。我是新手,但我非常喜欢动画。现在,我希望当你们点击发送按钮时,动画开始,显示正在进行的连接(无论是圆形还是闪屏),当结果出现时,动画停止,表单将显示。实际上我的申请表有三种形式,在第一种形式上,你可以选择短信还是上网。如果您选择internet,则form2 show有两个文本区域。在一个文本区域中键入文本,然
谢谢。我做到了。这很简单。实际上,对于LWUIT中的动画,您必须创建一个制作动画的类。那么你必须注册它。我找到了java me开发人员的动画示例表单LWUIT 1.1。所以我就这么用了。下面是这个类的代码 [守则]
class HelloForm extends Form
{
私有字符串helloString=“Hello!”;//要显示的字符串
private int index=-1;//从字符串中访问字符的索引
//私人海洛米德莱小腹;
私家美孚中庭;
私有标签文本标签
//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
{
//决定要绘制的圆
公共国家
//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
//helloForm.getContentPane().getStyle().SetbGTTransparency((字节)0);
//试一试{
//getStyle().setBgImage(Image.createImage(“/sdsym2.png”);
//}catch(java.io.IOException ioe){
//}
//helloForm.getTitleStyle().SetbGTTransparency(0);
//getTitleStyle().setFgColor(0x99cc00);
//helloForm.getTitleStyle().setFont(字体)
////样式s=新样式();
////透明度(25);
////s.setBgColor(0x663366);
////s.setFgColor(0x99cc00);
////s.setFont(字体);
////helloForm.setSoftButtonStyle(s)
[/code]
现在的问题是如何在事件中使用它。因此,在发送按钮单击时,我启动了一个线程来调用这个类,并在延迟3秒后(为此,我使用timre)我开始连接到url。因此,当您单击“发送”时,动画开始,当结果出现时,我只需将此表单替换为我的结果表单并停止动画。短信部分也是如此。实际上,我在应用程序中收到短信,所以当结果出现在我的应用程序中时,我会替换动画表单
谢谢:)
//set form background image
//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
//set menu bar background and foreground
//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));