Boa Noite Pessoal,
Estou fazendo uma aplicação para eu começar aprender J2ME e não estou conseguindo desenvolve-la.A minha aplicação é o seguinte o usuário pensará entre um numero de 0 a 50,verificara se o numero que está pensado está num determinado quadro de numeros e responderá se sim ou não de acordo com a resposta fornecida pelo usuário no final exibira o nº que o usuário está pensando.blz entederam meu programinha tá agora segue o codigo do mesmo:
[code]import javax.microedition.lcdui.;
import javax.microedition.midlet.;
public class MMagica extends MIDlet implements CommandListener
{
Display tela;
int aux=0,aux2=0,selecionado=0;
Alert resultado;
String cmagica,teste;
Command sair,entrar,conf;
List exclusiva;
NossaCanvas canvas;
class MyThreadClass extends Thread
{
}
MyThreadClass myThread = new MyThreadClass();
//this.myThread.start();
{
//this.cmagica = "" + this.canvas.magica;
//this.cmagica = new Integer(this.canvas.magica).toString();
//teste = this.cmagica
}
public MMagica ()
{
teste = "oi";
String[] exclusivaElementos = {"Está na tela anterior","Não está na tela anterior"};
this.tela=Display.getDisplay(this);
this.resultado = new Alert("Confirmação","TESTE",null,AlertType.CONFIRMATION);
this.resultado.setTimeout(8500);
this.sair = new Command("Sair",Command.EXIT,0);
this.conf = new Command("Confirmar",Command.SCREEN,1);
this.entrar = new Command("Entrar",Command.SCREEN,1);
this.exclusiva = new List("O seu nº:",Choice.EXCLUSIVE,exclusivaElementos,null);
this.canvas = new NossaCanvas();
this.exclusiva.addCommand(this.sair);
this.exclusiva.addCommand(this.conf);
this.canvas.addCommand(this.sair);
this.canvas.addCommand(this.entrar);
this.exclusiva.setCommandListener(this);
this.canvas.setCommandListener(this);
}
public void startApp()
{
this.tela.setCurrent(this.canvas);
}
public void pauseApp()
{
}
public void destroyApp(boolean i)
{
}
public void commandAction(Command c, Displayable d)
{
if (c == this.sair)
{
this.destroyApp(true);
this.notifyDestroyed();
}
if (c == this.entrar)
{
if (aux == 0)
{
this.canvas.inicio=true;
this.canvas.repaint();
}
if (aux == 1)
{
this.canvas.pensar1=true;
this.canvas.repaint();
}
if ((aux > 1) && (aux < 9))
{
this.tela.setCurrent(this.exclusiva);
}
//if (aux >= 8)
//{
//this.canvas.fim=true;
//this.tela.setCurrent(this.resultado);
//}
aux++;
}
if (c == this.conf)
{
selecionado = this.exclusiva.getSelectedIndex();
if (aux2 == 0)
{
switch (selecionado)
{
case 0:
this.canvas.magica = this.canvas.magica + 1;
break;
case 1:
break;
}
this.canvas.pensar2=true;
this.tela.setCurrent(this.canvas);
this.canvas.repaint();
}
if (aux2 == 1)
{
switch (selecionado)
{
case 0:
this.canvas.magica = this.canvas.magica + 2;
break;
case 1:
break;
}
this.canvas.pensar3=true;
this.tela.setCurrent(this.canvas);
this.canvas.repaint();
}
if (aux2 == 2)
{
switch (selecionado)
{
case 0:
this.canvas.magica = this.canvas.magica + 4;
break;
case 1:
break;
}
this.canvas.pensar4=true;
this.tela.setCurrent(this.canvas);
this.canvas.repaint();
}
if (aux2 == 3)
{
switch (selecionado)
{
case 0:
this.canvas.magica = this.canvas.magica + 8;
break;
case 1:
break;
}
this.canvas.pensar5=true;
this.tela.setCurrent(this.canvas);
this.canvas.repaint();
}
if (aux2 == 4)
{
switch (selecionado)
{
case 0:
this.canvas.magica = this.canvas.magica + 16;
break;
case 1:
break;
}
this.canvas.pensar6=true;
this.tela.setCurrent(this.canvas);
this.canvas.repaint();
}
if (aux2 == 5)
{
switch (selecionado)
{
case 0:
this.canvas.magica = this.canvas.magica + 32;
break;
case 1:
break;
}
this.tela.setCurrent(this.resultado);
//this.canvas.pensar7=true;
//this.tela.setCurrent(this.canvas);
//this.canvas.repaint();
}
aux2++;
}
}
}
class NossaCanvas extends Canvas
{
int magica=0;
Image logo,pp,img1,img2,img3,img4,img5,img6,img7;
boolean inicio=false,pensar1=false,pensar2=false,pensar3=false,pensar4=false,pensar5=false,pensar6=false,pensar7=false,fim=false;
public NossaCanvas()
{
try
{
logo=Image.createImage("/MMagica.png");
pp=Image.createImage("/pp.png");
img1=Image.createImage("/0.png");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void paint(Graphics g)
{
g.fillRect(0,0,this.getWidth(),this.getHeight());
g.setColor(255,255,255);
g.drawImage(logo,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
if (inicio)
{
g.drawImage(pp,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
if (pensar1)
{
g.drawImage(img1,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
if (pensar2)
{
g.drawImage(img1,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
if (pensar3)
{
g.drawImage(img1,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
if (pensar4)
{
g.drawImage(img1,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
if (pensar5)
{
g.drawImage(img1,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
if (pensar6)
{
g.drawImage(img1,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
if (fim)
{
g.drawImage(img1,this.getWidth()/2,this.getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);
}
}
}[/code]
Agora a minha duvida como vou fazer para exibir no final o valor da variavel Magica será que terei que fazer um thread,como faço ,alguma sugestão para melhorar meu codigo,preciso de ajuda pois estou fascinado em desenvolver em aplicações para celular quero apreder muito,conto com a ajuda de vcs.
Desde já agradeço