想画个动态的实心矩形,利用线程,有点问题,请各位帮忙看看!!!

smart_code 2010-10-16 01:20:18
protected void paint(Graphics g) {
g.setColor(0x00000000);
g.fillRect(50, 55, 150, RecHeight);
}


public void run() {
// TODO Auto-generated method stub
while(RecHeight<100){
RecHeight+=10;
repaint();
try{
Thread.sleep(1000);
}catch (Exception e) {
// TODO: handle exception
}
}

画的时候看不到动态向下拉的过程,等过了大概十秒一次性绘制出来,我想实现动态的向下拉的矩形效果怎么绘制?谢谢各位
...全文
67 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
harley 2010-10-16
  • 打赏
  • 举报
回复
import javax.microedition.lcdui.*;
public class Rect extends Canvas implements Runnable {
int RecHeight;
public final static int Width = 240,Height=320;
Thread thread;
public Rect() {
thread = new Thread(this);//开启线程
thread.start();
setFullScreenMode(true);//设置全屏
}
protected void paint(Graphics g) {
g.setColor(0x00000000);
g.fillRect(50, 55, 150, RecHeight);

}
public void run() {
// TODO Auto-generated method stub
while(RecHeight<100){
RecHeight+=10;
repaint();
try{
Thread.sleep(1000);
}catch (Exception e) {
// TODO: handle exception
}
}
}
}

上边代码都是按照你的写的。我的没有问题。就是下拉的时候有点慢。你把线程睡眠时间改短点。

13,097

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧