AWT for MI | Structure of MDK Examples

 

Developing AWT Applications for MI

AWT application development for MI is fairly straight-forward - any standard AWT application can easily be MI-enabled.

Development of AWT application for MI requires the installation of MI for AWT. See FAQ to find out, how MI for JSP and MI for AWT can be installed on the same PC or Notebook.

 

The main class of the AWT application must implement the interface com.sap.ip.me.api.runtime.awt.AwtApplication. This interface inherits certain methods from com.sap.ip.me.api.runtime.Application and add two additional methods:

Method

Description
initApplication()

This method is activated when the application is activated in the MI AWT window (Application -> myApplication) for the first time after the MI framework has been started.

This method is used to set up the application, like initializing variables. Subsequent activations of the application from the MI AWT window skip this method and call only the activateApplication() method.

activateApplication() This method is activated when the application is activated in the MI AWT window (Application -> myApplication) every time, except when the application is already active. This method contains the code that is needed to run the application.
deactivateApplication() This method is called when the user selects another application in the MI AWT window (Application -> myOtherApplication). This method can be used to do final steps before the application is terminated.
destroyApplication() This method is called when the user logs off from the MI. This method can be used to do final steps before the application is terminated - similar to method deactivateApplication().
getApplicationName() Returns the technical name of the MI application. The name specified has to match the archive name and the application name
specified in the MI WebConsole.
getRootPanel() The method getRootPanel returns the area/container which will be the main area of the AWT-Home. It doesn't necessarily have to be a Panel which is passed, it could also be a sub-class of Panel, for example an Applet.
actionMenuItem(MenuItem item)

This method is activated when the user selects a menu item in the MI AWT window (for example Action -> Sync). With the getLabel() method of the MenuItem object the selected item can be identified.

Example:

if (item.getLabel().compareTo("Exit") == 0) {
....
} 

 

Basic AWT Example

We take the TicTacToe game that Sun Microsystems furnishes as a straight-forward AWT example implementation as part of the JDK and convert it to a MI AWT application.

Click here, to see the original TicTacToe coding from Sun Microsystems.
Click here, to see the MI-enabled version of the code.
Click here, to download the application's jar-file. You have to deploy the application with the MI Web Console.

 

The difference between the two applications are the following:

  1. Main class is moved to a different package com.sap.ip.me.awtapps.demo (optional).
  2. Two import statements were added:
    import com.sap.ip.me.api.runtime.awt.AWTConfigurationUI;
    import com.sap.ip.me.api.runtime.awt.AwtApplication;
  3. The main class implements the interface com.sap.ip.me.api.awt.AwtApplication and therefore contains implementations for the methods in the table above. The implementations for initApplication(), activateApplication(), deactivateApplication() and destroyApplication() are not needed for this example and stay empty. The getApplicationName()method has to be implemented. We define a string variable MI_APPLICATION_NAME and assign the name for the MI application to it. The getApplicationName()method returns this string. When you create a JAR file with the export feature of the MDK plug-in, the MDK plug-in makes sure, that the JAR file has the correct name. When you upload the JAR to the MI WebConsole you have to specify this application name as well.

Access to the MI AWT User Interface

Other useful static methods includes the class AWTConfigurationUI in the same package:

Method

Description
public static void setMenu(Menu menu) Insert in the Mobile Infrastructure framework menu bar the application menu .
public static void setMenuVisible(boolean visible) Show and hide the menu bar.
public static void goHome() Shows the welcome/home screen of the Mobile Infrastructure.

 

Next Steps

The MDK examples use a structure that meets the requirements of the MI style guide and has a structure that can easily adopted to user requirements. See section Structure of MDK Examples for further details.