X

This Blog covers the latest Java technology for small devices and security in the IoT, mobile, ID and Payment

Using Line User Interface with Oracle Java ME Embedded 8.1 on STMicroelectronics Evaluation board

Oracle Java
ME Embedded 8.1 Developers Preview
for ST Micro Evaluation board has been
recently released. 

As
I mentioned in my previous post, one of the release additions is
a Line User Interface (LUI) API hardware implementation. LUI is an optional API
of MEEP (JSR 361), which enables rendering text information on a
display. In Java ME Embedded 8.0 this functionality was supported only by Java ME SDK Emulator and now it is possible to use a hardware
display to implement a simple user interaction in Java ME Embedded
applications. 

Java
ME SDK 8.1 update includes a very good LUI sample. The sample is an
on-screen text menu navigated by a built-in joystick. The menu has 12 items,
several nested items, and a status line reflecting a current user choice.  Code of the sample is accompanied very detailed comments, which can definitely helps start developing interactive
applications very fast.

Below
is a basic example that demonstrates the use of the built-in screen on STM32429I-EVAL board with Java ME Embedded and LUI API.

 Happy Java coding for embedded.

import java.util.Iterator;
import javax.microedition.lui.Display;
import javax.microedition.lui.DisplayColor;
import javax.microedition.lui.DisplayListener;
import javax.microedition.midlet.MIDlet;
public class LUIDemo extends MIDlet implements DisplayListener {@Overridepublic void startApp() {// Get Display instance and configure it
        Iterator<Display> displays = Display.getDisplays(false);
        Display myDisplay = displays.next();// Assign a state change listner to Display instance
        myDisplay.addDisplayListener((DisplayListener) this);//as soon as the hardware display will be assigned to myDisplay instance//hardwareStateChanged method will be invoked with newState = true synchronized (myDisplay) {try {// Assign hadware display to myDisplay 
                myDisplay.setHardwareAssigned(true);// Assigning display may take some time,// so that we need to wait the operation acomplishement 
                myDisplay.wait();// Now myDisplay has HW display assigned and we can use it} catch (InterruptedException ex) {
                ex.printStackTrace();}}//Display.setText is overloaded method. //In the example below the text "Hello world" is blinking.
        myDisplay.setText(0, "Hello world", true, false);
        myDisplay.setText(1, "I love programming Java ME Embedded on STM32429EVAL");}@Overridepublic void destroyApp(boolean unconditional) {}@Override// hardwareStateChanged method is invoked as the hardware display is assigned or unassignedpublic void hardwareStateChanged(Display d, boolean newState) {//Setting up assigned hardware display
        d.setLightingColor(new DisplayColor(0xFF, 0, 0));
        d.setCurrentTextColor(new DisplayColor(0, 0, 0xFF));
        d.setBackgroundColor(new DisplayColor(0, 0, 0));// notify all threads are waiting for Display Objectsynchronized (d) {
            d.notifyAll();}}@Overridepublic void displayAdded(Display d) {}@Overridepublic void displayRemoved(Display d) {}
}

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services