b k ; < i m e g i < c f w h v f i a -...

174
МИНИСТЕРСТВО ОБРАЗОВАНИЯ И НАУКИ РОССИЙСКОЙ ФЕДЕРАЦИИ Государственное образовательное учреждение высшего профессионального образования «НАЦИОНАЛЬНЫЙ ИССЛЕДОВАТЕЛЬСКИЙ ТОМСКИЙ ПОЛИТЕХНИЧЕСКИЙ УНИВЕРСИТЕТ» В.В. Соколова РАЗРАБОТКА МОБИЛЬНЫХ ПРИЛОЖЕНИЙ Рекомендовано в качестве учебного пособия Редакционно-издательским советом Томского политехнического университета Издательство Томского политехнического университета 2011

Upload: buikhanh

Post on 08-Sep-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • ..

    -

    2011

  • 2

    621.396.21(074.8)

    32.884.173

    594

    594

    .. : / ..

    ; . :

    - , 2011.

    175 .

    . -

    .

    Java -

    J2ME Android.

    230100

    ,

    230113 .

    621.396.21(074.8)

    32.884.173

    , 2011

    .., 2011

    .

    , 2011

  • 3

    ............................................................................................................... 5 1. .......................................... 7 1.1. ....................................................... 7 1.2. ............................. 14 1.2.1. ............................................................ 14 1.2.2. ............................................................. 16 1.2.3. ............................................... 17 1.3. ................................................................. 19 1.3.1. GSM ............................................................................................... 20 1.3.2. Wi-Fi .......................................................................................... 24 1.3.3. C IEEE 802.11 .................................................. 25 1.3.4. Bluetooth ....................................................................................... 26 1.3.5. ............................................................... 28 1.3.6. .............................................................. 29 1.4. ........................................................................... 30 1.4.1. Android ....................................................................................... 31 1.4.2. Java 2 Micro Edition (J2ME) .......................................................................... 34 1.4.3. ........................................................ 36 ................................................................................ 51 2. JAVA 2

    MICRO EDITION .............................................................................................................. 53 2.1. J2ME ................................................................ 53 2.1.1. Connected, Limited Device Configuration ........................... 55 2.1.2. Connected Device Configuration .......................................... 58 2.1.3. Foundation Profile .......................................................................... 59 2.1.4. Personal Profile............................................................................... 61 2.1.5. RMI ................................................................................................. 62 2.2. Mobile Information Device Profile ............................................... 63 2.2.1. .......................................................................... 65 2.2.2. MIDP ..................................................... 68 2.2.2.1. ............................................................... 68 2.2.2.2. ................................................................................................ 72 2.2.2.3. ....................................................................... 73 2.2.2.4. ..................................................................................................... 74 2.2.2.5. Pacpe ........................................................................... 78 2.2.3. MIDP ................... 80 2.2.4. API MIDP .................. 83 2.3. .................................................................. 104 2.4. .............................................................................. 111 .............................................................................. 126 3. ANDROID ............ 127 3.1. ........................................................ 127 3.1.1. Android (AVD) ............................ 128

    3.1.2. Android- ............................................................ 128 3.1.3. Android- ...................................................................... 128

  • 4

    3.1.4. Android- ................................................................ 134 3.1.5. Android GUI ........................................................................ 138

    3.2. ............................................... 139 3.2.1. View ................................................................................................ 139 3.2.2. .................................................................................................. 140

    3.2.3. ......................................................................... 147 3.2.4. ............................... 147 3.2.5. ............................................................................................ 155

    3.3. Activities Intent ................................................. 159 3.3.1. Intent ............................................................................................. 160

    3.3.2. Activity ..................................................................... 162 3.3.3. Intent ..................................................................... 162

    .............................................................................. 171 ............................................. 172

  • 5

    .

    ,

    -

    .

    .

    . -, ,

    , -

    (), -

    ,

    . -, -

    (), -

    -

    . , -,

    , -

    -

    -

    (, Wi-Fi), (

    GPRS, UMTS, WiMax) .

    , -

    .

    -

    , -

    . -

    ,

    .

    , -

    J2ME 70 %. , , -

    (BlackBerry,

    Android, iOS ..), -

    , .

    , .

    -

    , . , -

  • 6

    SMS-

    . , , -

    . -

    ,

    , -

    .

    -

    .

    -

    -

    . -

    ,

    .

    Java ,

    J2ME,

    Android.

  • 7

    1.

    , -

    -

    -

    .

    -

    . -

    .

    - -

    , .

    1.1.

    :

    ;

    ;

    ;

    ();

    . , -

    . -

    ,

    ().

    ,

    . 75 %

    . -

    , -

    (WAP) -

    .

    (

    , 4 12 ) 12-

    . -

    -, .. , -

    , . -

  • 8

    , -

    ,

    . ,

    : , , -

    . -

    , .

    , , -

    ,

    .

    ,

    .

    , , ,

    (WTA), WAP, -

    . , -

    .

    160 ,

    . -

    . -

    -

    (),

    ,

    ().

    , ,

    .

    . -

    .

    , -

    . , -

    . , RIM Motorola -

    , ,

    . -

    , J2ME . -

    RIM Blackberry

    Motorola Timeport -

    -.

    , -

    QWERTY,

    .

  • 9

    ,

    , -

    . WAP -

    WML,

    HTML-.

    , ,

    .

    ,

    .

    , -

    . -

    , . -

    ,

    , ,

    .

    , , -

    -.

    , , ,

    .

    , -

    ,

    . -, , , ,

    .

    -

    , .

    - ,

    , .

    .

    -

    , . ,

    , -

    .

    ,

    , ,

    .

    -

    . OTA-.

    -

    , -

    . -

    ( $ 1

  • 10

    $ 5). .

    -

    Java 2 Micro Edition (J2ME).

    -

    J2ME.

    -

    -

    . ,

    HTC, Nokia, Sony Ericsson, Motorola, ,

    .

    , -

    .

    , , -

    .

    -

    . -

    .

    12- -

    .

    640200 320240.

    . ,

    ,

    -. -

    WML HTML .

    , , -

    .

    , ,

    .

    , . -

    -

    .

    Android, Symbian OS, Palm OS, Pocket PC Phone Edition Windows

    Mobile 7. J2ME .

    ()

    , , -

    .

    , (), -

    .

    .

  • 11

    ,

    , VGA- (320240).

    /, ..

    .

    -

    . , ,

    , .

    -

    Palm Pocket PC. Palm-

    , ,

    Pocket PC , -

    . -

    -

    . Palm- ,

    , -

    . Palm-, , ,

    , ,

    . , -

    225 .

    Palm- ,

    -

    . Palm- -

    (OS) 8 32 ,

    33 . -

    ,

    . , Java-

    , -

    Java (JVM)

    . Palm-, -

    OS 5.0, -

    ARM-, 206 .

    .

    Pocket PC -

    . 32 64

    X-Scale ,

    400 . -

    Windows CE, ,

    Palm OS.

    . Palm-

  • 12

    , -

    Pocket PC .

    -

    , .

    Palm ,

    ,

    , .

    , ,

    Palm OS -

    .

    Pocket PC

    Palm. ,

    -

    . , ,

    Microsoft Office,

    Microsoft Word Excel. Pocket

    PC , .

    , Pocket PC 3050 % ,

    Palm OS.

    , Palm : Tungsten Zire.

    Tungsten Palm

    .

    -

    . Zire Palm -

    ,

    .

    , -

    .

    . -

    .

    , , , -

    . , ,

    .

    -

    , Palm i705.

    .

    , -.

    -

  • 13

    -

    .

    ,

    ,

    .

    . -

    Windows CE. NET Palm OS 5.0 , -

    -

    , .. -

    , .

    , -

    (). -

    ,

    ,

    ( -

    ). -

    ,

    Android, ,

    .

    , -

    .

    , , -

    :

    , - .

    Windows Mobile.

    , .

    Symbian OS.

    . 1.1 ,

    .

    , -

    ,

    . , -

    , , .

    , -

    .

  • 14

    . 1.1.

    , : -

    2007 Apple iPhone, -

    , -

    , , -

    . , -

    , , -

    .

    1.2.

    1.2.1.

    -

    . -

    . -

    , Treo 600,

    . 1.2 1.3:

    1) ; 2) ; 3) ; 4) ; 5) ; 6) /

    ;

    7) ; 8) (); 9) ;

  • 15

    10) ; 11) QWERTY-; 12) ; 13) ; 14) ; 15) ; 16) ; 17) SIM-; 18) ; 19) ; 20) ; 21) Secure Digital; 22) ; 23) -; 24) ; 25) .

    . 1.2.

    Treo 600 . 1.3.

    Treo 600

    , Treo 600, -

    , . -

    Treo 600 - qwerty-

    . , -

    : -

    , -

    ( , )

    .

  • 16

    ,

    .

    1.2.2.

    , -

    , Advanced RISC Machine (ARM).

    75 %

    32- RISC-,

    . -

    , ARM

    ,

    ().

    ARM Li-

    mited. -

    . , Intel XScale Tex-

    as Instruments OMAP, ARM.

    -

    : ARM7 (. 1.4), ARM9, ARM9E, ARM10, ARM11 SecurCore.

    Intel XScale

    StrongARM.

    ARM-

    :

    Thumb, 16- , -

    32- , -

    32- .

    SIMD ( ), - . , - / 4 .

    DSP, - DSP, 16- 32- .

    Jazelle, Java- .

    Intelligent Energy Manager (IEM), - , .

    . 1.4. -

    ARM7TDMI

    Atmel

  • 17

    TrustZone, - , .

    ARM, - - () , - , . MSM7200 Qual-comm, Windows Mobile. ARM : 400 ARM11 279 ARM9 , - (QDSP5000 QDSP4000). - ATi Imageon 2300 2D 3D , MPEG4 - JPEG . - NAND SDRAM.

    1.2.3.

    : Random access memory (RAM) Read-only memory (ROM).

    (Random access memory, RAM)

    , -

    . RAM .

    -

    , . -

    (, -

    ),

    .

    , -

    . -

    ,

    .

    RAM:

    (SRAM) - . -

    , , -

  • 18

    . , -

    . -

    .

    (DRAM) -

    . , . -

    -

    , .. , , , -

    , .

    ,

    . DRAM -

    , .. .

    (Read-only memory,

    ROM) . -

    , , ROM,

    ( , ).

    , ROM

    ,

    mask () ROM,

    . -

    ,

    . ROM (.. ,

    ) , -

    , -

    , ,

    . , -

    -

    ROM -

    . , -

    .

    , ROM

    -. - (flash-memory) -

    -

    . ,

    ,

    .

    -: NOR NAND. -

    , -

    .

  • 19

    RAM ROM

    . , RAM, ,

    , -

    . ROM , -

    , .. -

    . ,

    ROM. , -

    . , Windows Mobile,

    , ,

    -

    ,

    RAM. , -

    , , .. , ..,

    .

    -: NAND NOR -

    .

    NOR-

    (2 ). NAND ( -

    ). , -

    NAND.

    NAND

    .

    1.3.

    , -

    ,

    ,

    .

    90- -

    Handspring

    Visorphone Ericsson R380 (. 1.5).

    , -

    , -

    , , Pal-

  • 20

    mOS; , EPOC, -

    .

    . 1.5. Ericsson R380

    .

    1.3.1. GSM

    GSM (Global System for Mobile Communications).

    GSM, 82 %

    , 3 212 .

    , ,

    ,

    CDMA FOMA. GSM -

    .

    ,

    ,

    3 (. 1.1).

    1.1

    1G 2G 2.5G 3G

    1970 . 1980 . 1985 . 1990 .

    1984 . 1991 . 1999 . 2002 .

    -

    ,

    9,6 /.

    -

    ,

    -

    (SMS)

    ,

    ,

    2 /

  • 21

    1G 2G 2.5G 3G

    AMPS, TACS,

    NMT .

    TDMA, CDMA,

    GSM, PDC

    GPRS,

    EDGE,

    1xRTT

    WCDMA,

    CDMA2000,

    UMTS

    1,9 / 14,4 / 384 / 2 /

    (1G)

    NMT

    (Nordic Mobile Telephone system).

    1978 (, -

    , , ). NMT -

    453,0457,5 , 180 25 . -

    525

    . 1983 -

    NMT-900 ( NMT-450), -

    900 . -

    ,

    . , NMT -

    . ,

    , ..

    , -

    , .

    (2G) ( -

    , ) . NMT GSM, . , (). , 1G-, , -, .

    , , , (SMS). - GSM ( 9,6 /). - - , , .

  • 22

    (2,5G) -

    GSM- GPRS (General Packet Radio Service). - GPRS - , () . - GPRS GPRS - .

    GPRS -, , . , GPRS . 115 /, , 4050 /, -. .

    EDGE (Enhanced Data rates for GSM Evolution), 2,75G. EDGE GPRS GPRS. GPRS EDGE - , - , GPRS.

    (3G)

    3G

    ,

    , -

    .

    ,

    .

    , -

    3G, , -

    , , -

    (ITU). ITU, -

    , -

  • 23

    , 3G

    IMT-2000 (International Mobile Telecommunications-

    2000). IMT-2000 ,

    , -

    -

    3- . -

    2- 3- .

    ITU , IMT-2000 (3G), , -

    -

    2G

    144 /,

    ( ), 2 /, -

    ( ).

    , 1999 ITU

    IMT-2000,

    ITU-R M.1457. 3G: UMTS (Universal

    Mobile Telecommunications Systems -

    ), ,

    CDMA 2000 (Code Division Multiple Access

    ),

    . ,

    3G: -

    (UMTS) ( CDMA

    CDMA2000, CDMA2000 IX, CDMA2000 IX EvDo).

    -

    .

    UMTS ,

    CDMA, 3G, -

    cdmaOne (IS-95).

    3G: UMTS (Universal

    Mobile Telecommunications Service), CDMA2000 WCDMA (Wide

    CDMA). , -

    , , -

    . -

    2,4 /. ,

    , , , ,

    . -

    .

    3G , ,

    .

  • 24

    3G -

    .

    1.3.2. Wi-Fi

    WLAN- -

    .

    , ,

    (Access Point), -

    Ethernet, .

    WLAN- -

    (Institute of Electrical

    and Electronics Engineers), IEEE.

    IEEE 802.11

    1997 .

    2,4 1 2 /.

    7 -

    .

    , 802.11b (802.11

    High Rate), 1999 .

    11 /, -

    Ethernet. -

    ,

    WLAN.

    1999 -

    Wi-Fi Alliance (Wi-Fi Wireless Fidelity), -

    WLAN-

    .

    Intel, IBM, Cisco, HP, Dell . -

    200 , 1500

    Wi-Fi

    2000 .

    Wi-Fi

    .

    802.11b, WiFi -

    . Wi-Fi

    802.11: a, b g.

  • 25

    1.3.3. C IEEE 802.11

    WLAN-, -

    , ,

    ,

    . -

    IEEE 802.11b, IEEE 802.11g IEEE 802.11a.

    1.2.

    1999 802.11a

    802.11b, ,

    802.11b.

    802.11b -

    DSSS (Direct Sequence Spread

    Spectrum). 14 ,

    25 . -

    . -

    3 . -

    , -

    .

    1.2

    IEEE 802.11

    IEEE 802.11a IEEE 802.11b IEEE 802.11g

    54 / 11 / 54 /

    :

    12 (54 /),

    91 (6 /).

    -

    :

    30 (54 /),

    305 (6 /)

    :

    30 (11 /),

    91 (1 /).

    -

    :

    120 (11 /),

    460 (1 /)

    :

    30 (54 /),

    91 (1 /).

    -

    :

    120 (54 /),

    460 (1 /)

    5

    (5,155,350

    5,7255,825 )

    2,4

    (2,42,4835 )

    2,4

    (2,42,4835 )

    IEEE 802.11b

    11 /,

  • 26

    10 BaseT Ethernet. ,

    WLAN- -

    . -

    .

    802.11a 1999 ,

    2001 . -

    . .

    802.11a OFDM-

    (Orthogonal Frequency Division Multiplexing).

    , -

    . -

    (6, 12 24 /)

    (9, 18, 24, 48 54 /).

    ,

    .

    802.11g 2003 -

    . IEEE 802.11b

    . -

    54 /

    11 / 802.11b. IEEE 802.11b, -

    2,4 , -

    802.11a (OFDM).

    802.11b. , 802.11b 802.11g

    ( 11 /), 802.11g

    11 /

    802.11b.

    WLAN IEEE

    802.11n. , 802.11a 802.11g,

    100 /c 540 /.

    1.3.4. Bluetooth

    Bluetooth , 1998

    : Ericsson, IBM, Intel, Nokia, Toshiba. -

    Bluetooth Bluetooth SIG (Special Interest

    Group), Lucent, Microsoft .

  • 27

    Bluetooth (

    )

    ,

    , -

    Bluetooth .

    Bluetooth . -

    -

    . 2,4 ,

    Bluetooth-,

    10 100 . -

    , , , 10

    ,

    .

    -

    2,45 ;

    , ISM (Industrial, Scientific,

    Medical) ,

    . -

    ,

    .

    : 1.1, 1.2 2.0.

    . 2004

    Bluetooth 2.0 Enhanced Data Rate (EDR), -

    .

    Bluetooth -

    /: class 1 ( 100 ), class 2 ( 10 ) class 3

    ( 1 ). ,

    Bluetooth : -

    10 100 ( -

    ) -

    , . ,

    Bluetooth class 2, class 1,

    10 .

    Bluetooth. Bluetooth -

    ,

    Bluetooth-:

    , Bluetooth, -

    . -

    ,

    Bluetooth-, GAP (Generic Access Profile)

  • 28

    . -

    ,

    : SPP (Serial Port

    Profile),

    SDAP (Service Discovery Application Profile) -

    - GOEP (Generic Object Exchange

    Profile). , Bluetooth-

    ( ) - -

    .

    1.3.5.

    : Ad-Hoc

    Infrastructure Mode. Ad-Hoc

    , ( )

    . -

    .

    WLAN.

    Infrastructure Mode

    , (Access Point). -

    BSS (Basic Service Set) ESS

    (Extended Service Set). BSS -

    , -

    . ESS -

    , ..

    BSS.

    . , -

    -

    .

    WLAN- -

    . :

    1) ( ,

    );

    2) ( -

    );

    3) (Infrastructure Mode Ad Hoc);

    4) .

    ,

    :

    IEEE 802.11a 50 ;

  • 29

    802.11b 802.11g 100 . ( Infrastruc-

    ture ESS)

    .

    1.3.6.

    WLAN-

    , .. -

    .

    -

    , -

    .

    -

    :

    MAC- (Media Access Control ID): - , , -

    .

    .

    WLAN-

    .

    SSID (Service Set Identifier): -

    .

    .

    ,

    .

    802.11

    WEP (Wired Equivalent Privacy ,

    ), -

    RC4. , -

    . -

    40- ,

    64-, 128- 256-. WEP

    , .. -

    .

    , , -

  • 30

    , . -

    .

    WEP WPA (Wi-Fi Pro-

    tected Access), IEEE Wi-Fi Alliance.

    -

    -

    [2].

    WEP -

    TKIP (Temporal Key Integrity Protocol), -

    .

    RADIUS (Remote Authentication Dial-In User Service RADIUS

    ). , -

    , .

    -

    (

    PSK (Pre-Shared Keys)). -

    ,

    . WPA , -

    802.11i. , , , - . WiFi- ( , ) WPA .

    1.4.

    - ( , ), . . .

    Gartner , 2010

    Android 36,1 %.

  • 31

    1.4.1. Android

    Android ,

    34 Open Handset Alliance. SDK -

    API,

    Java Android.

    , - ;

    Dalvik, ;

    WebKit;

    , 2D- 3D- OpenGL ES 1.0;

    SQLite ;

    -, - (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF);

    GSM-;

    Bluetooth, EDGE, 3G Wi-Fi;

    , GPS, . Android

    . 1.6 -

    Android.

    .

  • 32

    . 1.6. Android

    Android -

    , , SMS, -

    , , , .

    Java.

    Android -

    API, .

    -

    ,

    ( -

    , ).

    .

    , :

    , - , , , ,

    web-;

  • 33

    -, - ( )

    ;

    , , - , , ..;

    , - ;

    , - .

    Android C/C++ , -

    Android. -

    Android.

    :

    BSD - C (libc), -

    Linux.

    OpenCORE PacketVideo.

    -, - , -

    MPEG4, H.264, MP3, AAC, AMR, JPG PNG.

    -, 2D- 3D-

    .

    LibWebCore , Android,

    web-.

    SGL 2D- .

    3D- API OpenGL ES 1.0, 3D, -

    , 3D-.

    FreeType .

    SQLite -, .

    Android Runtime

    Android ,

    -

    Java. Android

    Dalvik. Dalvik , -

  • 34

    . Dalvik -

    .dex,

    . -

    , , Java,

    .dex dx

    Android SDK.

    , -

    ,

    Dalvik Linux.

    Linux

    Android, ,

    , , -

    , Linux 2.6. -

    .

    1.4.2. Java 2 Micro Edition (J2ME)

    Java 1995

    Sun Microsystems. , -

    -

    . 1998 Java

    Standard Edition (J2SE), -

    , Enterprise Edition (J2EE), , Micro Edi-

    tion (J2ME), .

    , -

    ,

    ,

    - -

    . Java ME.

    Java , -

    , Java- (JVM Java Virtual Machine). -

    Java -

    , Java-. ,

    , Java-

    .

    Java ME

    KVM Kilobyte Virtual Machine.

    , Java ME, -

    . -

    , JAR Java Archive.

    : .class ( -),

  • 35

    (, ) -, -

    : , , .

    ,

    Java ME API. API, -

    , CDC (Connected Device Configu-

    ration), CLDC (Connected Limited Device Configuration). -

    , CDC, -

    ; CLDC.

    -

    , API, GUI -

    -

    . API Mo-

    bile Information Device Profile (MIDP).

    : MIDP 1.0 2000

    , 2002 -

    MIDP 2.0, .

    , API

    CLDC MIDP.

    Java, -

    (JSR Java Specification Request), -

    API .

    Java ME

    -

    , -

    API. API CLDC MIDP.

    . -

    , .

    , Java 3D

    JSR 184 Mobile 3D Graphics API ( M3G),

    java- JSR 135

    Mobile Media API.

    Java ME

    Java :

    Java ME . -

    Java-, -

    Java ME .

    , Java- -

    , sms Bluetooth -

    , -

    java- .

  • 36

    Java ME . - ,

    . , -

    - .

    Java:

    API. , API ,

    , -

    . Java API

    , -

    .

    CLDC, - API Java SE. API

    , API .

    MIDP 2.0,

    ,

    CLDC.

    : Java SE, - ,

    , Java 3.

    1.4.3.

    -

    (, -

    ) (, , -

    ). .

    , ,

    -, -

    . -

    (. 1.7).

  • 37

    . 1.7. -

    - :

    , .

    -

    .

    , -

    -

    .

    . -

    , -

    .

    . -

    . -

    , ,

    , -

    .

    , ,

    .

    -, -

    .

    .

    -

    . ,

    .

  • 38

    , -

    , [4]. -

    - . -

    ( -

    ).

    , -

    .

    , -

    . ,

    .

    -

    . , , -

    -

    . , -

    .

    , ,

    . ,

    - ,

    .

    -

    .

    , ,

    , . ,

    -

    - , -

    -

    .

    . -

    -

    .

    -

    .

    -

    . ,

    , -

    . ,

  • 39

    -

    (),

    -

    . , -

    , -

    , .

    .

    , -

    , ,

    - (. 1.8).

    (. 1.8).

    ,

    .

    . 1.8.

  • 40

    - -

    (WAP), -

    :

    Web (, HTML, XML);

    WAP (, WML). , -

    Microsoft Pocket Internet Explorer,

    Microsoft Internet

    Explorer Google Chrome. WAP- -

    WML-.

    -

    . , , -

    . , -

    .

    , ,

    , .. -

    . -

    , -

    .

    -

    .

    , , -

    .

    ,

    -

    -

    . ,

    / .

    ,

    .

    .

    ,

    .

    , /

  • 41

    . , -

    , , ,

    (. 1.9).

    . 1.9.

    -

    , -

    -,

    . ,

    -.

    , Microsoft HTTP-,

    . , -

    -, HTTP-

    , ,

    .

    , -,

    (. 1.10). -

    Windows ,

  • 42

    -, -

    Windows.

    . 1.10. -

    , , -

    , - . -

    , . ,

    -

    . -

    ,

    .

    , -

    .

    (. 1.11).

    .

  • 43

    : , .

    : .

    , -

    , . -

    , ,

    -

    .

    . 1.11.

    (. 1.12). -

    .

  • 44

    . 1.12.

    : .

    : ,

    .

    -

    , - -

    .

    , , -

    . ,

    .

    ,

    (. 1.13).

    .

  • 45

    . 1.13.

    : , -

    , .

    : , ,

    , .

    -

    .

    , -

    .

    .

    :

    , .

    , , , . , , , - , - - .

    . , -

  • 46

    , , - . , . - .

    , - , .

    , - . - : .

    , -

    -

    -

    (. 1.14).

  • 47

    . 1.14.

    , -

    , .

    , .

    -

    .

    , -

    ,

    . ,

    . -

    . -

    .

    .

  • 48

    , -

    , . ,

    , -

    .

    . ,

    ,

    (. 1.15).

    . 1.15.

    ,

    ,

    ,

    , ..

    .

  • 49

    -

    , .

    , -

    , , , -

    , 36 . -

    . -

    , -

    .

    ,

    , -, . - . . 1.16 .

    . 1.16.

    , - , . - (, ASP.NET, JSP, HTML) - -, Microsoft Pocket Internet Explorer.

    . , .

    , , . , -

  • 50

    . , - , .

    , ,

    , .. . - . . 1.17 .

    . 1.17.

    , -

    -

    , .

    ,

    .

    -

    .

    . , ,

    .

    .

  • 51

    -

    ,

    . , -

    , , ,

    .

    , , -

    . , -

    , -

    , . , -

    , .

    ,

    .

    , , -

    .

    ,

    . -

    , -

    .

    , -

    -

    , . -

    , (-

    ) ( -

    ) -

    .

    , ,

    . , -

    -

    , -

    , -

    . ,

    - .

    1. .

    2. ?

  • 52

    3. ?

    4. -

    ?

    5. ?

    ?

  • 53

    2.

    JAVA 2 MICRO EDITION

    Java 2 Micro Edition (J2ME) , -

    Java-.

    :

    - , -

    , -

    , .

    , (UI),

    -

    , , -

    , , .

    J2ME,

    ,

    . J2ME -

    .

    2.1. J2ME

    J2ME Java-

    . ,

    ,

    .

    :

    Java,

    Java,

    Java - (API).

    J2ME

    :

  • 54

    1. Connected, Limited Device Configuration (CLDC) -

    .

    2. Connected Device Configuration (CDC) - 2 -

    .

    J2ME -

    . -

    Java,

    , ..

    .

    , , -

    . , -

    -

    Java.

    ,

    Short Message Service (SMS).

    SMS -

    , ,

    ,

    .

    ,

    , , .

    -

    ,

    . -

    , J2ME

    . 2.1 , -

    J2ME.

    . 2.1. J2ME

  • 55

    2.1.1. Connected, Limited Device Configuration

    CLDC ,

    Java . - -

    CLDC ,

    . , -

    , -

    .

    CLDC CDC .

    ,

    . -

    2.2 J2SE.

    . 2.2. CLDC CDC

  • 56

    CDC, CLDC

    Java, -

    Java -

    .

    Java. CLDC -

    Java:

    ;

    ;

    Java.lang.Error .

    -

    Java, -

    CLDC, VM J2SE, -

    . , ,

    CLDC, , -

    . float

    Java.lang.Float CLDC.

    - -

    .

    . ,

    Object.finalized CLDC.

    Java.lang.Error

    CLDC .

    , , -

    .

    , -, -

    .

    -

    . ,

    , , ,

    . , , -

    , -

    . -

    .

    Java . CLDC -

    Java. VM,

    - -

    . , -

    J2SE VM, CLDC.

    , -

    CLDC- . , -

  • 57

    , - ,

    - :

    Java Native Interface (JNI, Java);

    ;

    (reflection);

    (thread daemons);

    ( Object.finalize() CLDC);

    (weak references);

    ( J2SE);

    . -

    . -

    CLDC ,

    ,

    , J2SE .

    , -

    CLDC, Kilobyte Virtual Machine (KVM), -

    ,

    [6]. KVM J2SE VM.

    , -

    , , .

    CLDC , -

    .

    CLDC ,

    , CLDC -

    . 2.1 ,

    CLDC.

    2.1.

    CLDC

    CLDC

    java.io / Java,

    J2SE

    java.lang VM, J2SE

    java.util , -

    J2SE

    javax.microedition.io

    CLDC

  • 58

    Java, , -

    J2SE. , ,

    javax., , -

    Java.

    2.1.2. Connected Device Configuration

    CDC Java, -

    (Compact Virtual Machine) -

    :

    ;

    ;

    ;

    ;

    . , CVM

    :

    ;

    ;

    Java (ROM);

    ;

    ;

    (RTOS);

    Java ;

    Java 1.3, ,

    Java .

    CDC API.

    Java:

    java.lang Java;

    java.util Java;

    java.net Universal Datagram Protocol (UDP)

    / (I/O);

    java.io / Java;

  • 59

    java.text -

    ;

    java.security

    .

    API -

    (Software

    Development Kit (SDK)) Java 2. -

    Java 2 SDK. 2.2

    , CDC.

    2.2.

    CDC

    CDC

    java.io /

    java.lang

    java.lang.ref

    java.lang.reflect ,

    ( )

    java.math

    java.net

    java.security

    java.security.cert

    java.text

    java.util

    java.util.jar Java (JAR)

    java.util.zip ZIP

    javax.microedition.io

    CDC

    2.1.3. Foundation Profile

    J2ME. , -

    , .

    . , -

    J2ME.

  • 60

    . , API. -

    J2ME CDC, Foundation, -

    J2SE 1.3. -

    Java Community Process, ,

    .

    Foundation J2SE, 2.3.

    2.3.

    Foundation

    Foundation

    java.lang Java.

    java.util zip

    J2SE.

    Java.net TCP/IP HTTP-.

    java.io /.

    java.text

    .

    java.security .

    , java.awt (Abstract

    Window Toolkit, AWT) java.swing ( Swing), -

    API (GUI), -

    . GUI, -

    . -

    . J2ME, ,

    .

    GUI Foundation -

    -

    , , -

    , , -

    J2ME, CLDC.

    , -

    ,

    .

  • 61

    2.1.4. Personal Profile

    Personal Java

    Community, JSR-62.

    Personal AWT.

    , , -

    Web-.

    J2ME Personal Java.

    Personal 1.0

    Foundation 1.0. Personal Basis

    Profile 1.0. Personal -

    J2SE 1.3.1, , -

    Personal, J2SE 1.3.1.

    2.4 ,

    Personal 1.0.

    2.4.

    Personal

    Personal

    java.applet , ,

    .

    java.awt AWT -

    .

    java.awt.data transfer

    .

    ]ava.awt.event

    AWT.

    java.awt.font .

    java.awt.im

    .

    java.awt.im.spi

    , -

    -

    Java.

    java.awt.image

    java.beans , -

    JavaBean.

    javax.microedition.xlet

    , -

    J2ME Personal

    .

  • 62

    2.1.5. RMI

    Remote Method Invocation (RMI) , -

    , CDC.

    JSR-66 ,

    Java Community Process.

    RMI Foundation

    . RMI

    :

    RMI ;

    ;

    RMI ;

    API UnicastRemoteObject;

    , ;

    ;

    RMI . RMI RMI API J2SE 1.3.

    RMI

    J2SE . 1.3 API, -

    RMI - ,

    :

    RMI ;

    RMI ;

    (activatable) - ;

    , ;

    / RMI . 1.1;

    . J2SE RMI 1.3 :

    java.rmi.server.disableHttp;

    java.rmi.activation.port;

    java.rmi.loader.packagePrefix;

    java.rmi.registry.packagePrefix;

    java.rmi.server.packagePrefix.

  • 63

    2.2. Mobile Information Device Profile

    , CLDC,

    ,

    . -

    Mobile

    Information Device (MIDP), MID Profile. MIDP -

    CLDC API

    (UI), .

    Java, MIDP- -

    [8]. C , MIDP

    , .

    , PDA,

    . PDA

    . PDA, -

    , , ,

    MIDP,

    [10].

    MIDP, Foundation

    CDC, ,

    Mobile Information Device Profile,

    ,

    .

    MIDP , ,

    , ,

    :

    ( ) 96x54 ;

    1 ;

    , ;

    128 MIDP-;

    8 -;

    32 - Jra:

    . MID , MIDP -

    -

    . MIDP API:

    ( MIDP);

    ;

  • 64

    ;

    ;

    . 2.5. , MIDP.

    2.5.

    MIDP

    MIDP

    javax.microedition.icdui

    javax.microedition.rms

    (Record

    management system, RMS), -

    javax.microedition.midlet -

    MIDP

    javax.microedition.io -

    MIDP

    java.io / -

    Java

    java.lang Java

    java.util

    MIDP ,

    MIDP. , -

    .

    2.6 CDC

    CLDC. CDC, CLDC ,

    . ,

    -

    .

    2.6.

    CDC

    ID

    javax.microedition.midlet -

    ID.

  • 65

    ID

    javax.microedition.io -

    ID.

    java.io / -

    Java.

    java.lang Java -

    .

    java.util .

    2.2.1.

    . -

    2.7 MID- -

    .

    2.7.

    MID-

    Active

    ()

    MID- , . , -

    MID-, -

    , MID- .

    Destroyed

    ()

    MID- -

    .

    Paused

    ()

    MID- .

    , .

    2.3 -

    , , -

    .

    startApp(), pauseApp() destroyApp() MID-

    .

  • 66

    . 2.3. MID-

    2.8

    javax.microedition.midlet.MIDlet, -

    MID-.

    2.8.

    MID-, MID-

    MID-

    protected abstract void

    destroyApp()

    AMS MID- -

    . MID- .

    void notifyDestroyed() MID- -

    .

    void notifyPaused() MID-

    .

    protected abstract void

    pauseApp()

    AMS MID- , MID-

    .

    void resumeRequest() MID- -

    .

    protected abstract void

    startApp() AMS MID-, .

    MID J2SE , -

    . MID- -

    notifyDestroyed(),

    AMS, MID- . AMS MID-

    . .

  • 67

    : import javax.microedition.midlet.*;

    import javax.microedition.lcdui.*;

    public class MIDPSkeleton extends MIDlet implements Comman-

    dListener

    {

    private Command quit; // The Quit command

    private Display display; // Declaring the display

    // Initialize the Display and place system controls in the

    Constructor

    public MIDPSkeleton()

    {

    display = Display.getDisplay(this);

    quit = new Command("Quit", Command.SCREEN, 2);

    }

    /**

    * Initialize all the classes to be used in the program here

    (startApp())

    */

    public void startApp()

    {

    ...

    ...

    }

    // If the Application needs to be paused temporarily.

    public void pauseApp()

    {

    ...

    ...

    }

    // Clean up when the application is destroyed.

    public void destroyApp(boolean unconditional)

    {

    ...

    ...

    }

    // Event handling routine.

    public void commandAction(Command c, Displayable s)

    {

    if (c == quit) // If Quit button is pressed.

    {

    notifyDestroyed(); // Call the destroyApp method.

    }

    }

    }

  • 68

    2.2.2. MIDP

    J2ME

    :

    1. . 2.

    J2SE.

    3. - Java :

    Java.

    4. JAR, - , ,

    .

    5. .

    6. . 7. -

    .

    2.2.2.1.

    ,

    MID-, .. MID-

    , .

    Hello, -

    , apps/, -

    . .

    ( ,

    , ), -

    .

    Java ME SDK 3.0. -

    Sun Microsystems, http://java.sun.com.

    2.4 .

    http://java.sun.com/

  • 69

    . 2.4.

    :

    1) (File New Project) .

    2) Java ME SDK MIDP (MIDP Application).

    (Next) (. 2.5).

  • 70

    . 2.5.

    3) (Project Name) (. 2.6). ,

    (Browse) (Project Location).

    (Create Hello MIDlet),

    (Finish).

  • 71

    . 2.6.

    -

    , 2.9.

    2.9.

    Bin : .jar, .jad, MANIFEST.MF.

    classes .class.

    Res , ,

    .png PNG.

    Src .

    tmpclasses , .class.

  • 72

    2.2.2.2.

    -

    . ,

    ,

    , J2ME -

    .

    :

    S javac -d -bootclasspath \

    -d ,

    . -

    bootclasspath midpapi.zip,

    J2ME Wireless Toolkit,

    Java Software, MIDP,

    J2ME.

    . -

    bootclasspath

    CLASSPATH, , , -

    . , -

    -

    . ,

    Java, .

    MID- HelloWorld -

    apps/HelloWorld/, :

    $ javac -d tmpclasses \

    -bootclasspach ../../lib/midpapi.zip src/HelloWorld.Java

    $

    -d -

    tmpclasses,

    HelloWorld/. -bootclasspath

    . -

    HelloWorld.Java.

    tmpclasses

    .class:

  • 73

    $ Is -I tmpclasses/

    total 0

    -rw-r--r-- 1 vartan None 922 HelloWorld.class

    $

    2.2.2.3.

    .class, .

    , :

    $ preverify -classpath "../../lib/midpapi.zip;tmpclasses" -d

    classes \

    tmpclasses

    S

    -d , -

    ,

    . , ,

    tmpclasses, , -

    , -

    .

    preverify

    .class :

    S Is -I classes/

    total 0

    -rw-r--r-- 1 vartan None 922 HelloWorld.class

    $

    preverify

    ,

    . CLDC, J2SE, -

    Java -

    . J2SE -

    CLDC :

    1. , 2. .

    preverify,

    .

    , MIDP-

    .

    , .

  • 74

    , J2SE

    , -

    .

    CLDC RAM -

    .

    2.2.2.4.

    . 2 :

    Java MID-,

    . MIDP ,

    MID- Java (JAR).

    JAR MID-

    , :

    (manifest file) , - JAR-,

    Java, MID- MID- ,

    , MID- - MID-.

    JAR (manifest file) ,

    JAR-. JAR-

    .

    ,

    , MID-.

    Java (JAD).

    MID- .

    .

    (AMS)

    , MID- JAR -

    , JAR. AMS

    MID-. AMS

    MID-.

    MID- , -

    MIDP. , AMS MID-,

    , MID-.

  • 75

    , MID- JAD-

    , -

    MID-. -

    MIDP-.

    MIDP , Manifest -

    . 2.10.

    2.10.

    Manifest.MF

    MIDlet-Name MID-.

    MIDlet-Versiorv

    MID-

    ..,

    JDK.

    MIDlet-Vendor ( -

    ).

    MIDlet-

    MID- , -

    -

    MID-,

    n- MID- .

    MicroEdition-Profile J2ME, -

    MID-.

    MicroEdition-Configuration J2ME, -

    MID-.

    ,

    . . -

    , .

    MANIFEST.MF Hello

    Hello/bin/. :

    MIDlet-l: Hello, Hello.png, Hello

    MIDlet-Narae: Hello

    MIDlet-Vendor: Vartan Piroumian

    MIDlet-Version: 1.0

    MicroEdition-Configuration: CLDC-1.0

    MicroEdition-Profile: MIDP-1.0

  • 76

    MID-,

    MIDlet-l MIDlet-/n. 1

    MID-.

    MIDlet-1 . -

    MID-, MID-, -

    , . -

    PNG, AMS

    , MID-. -

    MID-,

    MID-.

    AMS MicroEdition-Configuration

    MicroEdition-Profile , MID-

    .

    MIDP

    . 2.11

    .

    2.11.

    MANIFEST.MF

    MIDlet-Description MID-

    MIDlet-Icon PNG, JAR

    MIDlet-Info-URL URL,

    MID-

    MIDlet-Data-Size

    ,

    JAR , -

    :

    $ jar craf bin/MANIFEST.MF bin/HelloWorld.jar -C classes/ .

    -C res .

    $

    -

    JAD , -

    .

    , -

  • 77

    .

    2.12 2.13.

    2.12.

    MIDlet-Jar-URL URL JAR MID-.

    MIDlet-Jar-Size ( ) JAR.

    MIDlet-Name MID-.

    MIDlet-Vendor (, -

    ).

    MIDlet-Version

    MID- .

    ., -

    JDK.

    MicroEdition-

    Configuration

    J2ME,

    MID-.

    MicroEdition-Profile J2ME, MID-

    .

    2.13.

    MIDlet-Data-Size

    , .

    MIDlet-Delete-Confirm , AMS -

    MID-.

    MIDlet-Description MID-.

    MIDlet-Icon PNG, JAR.

    MIDlet-Info-URL URL, -

    MID-.

    MIDlet-Install-Notify , AMS

    MID-.

    , -

    2.13, JAD -

    MID-, .

  • 78

    -

    MIDlet-.

    2.2.2.5. Pacpe

    . JAR MID-

    -

    .

    MID- -

    :

    1) (Project)

    MID- (New MIDlet).

    2) (. 2.7) (MIDlet Name)

    (MIDlet Class Name) MID-.

    (Finish).

    . 2.7. MID-

    3) , , MID- . -

    :

    import javax.microedition.midlet.*;

  • 79

    import javax.microedition.lcdui.*;

    public class Hello extends MIDlet implements CommandListener

    {

    public Hello() {

    exitCommand = new Command ("Exit", Command.EXIT, 1);

    tbox = new TextBox ("Hello world MIDlet", "Hello

    World!", 25, 0);

    tbox.addCommand (exitCommand);

    tbox.setCommandListener (this);

    }

    protected void startApp() {

    Display.getDisplay (this).setCurrent (tbox);

    }

    protected void pauseApp() {}

    protected void destroyApp (boolean bool) {}

    public void commandAction (Command cmd, Displayable

    disp) {

    if (cmd == exitCommand) {

    destroyApp (false);

    notifyDestroyed();

    }

    }

    private Command exitCommand;

    private TextBox tbox;

    }

    4) (Run), - Hello World! (. 2.8).

  • 80

    . 2.8. MID-

    2.2.3. MIDP

    MIDP -

    javax.microedition.lcdui. -

    -

    .

    Display -

    . MID- -

    . -

    getDisplay(): public static Display getDisplay(MIDlet midlet);

  • 81

    getDisplay()

    startApp() Display. public void startApp()

    {

    Display display = Display.getDisplay();

    }

    Display

    ,

    (. 2.14).

    2.14.

    Display

    public int numColors()

    , -

    , , , -

    , -

    .

    public boolean isColor() ,

    .

    public int numAlphaLe-

    vels()

    -

    , .

    , -

    -

    -

    .

    , .

    public int getColor(int

    colorSpecifier)

    -

    .

    public int getBorderS-

    tyle(boolean highlighted)

    , -

    (/ ).

    public boolean flashBack-

    light(int duration)

    -

    .

    public boolean vibrate(int

    duration) .

    , -

    , , -

    Displayable. Displayable -

  • 82

    , , Display -

    setCurrent(): public void setCurrent(Displayable displayable),

    public void setCurrent(Alert alert, Displayable displaya-

    ble).

    alert ,

    Displayable.

    , Displayable -

    : public Displayable getCurrent().

    Displayable 2.15.

    2.15.

    Displayable

    public void isShown()

    -

    , -

    .

    public void addCommand(Command cmd) .

    public void removeCommand(Command cmd) .

    public void setCommandListen-

    er(CommandListener l)

    , -

    .

    public void setTitle(String title) .

    public String getTitle() .

    public void setTicker(Ticker ticker)

    -

    , - .

    public Ticker getTicker()

    .

    MIDP Displayable

    Screen Canvas.

    Canvas ,

    GUI API.

    to handle game actions, key events

    pointer events. -

    API, Canvas

    paint(). -

    .

    Screen ,

    API. , -

    http://download.oracle.com/javame/config/cldc/ref-impl/midp1.0/jsr037/javax/microedition/lcdui/Command.html

  • 83

    Screen.

    : TextBox, List, Alert Form. Screen -

    , . -

    , , -

    API, , -

    , .

    2.2.4. API MIDP

    , API,

    , -

    ,

    .

    Command

    Displayable -

    .

    Command , -

    .

    , CommandListener, Dis-

    playable. , ,

    , -

    .

    : public void addCommand(Command cmd);

    public void removeCommand(Command cmd).

    -

    : public Command(String label, int commandType, int priority);

    public Command(String shortLabel, String longLabel, int com-

    mandType, int priority).

    label shortLabel -

    , commandType -

    . , -

    Command (. 2.16).

    2.16.

    public static int OK .

  • 84

    public static int

    CANCEL

    .

    public static int BACK .

    public static int STOP .

    public static int HELP .

    public static int

    SCREEN

    , -

    .

    public static int EXIT .

    public static int ITEM ,

    .

    priority , -

    , . ,

    .

    , -

    , CommandListener Dis-

    playable. : public void setCommandListener(CommandListener l);

    CommandListener : public void commandAction(Command c, Displayable d);

    , -

    Displayable.

    Displayable,

    .

    TextBox

    TextBox (Screen),

    . -

    2.17.

    : public TextBox(String title, String text, int maxSize, int

    constrants);

    title , -

    , text , maxSize

    constrants -

    , .

    2.17.

    TextBox

    public int getConstraints()

    TextBox.

  • 85

    public void setCon-

    straints(int constraints) .

    public int getMaxSize()

    (

    ),

    TextBox.

    public int setMaxS-

    ize(int maxSize)

    ( ), -

    TextBox.

    public String getString() TextBox

    .

    public void set-

    String(String text)

    TextBox

    , -

    .

    public int size()

    , -

    TextBox.

    public void delete(int offset,

    int length) TextBox.

    public void insert(String src,

    int position) TextBox.

    public void insert(char[] data,

    int offset, int length,

    int position)

    TextBox.

    public void set-

    Chars(char[] data, int offset,

    int length)

    TextBox

    ,

    .

    public void getCaretPosition() .

    TextBox -

    . TextBox , -

    , 120 .

    2.1: TextBox.

    /*

    * TextBoxExample.java demonstrates a typical use of the

    TextBox class.

    */

    package lab2;

    import javax.microedition.lcdui.Command;

    import javax.microedition.lcdui.CommandListener;

    import javax.microedition.lcdui.Display;

    import javax.microedition.lcdui.Displayable;

    import javax.microedition.lcdui.TextBox;

    import javax.microedition.lcdui.TextField;

  • 86

    import javax.microedition.lcdui.Ticker;

    import javax.microedition.midlet.*;

    public class TextBoxExample extends MIDlet {

    // Maximum text size in the TextBox

    private static final int MAX_TEXT_SIZE = 120;

    public void startApp() {

    // Create the TextBox

    TextBox textBox = new TextBox("TextBox Example",

    "Initial TextBox text",

    MAX_TEXT_SIZE, TextField.ANY);

    // Create a ticker

    Ticker ticker = new Ticker("Ticker for the Text-

    Box");

    textBox.setTicker(ticker);

    // Create Exit Command

    Command exitCommand = new Command("Exit", Com-

    mand.EXIT, 0);

    textBox.addCommand(exitCommand);

    textBox.setCommandListener(new CommandListener(){

    public void commandAction(Command c, Displayable

    d) {

    notifyDestroyed();

    }

    });

    // Make the TextBox to be visible on the display

    Display.getDisplay(this).setCurrent(textBox);

    }

    public void pauseApp() {

    }

    public void destroyApp(boolean unconditional) {

    }

    }

    Alert

    alert , -

    .

    MIDP :

    1) timed alert

    ;

    2) modal alert

    , .

    : public Alert(String title);

    public Alert(String title, String alertText, Im-

    age alertImage, AlertType alertType);

    http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/java/lang/String.html

  • 87

    title , alertText ,

    alertImage , , alert-

    Type ,

    (. 2.18).

    2.18.

    Alert

    Alert

    public static final int

    ALARM

    , -

    -

    .

    public static final int

    CONFIRMATION

    -

    .

    public static final int

    ERROR

    .

    public static final int

    INFO

    -

    .

    public static final int

    WARNING

    .

    Alert 2.19.

    2.19.

    Alert

    public int

    getDefaultTimeout()

    .

    public int getTimeout() ,

    .

    public void setTi-

    meout(int time)

    ,

    .

    public Image getImage() , -

    .

    public void setI-

    mage(Image img)

    , -

    .

    public AlertType

    getType()

    .

    public void set-

    Type(AlertType type)

    .

  • 88

    ,

    (timed alert), -

    getDefaultTimeout().

    ,

    setTimeout(Alert.FOREVER).

    -

    DISMISS_COMMAND, ,

    .

    , -

    . public

    static final Command DISMISS_COMMAND,

    .

    : -

    . MID-

    3000 .

    TextBox. setCurrent(Alert

    alert, Displayable displayable).

    , displayable.

    TextBox

    (modalAlert). ,

    TextBox,

    (Exit).

    2.2: . /*

    * AlertExample.java

    */

    package lab2;

    import java.io.IOException;

    import javax.microedition.lcdui.Alert;

    import javax.microedition.lcdui.AlertType;

    import javax.microedition.lcdui.Command;

    import javax.microedition.lcdui.CommandListener;

    import javax.microedition.lcdui.Display;

    import javax.microedition.lcdui.Displayable;

    import javax.microedition.lcdui.Image;

    import javax.microedition.lcdui.TextBox;

    import javax.microedition.lcdui.TextField;

    import javax.microedition.midlet.*;

    public class AlertExample extends MIDlet {

    // Get the instance of Display

    private Display display = Display.getDisplay(this);

    // The Alerts

  • 89

    private Alert timedAlert, modalAlert;

    // The TextBox

    private TextBox textBox;

    // Command for exit the application

    private Command exit = new Command("Exit", Command.EXIT,

    0);

    // Command for transition to the modal alert

    private Command nextAlert = new Command("Next alert",

    "Show next alert",

    Command.OK, 0);

    // Path to the image file

    private static final String pathToImage = "images/alert-

    image.png";

    public void startApp() {

    // Load the image

    Image image = loadImage();

    // Create the TextBox

    textBox = new TextBox("", "", 120, TextField.ANY);

    textBox.setCommandListener(new CommandListener() {

    public void commandAction(Command c, Displayable

    d) {

    if (c == exit) {

    notifyDestroyed();

    }

    else if (c == nextAlert) {

    textBox.setTitle("TextBox after modal

    alert");

    textBox.removeCommand(nextAlert);

    display.setCurrent(modalAlert, textBox);

    }

    }

    });

    // Create the timed Alert

    timedAlert = new Alert("Timed alert", "The alert is

    going to be gone",

    image, AlertType.INFO);

    timedAlert.setTimeout(3000);

    // Create the modal Alert

    modalAlert = new Alert("Modal alert", "The alert is

    waiting for action",

    image, AlertType.WARNING);

    modalAlert.setTimeout(Alert.FOREVER);

    textBox.setTitle("TextBox after timed alert");

    textBox.addCommand(exit);

    textBox.addCommand(nextAlert);

    // Make the timed Alert visible

  • 90

    display.setCurrent(timedAlert, textBox);

    }

    public void pauseApp() {

    }

    public void destroyApp(boolean unconditional) {

    }

    private Image loadImage() {

    try {

    // Try to load the image by path

    return Image.createImage(pathToImage);

    }

    catch (IOException e) {

    // If an exception occurred we return null

    System.out.println(e.getMessage());

    return null;

    }

    }

    }

    List

    List (Screen),

    . -

    .

    MIDP List:

    1. EXCLUSIVE .

    2. MULTIPLE .

    3. IMPLICIT

    .

    List -

    : public List(String title, int listType);

    public List (String title, int listType,

    String[] stringElements, Image[] imageElements).

    title , stringElements , -

    null, , imageElements

    . ListType

    : Choice.EXCLUSIVE,

    Choice.MULTIPLE, Choice.IMPLICIT.

    , List Choice. -

    2.20.

  • 91

    2.20.

    List

    public void set(int elementNum,

    String stringPart, Im-

    age imagePart)

    -

    ,

    .

    public void in-

    sert(int elementNum,

    String stringPart, Im-

    age imagePart)

    -

    .

    public int ap-

    pend(String stringPart, Im-

    age imagePart)

    .

    public String get-

    String(int elementNum)

    -

    .

    public Image getI-

    mage(int elementNum)

    .

    public void de-

    lete(int elementNum)

    .

    public void deleteAll() .

    public int size()

    .

    public void setFitPoli-

    cy(int fitPolicy)

    , -

    Choice -

    .

    public void set-

    Font(int elementNum, Font font)

    .

    public Font get-

    Font(int elementNum)

    .

    public boolean isSe-

    lected(int elementNum)

    , -

    , -

    .

    public int getSelectedIndex() -

    .

    public void setSelectedIn-

    dex(int elementNum, boo-

    lean selected)

    .

    public int getSelected-

    Flags(boolean[] selectedArray_r

    eturn)

    -

    .

    public void setSelected-

    Flags(boolean[] selectedArray)

    .

    IMPLICIT, -

    , . -

  • 92

    , , .

    -

    setSelectCommand().

    -

    , Store

    Favorites. (Store)

    List.MULTIPLE, (Fa-

    vorites) List.IMPLICIT.

    List.IMPLICIT.

    . -

    (Favorites) (-

    (alert) 5 )

    (Store).

    2.3: . package lab2;

    /*

    * ListExample.java

    */

    import javax.microedition.lcdui.Alert;

    import javax.microedition.lcdui.AlertType;

    import javax.microedition.lcdui.Command;

    import javax.microedition.lcdui.CommandListener;

    import javax.microedition.lcdui.Display;

    import javax.microedition.lcdui.Displayable;

    import javax.microedition.lcdui.List;

    import javax.microedition.midlet.*;

    public class ListExample extends MIDlet {

    Display display = Display.getDisplay(this);

    // The Store list

    private List storeList;

    // The Favorite list

    private List favoriteList;

    // The Menu list

    private List menuList;

    // Commands

    private Command exitCommand = new Command("Exit", Com-

    mand.EXIT, 0);

    private Command gotoFavoriteCommand = new Com-

    mand("Favorites", Command.OK, 0);

    private Command playCommand = new Command("Play", Com-

    mand.ITEM, 0);

    private Command deleteCommand = new Command("Delete",

    Command.ITEM, 1);

    private Command gotoMenuCommand = new Command("Menu",

    Command.OK, 0);

  • 93

    private Command takeSongsCommand = new Command("Take",

    Command.SCREEN, 0);

    public void startApp() {

    // Create all lists

    createStore();

    createFavoriteList();

    createMenu();

    // Start the app with the main menu

    display.setCurrent(menuList);

    }

    public void pauseApp() {

    }

    public void destroyApp(boolean unconditional) {

    }

    private void createStore() {

    // Form the list of songs

    String[] items = {

    "Beethoven. Symphony No. 5: I",

    "Tchaikovsky. 1812 Overture",

    "Mozart. Eine Kleine Nachtmusik: Allegro",

    "Bach. Toccata And Fugue In D Minor",

    "Rossini. William Tell Overture",

    "Pachelbel. Canon In D",

    "Strauss. Blue Danube"

    };

    // Create the list

    storeList = new List("Store", List.MULTIPLE, items,

    null);

    // Add the commands

    storeList.addCommand(takeSongsCommand);

    storeList.addCommand(gotoFavoriteCommand);

    // Define the logic for commands

    storeList.setCommandListener(new CommandListener() {

    public void commandAction(Command c, Displayable

    d) {

    if (c == takeSongsCommand) {

    // Find selected items, remove them from the Store, and

    // add them to the Favorites

    boolean[] selected = new boo-

    lean[storeList.size()];

    storeList.getSelectedFlags(selected);

    for (int i = 0; i < storeList.size();

    i++) {

    if (selected[i]) {

    String item = store-

    List.getString(i);

    favoriteList.append(item, null);

    storeList.delete(i);

  • 94

    }

    }

    }

    else {

    // Go to the Favotites

    display.setCurrent(favoriteList);

    }

    }

    });

    }

    private void createFavoriteList() {

    // Create the list

    favoriteList = new List("Favorites", List.IMPLICIT);

    // Set the select command

    favoriteList.setSelectCommand(playCommand);

    // Set other commands

    favoriteList.addCommand(deleteCommand);

    favoriteList.addCommand(gotoMenuCommand);

    favoriteList.setCommandListener(new CommandListen-

    er() {

    public void commandAction(Command c, Displayable

    d) {

    if (c == playCommand) {

    // Show an alert for 5 seconds

    int index = favoriteL-

    ist.getSelectedIndex();

    String item = favoriteL-

    ist.getString(index);

    Alert alert = new Alert("Playing...",

    item, null, AlertType.INFO);

    alert.setTimeout(5000);

    display.setCurrent(alert, favoriteList);

    }

    else if (c == deleteCommand) {

    // Remove the item from this list and add it to Store

    int index = favoriteL-

    ist.getSelectedIndex();

    String item = favoriteL-

    ist.getString(index);

    favoriteList.delete(index);

    storeList.append(item, null);

    }

    else {

    display.setCurrent(menuList);

    }

    }

    });

    }

  • 95

    private void createMenu() {

    String[] items = {"Store", "Favorites", "Exit"};

    menuList = new List("Menu", List.IMPLICIT, items,

    null);

    menuList.addCommand(exitCommand);

    menuList.setCommandListener(new CommandListener() {

    public void commandAction(Command command, Dis-

    playable d) {

    if (command == List.SELECT_COMMAND) {

    // Transfer to a screen depending on the selected item

    int index = menuList.getSelectedIndex();

    switch (index) {

    case 0:

    display.setCurrent(storeList);

    break;

    case 1:

    dis-

    play.setCurrent(favoriteList);

    break;

    default:

    notifyDestroyed();

    }

    }

    else if (command == exitCommand) {

    // Exit the application

    notifyDestroyed();

    }

    }

    });

    }

    }

    Form

    Form (Screen),

    -

    , items. ,

    , Item.

    Form : public Form(String title);

    public Form(String title, Item[] items);

    title,

    items.

    http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Form.html#Form%28java.lang.String,%20javax.microedition.lcdui.Item[]%29http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/java/lang/String.htmlhttp://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Item.html

  • 96

    items, ,

    , 2.21.

    2.21.

    Form

    public int ap-

    pend(Item item)

    .

    public int ap-

    pend(String str)

    ,

    .

    public int ap-

    pend(Image img)

    ,

    .

    public void

    set(int itemNum, Item item)

    ,

    .

    public void in-

    sert(int itemNum,

    Item item)

    -

    .

    public void de-

    lete(int itemNum)

    .

    public void deleteAll() .

    public int size() .

    public Item

    get(int itemNum)

    .

    Item

    Item , -

    . Item (label

    field).

    , . Items -

    ,

    Items . -

    get-

    MinimumWidth() getMinimumHeight().

    , -

    setPreferredSize().

    Item -

    . -

    getLayout() setLayout(). , -

    , Item,

    2.22.

    2.22.

  • 97

    Item

    LAYOUT_2 MIDP 2.0.

    LAYOUT_LEFT

    LAYOUT_RIGHT

    LAYOUT_CENTER

    -

    .

    LAYOUT_TOP

    LAYOUT_BOTTOM

    LAYOUT_VCENTER

    .

    LAYOUT_SHRINK

    LAYOUT_EXPAND

    LAYOUT_VSHRINK

    LAYOUT_VEXPAND

    .

    LAYOUT_NEWLINE_BEFORE

    LAYOUT_NEWLINE_AFTER

    -

    .

    Item :

    1. PLAIN Item .

    2. HYPERLINK Item .

    3. BUTTON Item .

    StringItem

    StringItem Item,

    . StringItem

    : public StringItem(String label, String text);

    public StringIten(String label, String text, int appearance-

    Mode);

    , appearanceMode

    : Item.PLAIN, Item.HYPERLINK Item.BUTTON.

    StringItem 2.23.

    2.23.

    StringItem

    public String getText() null,

    .

    public void setText(String

    text)

    -

    .

    public Font getFont() .

    public void setFont(Font

    font)

    .

    public int

    getAppearanceMode()

    .

  • 98

    Spacer

    Spacer

    . Spacer

    : public Spacer(int minWidth, int minHeight);

    TextField

    TextField , -

    . -

    : public TextField(String label, String text, int maxSize,

    int constraints);

    label , text

    , maxSize ,

    constraints . in-

    put constraints

    , TextField:

    ANY ,

    NUMERIC ,

    DECIMAL ,

    PHONENUMBER -

    ,

    EMAILADDR e-mail,

    URL URL.

    , -

    : PASSWORD, UNEDITABLE,

    SENSITIVE, NON_PREDICTIVE, INITIAL_CAPS_WORD,

    INITIAL_CAPS_SENTENCE.

    TextField

    TextBox.

    ImageItem

    ImageItem ,

    . ImageItem: public ImageItem(String label, Image image, int layout,

    String altText);

    public ImageItem(String label, Image image, int layout,

    String altText, int appearanceMode);

  • 99

    label , image -

    , Image, layout

    , altText , appearanceMode

    . Label altText .

    DateField

    DateField -

    . DateField : public DateField(String label, int mode);

    public DateField(String label, int mode, TimeZone timeZone);

    label , mode ,

    DateField.DATE, Date-

    Field.DATE_TIME DateField.TIME, timeZone ,

    .

    DateField 2.24.

    2.24.

    DateField

    public Date getDate() .

    public int

    getInputMode()

    .

    public void setDate(Date

    date)

    .

    public void setInput-

    Mode(int mode)

    .

    Gauge

    Gauge .

    , -

    .

    Gauge -

    : public Gauge(String label, boolean interactive, int maxVa-

    lue, int initialValue);

    label , in-

    teractive

    , maxValue , initialValue

    0 maxValue, ,

    maxValue Gauge.INDEFINITE, -

    : Gauge.CONTINUOUS_IDLE,

  • 100

    Gauge.CONTINUOUS_RUNNING, Gauge.INCREMENTAL_IDLE

    Gauge.INCREMENTAL_UPDATING.

    Gauge , -

    2.25.

    2.25.

    Gauge

    public boolean isInte-

    ractive()

    ,

    .

    public int getMaxValue()

    .

    public void setValue(int

    value)

    .

    public int getValue() .

    public void setMaxVa-

    lue(int maxValue)

    .

    ChoiceGroup

    ChoiceGroup List,

    Choice .

    ChoiceGroup: public ChoiceGroup(String label, int choiceType);

    public ChoiceGroup(String label, int choiceType, String[]

    stringElements, Image[] imageElements);

    , ChoiceType ,

    List, , IMPLICIT -

    POPUP, -

    .

    CustomItem

    CustomItem ,

    , .

    ,

    API.

    , , . -

    .

    StringItem :

    BUTTON, PLAIN HYPERLINK. StringItem BUTTON

    , -

    . DateField StringItem

    (BUTTON). Date-

  • 101

    Field. Gauge Text-

    Field, TextField Gauge.

    setItemStateListener

    . ,

    ItemStateListener, -

    TextField Gauge.

    2.4: . /*

    * FormExample.java

    */

    package lab2;

    import javax.microedition.lcdui.Command;

    import javax.microedition.lcdui.CommandListener;

    import javax.microedition.lcdui.DateField;

    import javax.microedition.lcdui.Display;

    import javax.microedition.lcdui.Displayable;

    import javax.microedition.lcdui.Form;

    import javax.microedition.lcdui.Gauge;

    import javax.microedition.lcdui.Item;

    import javax.microedition.lcdui.ItemCommandListener;

    import javax.microedition.lcdui.ItemStateListener;

    import javax.microedition.lcdui.StringItem;

    import javax.microedition.lcdui.TextField;

    import javax.microedition.midlet.*;

    public class FormExample extends MIDlet

    implements CommandListener {

    private Display dispaly = Display.getDisplay(this);

    // The global Next and Exit commands

    private Command exitCommand = new Command("Exit", Com-

    mand.EXIT, 0);

    private Command nextCommand = new Command("Next", Com-

    mand.OK, 0);

    // The array of forms and the index of the current form

    private int currentForm = 0;

    private Form[] forms = new Form[3];

    // The form items

    private StringItem item1, item2, item3;

    private DateField dateField;

    private Gauge gauge;

    public void startApp() {

    makeForms();

    dispaly.setCurrent(forms[nextFormIndex()]);

    }

    public void pauseApp() {

    }

    public void destroyApp(boolean unconditional) {

    }

  • 102

    // Process the global commands

    public void commandAction(Command command, Displayable

    d) {

    if (command == exitCommand) {

    notifyDestroyed();

    }

    else if (command == nextCommand) {

    dispaly.setCurrent(forms[nextFormIndex()]);

    }

    }

    private int nextFormIndex() {

    if (currentForm == forms.length) {

    currentForm = 0;

    }

    return currentForm++;

    }

    private void makeForms() {

    // Create the first form

    Form form1 = new Form("Form1. Layout of StringI-

    tems");

    item1 = new StringItem(null, "one", Item.BUTTON);

    item2 = new StringItem(null, "two");

    item3 = new StringItem(null, "three",

    Item.HYPERLINK);

    // Define command and command listener for item1

    Command changeLayoutCommand = new Command("one",

    Command.ITEM, 0);

    item1.setDefaultCommand(changeLayoutCommand);

    item1.setItemCommandListener(new ItemCommandListen-

    er() {

    public void commandAction(Command c, Item item)

    {

    // Change the layout mode for all StringItems

    item1.setLayout(Item.LAYOUT_2 |

    Item.LAYOUT_LEFT | Item.LAYOUT_NEWLINE_AFTER);

    item2.setLayout(Item.LAYOUT_2 |

    Item.LAYOUT_CENTER | Item.LAYOUT_NEWLINE_AFTER);

    item3.setLayout(Item.LAYOUT_2 |

    Item.LAYOUT_RIGHT | Item.LAYOUT_NEWLINE_AFTER);

    }

    });

    form1.append(item1);

    form1.append(item2);

    form1.append(item3);

    // Create the second form

    Form form2 = new Form("Form2. DateField");

    // Create the DateField item and place it on the form2

  • 103

    dateField = new DateField("DateField", Date-

    Field.DATE);

    dateField.setLayout(Item.LAYOUT_CENTER |

    Item.LAYOUT_VCENTER);

    // Create StringItem, place it and define Command and Com-

    mandListener

    StringItem dateControl = new StringItem(null,

    "Change", Item.BUTTON);

    dateControl.setLayout(Item.LAYOUT_CENTER |

    Item.LAYOUT_BOTTOM);

    dateControl.setDefaultCommand(new Command("Change",

    Command.ITEM, 0));

    dateControl.setItemCommandListener(new ItemComman-

    dListener() {

    public void commandAction(Command c, Item item)

    {

    // Change DateField's input mode

    date-

    Field.setInputMode((dateField.getInputMode() + 1) % 3 + 1);

    }

    });

    form2.append(dateField);

    form2.append(dateControl);

    // Create the third form

    Form form3 = new Form("Form3. Gauge");

    gauge = new Gauge(null, false, 10, 5);

    TextField textField = new TextField(null, "5", 2,

    TextField.NUMERIC);

    form3.setItemStateListener(new ItemStateListener() {

    // Transfer changes from the textField to the gauge

    public void itemStateChanged(Item item) {

    TextField tField = (TextField) item;

    int value = Integ-

    er.parseInt(tField.getString());

    if (value < 0)

    value = 0;

    else if (value > 10)

    value = 10;

    gauge.setValue(value);

    }

    });

    form3.append(gauge);

    form3.append(textField);

    forms[0] = form1;

    forms[1] = form2;

    forms[2] = form3;

    // Add global Commands and define the CommandListener for

    them

  • 104

    for (int i = 0; i < forms.length; i++) {

    forms[i].addCommand(exitCommand);

    forms[i].addCommand(nextCommand);

    forms[i].setCommandListener(this);

    }

    }

    }

    2.3.

    MIDP

    (Record Management System),

    . Record Management System (RMS)

    , -

    ,

    .

    (record) ,

    , , , , .. ,

    . API

    .

    . RMS

    .

    (RecordStore) .

    , -

    (record ID). , -

    record ID 1, 2 . . ,

    , .

    (name)

    MID-. 1 32

    MID-, . MIDP 1.0

    .

    MIDP 2.0 -

    . , -

    , , .

    ,

    .

    .

    Record Store ja-

    vax.microedition.rms.RecordStore.

  • 105

    Record Store MID-, Record Store

    MID- Record Store.

    Record Store :

    1. public static RecordStore openRecordStore(String re-cordStoreName, boolean createIfNecessary);

    2. public static RecordStore openRecordStore(String re-cordStoreName, boolean createIfNecessary, int authmode,

    boolean writable);

    3. public static RecordStore openRecordStore(String re-cordStoreName, String vendorName, String suiteName);

    , recordStoreName ; createIfNe-

    cessary , ,

    ; authmode -

    , .

    authmode :

    AUTHMODE_PRIVATE -

    AUTHMODE_ANY

    . writable

    , ;

    vendorName suiteName -

    .

    public void

    closeRecordStore().

    , .

    , , -

    : public static String[] listRecordStores().

    pub-

    lic static void deleteRecordStore(String recordSto-

    reName).

    -

    public void setMode(int authmode, boolean writa-

    ble).

    ,

    public int getSize().

    -

    : public int getSizeAvailable().

    , ja-

    vax.microedition.rms,

    , 2.26.

  • 106

    2.26.

    InvalidRecordIDException ,

    , -

    .

    RecordStoreException , -

    .

    RecordStoreFullException , -

    .

    RecordStoreNotFoundException , -

    .

    RecordStoreNotOpenException , -

    , -

    .

    ,

    : public int addRecord(byte[] data, int offset, int numBytes).

    data , ;

    offset data, -

    ; numBytes ,

    . -

    .

    , -

    : 1. public byte[] getRecord(int recordId). 2. public int getRecord(int recordId, byte[] buf-

    fer, int offset).

    , recordId ; buffer

    , ; offset -

    , .

    , .

    : public void deleteRecord(int recordId).

    : public void setRecord(int recordId, byte[] newData,

    int offset, int numBytes). -

    newDa-

    ta.

    int getNextRecordID() -

    , Record Store.

  • 107

    getNumRecords() -

    .

    (RecordStore)

    , TextBox

    . TextBox -

    (id),

    RECORD_ID. , destroyApp(),

    TextBox . ,

    , - ,

    TextBox .

    2.5: . /*

    * TextMiniEditor.java

    */

    package lab3;

    import javax.microedition.lcdui.Alert;

    import javax.microedition.lcdui.AlertType;

    import javax.microedition.lcdui.Command;

    import javax.microedition.lcdui.CommandListener;

    import javax.microedition.lcdui.Display;

    import javax.microedition.lcdui.Displayable;

    import javax.microedition.lcdui.TextBox;

    import javax.microedition.lcdui.TextField;

    import javax.microedition.midlet.*;

    import javax.microedition.rms.RecordStore;

    import javax.microedition.rms.RecordStoreException;

    public class TextMiniEditor extends MIDlet

    implements CommandListener

    {

    private static final String STORE_NAME = "TextMiniEdi-

    torStore";

    private static final int RECORD_ID = 1;

    private TextBox textBox;

    private RecordStore store;

    private Command exitCommand = new Command("Exit", Com-

    mand.EXIT, 0);

    public TextMiniEditor()

    {

    textBox = new TextBox("Text Mini Editor", null,

    2000, TextField.ANY);

    textBox.addCommand(exitCommand);

    textBox.setCommandListener(this);

    try {

    store = openStore();

    if (store.getNumRecords() > 0) {

    byte[] data = store.getRecord(RECORD_ID);

  • 108

    textBox.setString(new String(data));

    }

    }

    catch (RecordStoreException ex) {

    showError(ex.getMessage(), false);

    }

    finally {

    try {

    store.closeRecordStore();

    }

    catch (RecordStoreException ex) {

    ex.printStackTrace();

    }

    }

    }

    protected void destroyApp(bo