java me - Clearing the canvas with J2ME -


i'm trying create program shows 2 images @ random locations , changes them every second. problem when image redrawn can still see image in previous position.

i'm using wtk 2.52 if that's relevant.

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

you clear canvas this:

g.setcolor(0x000000); // whatever color wish clear g.setclip(0,0,getwidth(),getheight()); g.fillrect(0,0,getwidth(),getheight()); 

so insert lines before drawing images.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -