- Forward


The J2ME Mobile Information Device Profile
Using the State Pattern


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Motivation
Back SMYC Forward
  • An Observation:
    • People often write MIDlets that are the CommandListener for multiple Displayable objects
  • The Problem:
    • This leads to a complicated nested if statement
  • The Solution:
    • Think of each "screen" as a state
    • Use the State Pattern
A Generic Abstract State
Back SMYC Forward
j2meexamples/src/gui/AbstractScreen.java
 
The Context/Controller
Back SMYC Forward
j2meexamples/src/gui/ApplicationContext.java
 
A Complete Example
Back SMYC Forward

An Overview
phoneycall

A Complete Example (cont.)
Back SMYC Forward

The MIDlet

j2meexamples/src/phoneycall/PhoneyCall.java
 
A Complete Example (cont.)
Back SMYC Forward

The AbstractState for this Example

j2meexamples/src/phoneycall/AbstractState.java
 
A Complete Example (cont.)
Back SMYC Forward

The Initial State

j2meexamples/src/phoneycall/CallCountScreen.java
 
A Complete Example (cont.)
Back SMYC Forward

The Next Two States

j2meexamples/src/phoneycall/SingleCallScreen.java
 
j2meexamples/src/phoneycall/MultipleCallScreen.java
 
A Complete Example (cont.)
Back SMYC Forward

The Next State

j2meexamples/src/phoneycall/CallersScreen.java
 
A Complete Example (cont.)
Back SMYC Forward

The Last State

j2meexamples/src/phoneycall/WaitingScreen.java
 
There's Always More to Learn
Back -