The Wayback Machine - https://web.archive.org/web/20220410084205/https://www.scribd.com/document/492588742/lab-3
You are on page 1of 3

Mobile Programming Laboratory Manual 1 Addis Ababa University, Institute of Technology,

February 2015, - Prepared by Eyob Gebretisnae. Center of Information Technology & Scientific Computing

Lab Three
Java ME UI Part Two (Alert and Command)
Objective:

 To be familiar with Java ME User Interface commands

 To Practice Ticker

 To understand Alert in Java ME and to Practice all possible alerts with commands

Put Your Hand for Exercise

Task 1: Creating a Mobile project called lab3 using netbeans

Task 2: Create a TextBox with three commands


 Create a TextBox object inside startApp() method using a Displayable interface
Displayable d=new TextBox("Comment","",20,TextField.ANY);
 Create Three commands objects namely Exit, Stop, Help, assign the priority 0-2
Command exit=new Command("Exit",Command.EXIT,0);
Command help=new Command("Help",Command.HELP,1);
Command stop=new Command("Stop",Command.STOP,2);
 Add all commands to TextBox
d.addCommand(stop);
d.addCommand(help);
d.addCommand(exit);
 Write a method setCommandListener. The listener can be created as an anonymous inner
subclass in startApp method.
Call the notifyDestroyed(); method on commandAction() method to stop when the
command is executed.
Mobile Programming Laboratory Manual 1 Addis Ababa University, Institute of Technology,
February 2015, - Prepared by Eyob Gebretisnae. Center of Information Technology & Scientific Computing

Task 3: Create a Ticker

 Create a Ticker
Ticker ticker = new Ticker("This is the ticker message!");
 Add a ticker to the TextBox using setTicker method
d.setTicker(ticker);
 Run the application

Task 4: Create a ExersisAlert Project

 Declare a variable of Display class as instance field in MIDLet application


Display d;
 Create an instance of alert inside startApp() method
Alert alert = new Alert("Sorry", "I'm sorry, Eyob...",
null, null);
 Create an instance of display and add the alert instance to display object
d.getDisplay(this).setCurrent(alert);
 Run the application
Mobile Programming Laboratory Manual 1 Addis Ababa University, Institute of Technology,
February 2015, - Prepared by Eyob Gebretisnae. Center of Information Technology & Scientific Computing

Exercise:

Create, TwoAlerts, shows both types of alert. It features a main TextBox that is displayed when
the MIDlet begins. Two commands Go and About, provide access to the alerts. The Go
command shows a timed alert that contains a message about a fictitious network error. The
About command displays a modal alert that could contain copyright information. A third
command, Exit, provides a way to exit the MIDlet. Keep in mind that all three commands may
not fit on the screen; some of them may be accessible from a secondary menu.

Code Ref: Use Example on Handout Two

You might also like