import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.util.*; import java.io.*; public class Midlet extends MIDlet implements CommandListener,Runnable { private Command exitMidlet; private Command playAgain; private Thread thread; private Random r; private int a; private Form form; private Display display; public void Midlet() { exitMidlet = new Command("Exit", Command.EXIT, 1); playAgain = new Command("Again", Command.SCREEN, 2); r = new Random(); a = r.nextInt(10); form = new Form(""); form.addCommand(exitMidlet); form.addCommand(playAgain); form.setCommandListener(this); form.append("Загаданное число - "+ a); display=Display.getDisplay(this); thread=new Thread(this); //создаем тред(паралл.метод) } public void run(){ try{ thread.sleep(1000); }catch(Exception e){} } public void startApp(){ display.setCurrent(form); thread.start(); //запускаем тред } public void pauseApp() { } public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { if(c == exitMidlet) { destroyApp(false); } if(c == playAgain) { a = r.nextInt(10); form.deleteAll(); form.append("Загаданное число - "+ a); } } }