import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Graphics; public class NewClass extends Canvas implements CommandListener, Runnable { private Command c1 = new Command("Add New", Command.OK, 1); private Command c2 = new Command("Destroy", Command.BACK, 1); private Command c3 = new Command("Exit", Command.EXIT, 1); private boolean z; private int num = 0; protected void paint(Graphics g) { this.addCommand(c1); this.addCommand(c2); this.addCommand(c3); this.setFullScreenMode(false); this.setCommandListener(this); g.setColor(0); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.setColor(0xff00); g.drawString(""+Thread.activeCount(), 5, 5, 0); g.setColor(0xff0000); g.drawString("I'm alive "+num+" :)", 5, 55, 0); this.repaint(); } public void commandAction(Command c, Displayable d) { if(c==c1) { z = true; Thread t = new Thread(this); t.start(); } if(c==c2) { z = false; } if(c==c3) { JavaME.midlet.notifyDestroyed(); } } public void run() { while (z) { num++; try { Thread.sleep(1); } catch (java.lang.InterruptedException zxz) {}; } } }