Prezados amigos,
Estou usando o Eclipse com WTK e implementei uma função bem básica que exibe uma imagem de inicialização, usando calsses Alert e Image.Gostaria de saber como posso implementar uma função que abre imagens aleatórias(umas 3) quando uma aplicação é startada no celular, por exemplo, qdo inico uma vez ele exibe imagem A, depois na outra inicialização exibe imagem B e em outra inicialização exibe a imagem C e assim por diante, Acho q tem usar a classe random, mas não sei como utilizá-la
Se possivel, gostaria que alguem tbem me fornecesse códigos para praticar e aprender bem J2ME, pois sou novatão ao extremo.
Antecipadamente agradeço!!!
[code]private final short intervalMin = 0;
private final short intervalMax = 3;
Random r = new Random();
short nr =(short) ( (r.nextInt() >>> 1) % (intervalMax + 1 - intervalMin) + intervalMin ); [/code]
daí voce faz uns ifs… se for 1 tal mensagem… se for 2…
pode ser short ou byte ou int … depende da sua necessidade.
Até Mais!

Valeu aí amigo, funcionou bem para o código abaixo:
[size=9]import java.io.IOException;
import java.util.Random;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TesteMIDlet extends MIDlet implements CommandListener
{
private Display display;
private TextBox txt1;
private TextBox txt2;
private Command cmExit;
public TesteMIDlet ()
{
display = Display.getDisplay(this);
cmExit = new Command("sair",Command.EXIT,1);
txt1 = new TextBox("Bem vindo","Alo Mundo - Java!", 20, TextField.ANY);
txt2 = new TextBox("Welcome","Hello World - Java!", 20, TextField.ANY);
txt1.addCommand(cmExit);
txt1.setCommandListener(this);
txt2.addCommand(cmExit);
txt2.setCommandListener(this);
}
public void startApp()
{
String nome_img = "/imagem1.png";
Image img = null;
String nome_img2 = "/imagem2.png";
Image img2 = null;
try {
img1 = Image.createImage(nome_img);
img2 = Image.createImage(nome_img2);
}catch (IOException e) {
e.printStackTrace();
}
final short intervalMin = 1;
final short intervalMax = 2;
Random r = new Random();
short number=(short) ( (r.nextInt() >>> 1) % (intervalMax + 1 - intervalMin) + intervalMin );
if ( number == 1 ) {
Alert alert1 = new Alert ("teste1","",img1,AlertType.INFO);
alert1.setTimeout(2000);
display.setCurrent(alert1,txt1);//teste1
}
if ( number == 2 ) {
Alert alert2 = new Alert ("teste2","",img2,AlertType.INFO);
alert2.setTimeout(2000);
display.setCurrent(alert2,txt2);
}//teste2
}
public void pauseApp()
{};
public void destroyApp(boolean inconditional)
{};
public void commandAction ( Command c, Displayable s)
{
if (c==cmExit)
{
destroyApp(false);
notifyDestroyed();
}
}
}[/size]
Um grande abraço aí!!!
[color=“red”]Utilize as tags BBCode [ code] e [ /code] para deixar seu código identado
[/color]