我有一个问题,我需要在J2ME中使用Canvas制作多色轮旋转。我需要做的是让用户增加旋转的速度或减慢旋转的轮子。我主要解决了这个问题(我认为),但是不能想象一种让车轮旋转而不会导致手机崩溃的方法。这是我到目前为止,它接近但不完全是我需要的。使用画布在J2ME中旋转圆圈
class MyCanvas extends Canvas{
//wedgeOne/Two/Three define where this particular section of circle begins to be drawn from
int wedgeOne;
int wedgeTwo;
int wedgeThree;
int spinSpeed;
MyCanvas(){
wedgeOne = 0;
wedgeTwo = 120;
wedgeThree = 240;
spinSpeed = 0;
}
//Using the paint method to
public void paint(Graphics g){
//Redraw the circle with the current wedge series.
g.setColor(255,0,0);
g.fillArc(getWidth()/2, getHeight()/2, 100, 100, wedgeOne, 120);
g.setColor(0,255,0);
g.fillArc(getWidth()/2, getHeight()/2, 100, 100, wedgeTwo, 120);
g.setColor(0,0,255);
g.fillArc(getWidth()/2, getHeight()/2, 100, 100, wedgeThree, 120);
}
protected void keyPressed(int keyCode){
switch (keyCode){
//When the 6 button is pressed, the wheel spins forward 5 degrees.
case KEY_NUM6:
wedgeOne += 5; wedgeTwo += 5; wedgeThree += 5;
repaint();
break;
//When the 4 button is pressed, the wheel spins backwards 5 degrees.
case KEY_NUM4:
wedgeOne -= 5; wedgeTwo -= 5; wedgeThree -= 5;
repaint();
}
}
我已使用,其将所述spinSpeed到每个楔值的同时(spinSpeed> 0),并调用在加入后重绘()方法重绘()方法试过,但它会导致系统崩溃和锁止(我假设由于无限循环)。有没有人有任何提示或想法如何我可以自动旋转,所以你没有按下按钮,每次你想它旋转? (PS - 我已经潜伏了一段时间,但这是我的第一篇文章,如果它太笼统或要求太多的信息(对不起,如果是的话),我要么删除它,要么修复它。谢谢! )
这是我遇到的问题,我没有意识到所有的动画都必须在单独的线程中完成。 – JohnQPublic 2010-06-18 00:35:30