File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes anyone used Canvas + graphics ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "anyone used Canvas + graphics ?" Watch "anyone used Canvas + graphics ?" New topic
Author

anyone used Canvas + graphics ?

Naveen Sharma
Ranch Hand

Joined: Mar 23, 2001
Posts: 65
hi,
i m trying to draw a string at some random position on the screen
i have extended the Canvas class and overided the paint()
now say on some clicks i am generating a random x,y positions.. and drawing a string using drawString() of Graphics class
evrything works fine,
but i want the previously written string should be cleand up... and each time the text should is written at new x,y location, it should not messed up with previous written
i have called the repaint() of graphics class to repaint the text at new location... but as i donot find any update() in canvas class... how to achieve this
any ideas?
Thanks
Naveen
Naveen Sharma
Ranch Hand

Joined: Mar 23, 2001
Posts: 65
I am surprised no one is having ANY idea about that
Xiao Qinglai
Greenhorn

Joined: Mar 19, 2003
Posts: 6
First you should stroe the (x, y) of your latest panited String; Whenever you are painting the nextString, repaint both area of oldString and newString.
like this:
repaint(xOfOldString, yOfOldString, widthOfOldString, heightOfOldString);
repaint(xOfNewString, yOfNewString, widthOfNewString, heightOfNewString);


Regards,<p>Xiao
Naveen Sharma
Ranch Hand

Joined: Mar 23, 2001
Posts: 65
hi,
as Xiao Qinglai said use repaint(int,int,int,int) instead of repaint()..
i have written the following code, my aim is to make a toggle,
when we press key "3" it should write the string..
and when we press key "9" it should delete the string from canvas...
please tell me where things are wrong
Thanks
Navi
//------ Following is the code


//--------Code ends here
Xiao Qinglai
Greenhorn

Joined: Mar 19, 2003
Posts: 6
plz pay attention to this method:
/************paint() of CanvasArea************/
public void paint(Graphics g){g.setColor(255, 0, 0); if(toDraw)g.drawString(txt,50,100, Graphics.TOP | Graphics.HCENTER);}
/*****************end**************************/
if toDraw is true, paint txt to screen;
if toDraw is false, do nothing --- instead, you should do this:
/*************start********/
Font f = g.getFont();
g.setColor(0x00FFFFFF);
g.fillRect(50, 100, f.stringWidth(txt), f.getHeight());
/********end**********/
good luck
Regards,
XQL
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: anyone used Canvas + graphics ?