The J2ME Mobile Information Device Profile
Using the State Pattern
|
Prof. David Bernstein
James Madison University
|
|
Computer Science Department
|
bernstdh@jmu.edu
|
Motivation
- An Observation:
- People often write
MIDlet
s 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
j2meexamples/src/gui/AbstractScreen.java
The Context/Controller
j2meexamples/src/gui/ApplicationContext.java
A Complete Example
An Overview
A Complete Example (cont.)
The MIDlet
j2meexamples/src/phoneycall/PhoneyCall.java
A Complete Example (cont.)
The AbstractState
for this Example
j2meexamples/src/phoneycall/AbstractState.java
A Complete Example (cont.)
The Initial State
j2meexamples/src/phoneycall/CallCountScreen.java
A Complete Example (cont.)
The Next Two States
j2meexamples/src/phoneycall/SingleCallScreen.java
j2meexamples/src/phoneycall/MultipleCallScreen.java
A Complete Example (cont.)
The Next State
j2meexamples/src/phoneycall/CallersScreen.java
A Complete Example (cont.)
The Last State
j2meexamples/src/phoneycall/WaitingScreen.java
There's Always More to Learn