{"id":455,"date":"2003-07-22T23:17:52","date_gmt":"2003-07-23T03:17:52","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=455"},"modified":"2003-07-22T23:17:52","modified_gmt":"2003-07-23T03:17:52","slug":"stopwatch-midlet","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2003\/07\/22\/stopwatch-midlet\/","title":{"rendered":"StopWatch MIDlet"},"content":{"rendered":"<p>To get a better handle on MIDP programming, I&#8217;m writing a quick and dirty stopwatch for my phone (the Nokia 3650, which didn&#8217;t come with a stopwatch, unlike the T68i I had before).  <\/p>\n<p>Basically, I&#8217;ve got a MIDlet class (container for the app), a Canvas class (displays the stopwatch) and a Thread class (updates the canvas every second).  I&#8217;ve run into a couple interesting tidbits while trying to use the repaint() method of the Canvas class.  At first I was having the Thread class update a public String object in the Canvas and then calling repaint() on the canvas, which according to this <a href=\"http:\/\/wireless.java.sun.com\/midp\/ttips\/repaint\/\">article<\/a> on java.sun.com, should then clear the previous canvas and display the new canvas. Curiously, this resulted in each canvas repainting the display with the previous canvas showing through, which I&#8217;m guessing is what the above article was saying might happen when it said:<\/p>\n<p><i>&#8220;&#8230; If you mark two or more areas for repainting within a short span of time, the system may combine the paint requests into a single request to paint the union of the two areas (the smallest rectangle containing both).&#8221;<\/i><\/p>\n<p>For example, in my thread class, I&#8217;d update a property of the canvas:<\/p>\n<p>canvas.setText(&#8220;this is the new time&#8221;);<\/p>\n<p>and then call the repaint method:<\/p>\n<p>canvas.repaint();<\/p>\n<p>This resulted in &#8220;this is the new time&#8221; being written over whatever previously existed in the canvas.  Do I have the wrong idea about how to update text in a canvas? Shouldn&#8217;t I just be able to update the text and call repaint()?<\/p>\n<p>Anyways, I&#8217;ve ended up updating a public Image object in the Canvas from the Thread and then calling repaint(), which seems to work. Love to hear any suggestions about a better way!<\/p>\n<p>Links:<\/p>\n<p><a href=\"http:\/\/www.onjava.com\/pub\/a\/onjava\/excerpt\/wirelessjava_ch5\/index3.html\">Creating Low-Level GUI Components<\/a> [onjava.com]<\/p>\n<p><a href=\"http:\/\/wireless.java.sun.com\/midp\/ttips\/repaint\/\">MIDP Canvas Repainting<\/a> [java.sun.com]<\/p>\n<p><a href=\"http:\/\/discussion.forum.nokia.com\/forum\/forumdisplay.php?s=&amp;forumid=54\">Nokia Java Graphics Forum<\/a> [discussion.forum.nokia.com]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get a better handle on MIDP programming, I&#8217;m writing a quick and dirty stopwatch for my phone (the Nokia 3650, which didn&#8217;t come with a stopwatch, unlike the T68i I had before). Basically, I&#8217;ve got a MIDlet class (container for the app), a Canvas class (displays the stopwatch) and a Thread class (updates the &hellip; <a href=\"https:\/\/cephas.net\/blog\/2003\/07\/22\/stopwatch-midlet\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">StopWatch MIDlet<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/455"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=455"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/455\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}