Colocando imagens em uma mensagem de Alerta – J2ME

Veja nesta dica como inserir imagens nas suas mensagens de alerta para os dispositivos móveis.

Colocando imagens em uma mensagem de Alerta – J2ME

Veja nesta dica como inserir imagens nas suas mensagens de alerta para os dispositivos móveis.

   

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class AlertImage extends MIDlet
{

private Display display;    
private Alert myAlert = null;

public AlertImage() {
}

public void startApp() {

display = Display.getDisplay(this);
TextBox t = new TextBox("Hello MIDlet""Hello J2MECamp!"2560);
display.setCurrent(t);
System.out.println( "Gonna create Alert.." );
createAlert();
}


private void createAlert() 
{
myAlert = new Alert("MIDlet Alert");
String[] alertString = { " Alert String" };
myAlert.setTimeout(Alert.FOREVER);
// Adiciona uma imagem na Alerta
if (display.numColors() > 2
{
String icon = (display.isColor()) ?"/JavaPowered-
                         
8.png" "/JavaPowered-2.png";
try
{
Image image = Image.createImage( icon );
if (image != null)
{
myAlert.setImage(image);
System.out.println( "Image created and added to alert.. " );
}
else
{
System.out.println( "No Image created... " );
}
// Adiciona um texto na Alerta
for int i = 0; i < alertString.length; i++ ) {
myAlert.setString( alertString[i] );
}
if ( myAlert != null ) {
display.setCurrent( myAlert );
}
}
catch( Exception e )     {
System.out.println( "Exception in CreateImage() " );
}
}
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

}

Ebook exclusivo
Dê um upgrade no início da sua jornada. Crie sua conta grátis e baixe o e-book

Artigos relacionados