In the/wtk22/wtklib/devices/defaultcolorphone. properties file under the wtk directory, change touch_screen = false to true. Enablealphachannel = true indicates whether the alpha channel is supported.
Midp2.0 has three touch screen methods:
1. pointerdragged (int x, int y) touch screen drag event (not studied yet)
2. pointerpressed (int x, int y) Touch Screen Press
3. pointerreleased (int x, int y) Touch Screen release
Pointerpressed (int x, int y) the method x is automatically called when the user presses the touch screen. Y is the coordinate of the current press.
Pointerreleased (int x, int y) and pointerpressed (int x, int y) are similar to the corresponding touch screen release events.
Import javax. microedition. lcdui. canvas; <br/> Import javax. microedition. lcdui. graphics; </P> <p> public class testpointcanvas extends canvas {</P> <p> Private Static int RX, Ry; </P> <p> protected void paint (Graphics g) {<br/> G. setcolor (1, 255,255,255); <br/> G. fillrect (0, 0,240,320); <br/> G. setcolor (0, 0, 0); <br/> G. drawstring ("this is a touch test! ", 60,100, 20); <br/> G. drawstring ("Left:" + RX, 20,260, 20); <br/> G. drawstring ("Right:" + ry, 180,260, 20); <br/>}</P> <p> protected void pointerpressed (int x, int y) {<br/> If (x <40 & Y> 240) {<br/> docommandl (); <br/>}< br/> If (x> 200 & Y> 240) {<br/> docommandroid (); <br/>}< br/> repaint (); <br/>}</P> <p> protected void keypressed (INT key) {<br/> If (Key =-6) {<br/> docommandl (); <br/>}< br/> If (Key =-7) {<br/> docommandroid (); <br/>}< br/> repaint (); <br/>}</P> <p> private void docommandl () {<br/> RX ++; <br/>}</P> <p> private void docommandroid () {<br/> ry ++; <br/>}< br/><textarea cols="79" rows="15" name="code" class="java">Import javax. microedition. lcdui. display; <br/> Import javax. microedition. MIDlet. MIDlet; <br/> Import javax. microedition. MIDlet. midletstatechangeexception; </P> <p> public class mymidlet extends MIDlet {</P> <p> Public mymidlet () {<br/>}</P> <p> protected void destroyapp (Boolean flag) throws midletstatechangeexception {<br/>}</P> <p> protected void pauseapp () {<br/>}</P> <p> protected void Startapp () throws midletstatechangeexception {<br/> display. getdisplay (this ). setcurrent (New testpointcanvas (); <br/>}</P> <p>}</textarea>