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; public void startApp() { exitMidlet = new Command("Exit", Command.EXIT, 1); playAgain = new Command("Again", Command.SCREEN, 2); Random r = new Random(); int a = r.nextInt(10); Form form = new Form(""); form.addCommand(exitMidlet); form.addCommand(playAgain); form.setCommandListener(this); form.append("Загаданное число - "+ a); Display.getDisplay(this).setCurrent(form); thread=new Thread(this); //создаем тред(паралл.метод) thread.start(); //запускаем тред } public void run(){ try{ thread.sleep(1000); }catch(Exception e){} } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { if(c == exitMidlet) { destroyApp(false); notifyDestroyed(); } if(c == playAgain) { Random r = new Random(); int a = r.nextInt(10); Form form = new Form(""); form.append("Загаданное число - "+ a); Display.getDisplay(this).setCurrent(form); } } }