【问题标题】:Clearing the canvas with J2ME使用 J2ME 清除画布
【发布时间】:2013-03-25 22:50:46
【问题描述】:

我正在尝试创建一个程序,该程序在随机位置显示两个图像并每秒更改它们。然而我的问题是,当图像被重绘时,我仍然可以在之前的位置看到图像。

如果相关,我正在使用 WTK 2.52。

public void run()
{

    while(true)
    {
        dVert = rand.nextInt(136);
        dHorz = rand.nextInt(120);
        rVert = 136 + rand.nextInt(136);
        rHorz = 120 + rand.nextInt(120);

        try
        {
            Thread.sleep(1000);
        }
        catch (InterruptedException e)
        {
            System.out.println("Error");
        }
        repaint();
    }
}

public void paint(Graphics g)
{
    int width = this.getWidth() / 2;
    int height = this.getHeight() / 2;
    g.drawImage(imgR, rVert, rHorz, g.TOP | g.LEFT);
    g.drawImage(imgD,dVert,dHorz,g.TOP | g.LEFT);

    //g.drawString(disp, width, 50, Graphics.TOP | Graphics.HCENTER);
    //g.drawString(centerMsg,width, height, Graphics.TOP | Graphics.HCENTER);
    System.out.println(width);
    System.out.println(height);
}

Complete code

【问题讨论】:

    标签: java-me midp lcdui


    【解决方案1】:

    你像这样清除画布:

    g.setColor(0x000000); // Whatever color you wish to clear with
    g.setClip(0,0,getWidth(),getHeight());
    g.fillRect(0,0,getWidth(),getHeight());
    

    因此,只需在绘制图像之前插入这些线条即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-21
      • 2012-07-26
      • 2012-07-19
      • 1970-01-01
      • 2014-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多