[BB] Aplicación Simple Con un Menu

Una aplicación muy, pero muy simple en la cual crea un menu y una opcion. y el evento muestra un Mensaje.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
 
//Main Class
public class FirstApp extends UiApplication
{
	//Globals || Globales
	private RichTextField g_Output;
 
	//Constructor || Constructor
	public FirstApp()
	{
		//Create the Screen || Creamos la pantalla.
		pushScreen( new FirstAppScreen() );
	}
 
	//Start Function || Funcion donde Arranca la Aplicación
	public static void main(String[] args)
	{
		new FirstApp().enterEventDispatcher();
	}
 
	//Class where process all the GUI Thread
	private class FirstAppScreen extends MainScreen
	{
		//Constructor || Constructor
	    FirstAppScreen()
	    {
	    	//We add the menu Variable
	    	addMenuItem( _hola );
 
	    	//Set Title || Seteamos un titulo para nuestra Aplicacion
	        setTitle( "FirstApp" );
 
	        //We Create a RichTextField to set the Debug's Messages.
	        g_Output = new RichTextField();
	        add( g_Output );
	    }
 
	    //This is a Special function of the MenuItem
	    private MenuItem _hola = new MenuItem( "Seleccioname!!" , 10, 10)
	    {
	    	//Run is called then I select this item on menu.
	    	//Esta funcion es llamada cuando se selecciona la opcion del menu.
	    	public void run()
	    	{
	    		//Show the Debug Message. || Mostramos el mensaje.
	    		message("Debug: Se apreto: " + _hola.toString() );
	    	}
	    };
 
	    //a esto no le des bola.. xD
	    public boolean onSavePrompt()
	    {
	    	return true;
	    }
 
	    //Overwrite function. that is called when the App need to close.
	    //Funcion sobre escrita, es llamada cuando se quiere cerrar la aplicacion.
	    public void close()
	    {
	    	//Show a Dialog || mostramos un dialogo antes de cerrar
	        Dialog.alert( "Chau Reymon!" );
 
	        //Call the MainScreen close
	        //Como sobre escribimos la funcion, necesitamos llamar a la funcion base.
	        super.close();
	    }
	}
 
	//A Simple function to make it more easy the Debug's Messages.
	//Una simple funcion para ayudarnos a Debugear(xD) la Aplicacion.
    private void message(final String msg)
    {
        invokeLater(new Runnable()
        {
            public void run()
            {
            	if( g_Output.getTextLength() > 0 )
            	{
            		g_Output.setText(g_Output.getText() + "\n" + msg);
            	}
            	else
            	{
            		g_Output.setText( msg );
            	}
            }
        }); // Don't forget the ;
    }
}

Deja un Comentario por Ayuda.

You can skip to the end and leave a response. Pinging is currently not allowed.

One Response to “[BB] Aplicación Simple Con un Menu”

  1. Bolivar dice:

    Que pograma tengo que utilizar para crear la aplicacion. Gracias

    Un Saludo

    Excelente

Leave a Reply