FINAL W.T Shree Ram College

download FINAL W.T Shree Ram College

of 60

Transcript of FINAL W.T Shree Ram College

  • 8/15/2019 FINAL W.T Shree Ram College

    1/60

    PRACTICAL No. 1

    Que: Wrie a program in J2ME to perform the simple calculator operations such as-

    a. Addition

    b. Subtractionc. Multiplicationd. Diision

    !rogram:

    import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class Calc extends MIDlet implements CommandListener {

    Display disp;

    TextField t!"t#"t$;Form orm;Command add"sub"mul"div"mod"exit;

      public Calc%&{

    disp'Display.(etDisplay%t)is&;orm'ne Form%+,ddition o to nos+&;t!'ne TextField%+First no.+"+-+"$-"TextField.,/&;t#'ne TextField%+0econd no.+"+-+"$-"TextField.,/&;t$'ne TextField%+1esult+"+-+"$-"TextField.,/&;orm.append%t!&;

    orm.append%t#&;orm.append%t$&;add'ne Command%+add+"Command.0C122"!&;sub'ne Command%+subtract+"Command.0C122"!&;mul'ne Command%+multiply+"Command.0C122"!&;div'ne Command%+Divide+"Command.0C122"!&;mod'ne Command%+modulus+"Command.0C122"!&;exit'ne Command%+2xit+"Command.23IT"#&;orm.addCommand%add&;orm.addCommand%sub&;orm.addCommand%mul&;orm.addCommand%div&;orm.addCommand%mod&;orm.addCommand%exit&;orm.setCommandListener%t)is&;

    4public void start,pp%&{

  • 8/15/2019 FINAL W.T Shree Ram College

    2/60

    disp.setCurrent%orm&;4public void pause,pp%&{4public void destroy,pp%boolean unconditional&

    {4

    public void command,ction%Command c"Displayable d&{

    i%c''add&{

    int a'Inte(er.parseInt%t!.(et0trin(%&&;int b'Inte(er.parseInt%t#.(et0trin(%&&;int c!'a5b;t$.set0trin(%0trin(.value6%c!&&;

    4

    i%c''sub&{int a'Inte(er.parseInt%t!.(et0trin(%&&;int b'Inte(er.parseInt%t#.(et0trin(%&&;int c!'a7b;t$.set0trin(%0trin(.value6%c!&&;

    4i%c''mul&{

    int a'Inte(er.parseInt%t!.(et0trin(%&&;int b'Inte(er.parseInt%t#.(et0trin(%&&;

    int c!'a*b;t$.set0trin(%0trin(.value6%c!&&;4i%c''div&{

    int a'Inte(er.parseInt%t!.(et0trin(%&&;int b'Inte(er.parseInt%t#.(et0trin(%&&;i%b''-&

    t$.set0trin(%+Divisor cannot be 8ero+&;else{int c!'a9b;t$.set0trin(%0trin(.value6%c!&&;4

    4i%c''mod&{

    int a'Inte(er.parseInt%t!.(et0trin(%&&;int b'Inte(er.parseInt%t#.(et0trin(%&&;

  • 8/15/2019 FINAL W.T Shree Ram College

    3/60

    i%b''-&t$.set0trin(%+Divisor cannot be 8ero+&;

    else{int c!'a:b;

    t$.set0trin(%0trin(.value6%c!&&;44i%c''exit&{

    destroy,pp%alse&;notiyDestroyed%&;

    44

    4

    "#$!#$:

     

  • 8/15/2019 FINAL W.T Shree Ram College

    4/60

      PRACTICAL No. 2 

    Que: Write a program in J2ME to create a simple Qui% &hich content ' to ()uestions and also displa* the score.

    !rogram:

    import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import java.lan(.*;

    public class ui8Demo extends MIDlet implements CommandListener"Item0tateListener {

    private Display disp;private Form orm!"orm#"orm$"ormroup radiobuttons"rdb#"rdb$"rdb

  • 8/15/2019 FINAL W.T Shree Ram College

    5/60

    ms$'ne 0trin(Item%null"+?)ic) olloin( city is capital o A@ +&;

    rdb$'ne C)oice>roup%+0elect youranser+"C)oice.23CLA0IB2&;

    rdb$.append%+,msterdam+"null&;rdb$.append%+London+"null&;rdb$.append%+e /orE+"null&;rdb$.append%+Mexico+"null&;

    msroup%+0elect youranser+"C)oice.23CLA0IB2&;

    rdb

  • 8/15/2019 FINAL W.T Shree Ram College

    6/60

    orm$.setCommandListener%t)is&;orm

  • 8/15/2019 FINAL W.T Shree Ram College

    7/60

    4i%item''rdb$&{

    0trin( ans'%rdb$.(et0trin(%rdb$.(et0electedIndex%&&&;i%ans.eHuals%+London+&&

    { la(55;4

    4i%item''rdb

  • 8/15/2019 FINAL W.T Shree Ram College

    8/60

    4

    4

    4

     

  • 8/15/2019 FINAL W.T Shree Ram College

    9/60

    PRACTICAL No. 3 

    Que: Write a program in J2ME to create a currenc* conerter and also displa* theresult.

    !rogram:

    import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class Currency extends MIDlet implements CommandListener {

    Display disp;TextField t!"t#;Form orm;Command A0"A"apan"exit;public Currency%&

    { disp'Display.(etDisplay%t)is&;orm'ne Form%+Conversion o Currency+&;t!'ne TextField%+Indian Currency+"+-+"$-"TextField.,/&;t#'ne TextField%+Forei(n Currency+"+-+"$-"TextField.,/&;orm.append%t!&;orm.append%t#&;A0'ne Command%+A0+"Command.0C122"!&;A'ne Command%+A+"Command.0C122"!&;apan'ne Command%+apan+"Command.0C122"!&;exit'ne Command%+2xit+"Command.23IT"#&;

    orm.addCommand%A0&;orm.addCommand%A&;orm.addCommand%apan&;orm.addCommand%exit&;orm.setCommandListener%t)is&;

    4public void start,pp%&{

    disp.setCurrent%orm&;4public void pause,pp%&{4public void destroy,pp%boolean unconditional&{4

    public void command,ction%Command c"Displayable d&{

    i%c''A0&

  • 8/15/2019 FINAL W.T Shree Ram College

    10/60

    {loat a'Float.parseFloat%t!.(et0trin(%&&;loat c!'a9

  • 8/15/2019 FINAL W.T Shree Ram College

    11/60

    "#$!#$

  • 8/15/2019 FINAL W.T Shree Ram College

    12/60

    PRACTICAL No. 4 

    Que: Write a program in J2ME to generate a calendar.

    !rogram:

    import javax.microedition.lcdui.*;import javax.microedition.midlet.MIDlet;import java.util.Date;

    public class CalenderMIDlet extends MIDlet{

    private Form orm;private Display disp;private DateField cal;private static inal int D,T2'-;

    public CalenderMIDlet%&{

    cal'ne DateField%+Date In+"DateField.D,T2&;

    4

    public void start,pp%&{

    disp'Display.(etDisplay%t)is&;orm'ne Form%+Calender+&;

    orm.append%cal&;disp.setCurrent%orm&;4

    public void pause,pp%&{

    4

    public void destroy,pp%boolean unconditional&{

    44

  • 8/15/2019 FINAL W.T Shree Ram College

    13/60

    "#$!#$

  • 8/15/2019 FINAL W.T Shree Ram College

    14/60

    PRACTICAL No. 5 

    Que: Write a program in J2ME to demonstrate simple animation through sna+emoement

     import ,aa.microedition.midlet./import ,aa.microedition.lcdui./

    public class M*Sna+e etends M0Dlet implements 1ommandistener 3

    Dra&Sna+e ds/Displa* dis/

    public M*Sna+e453

    dis6Displa*.getDispla*4this5/

    ds6ne& Dra&Sna+e45/7

    public oid startApp453

    dis.set1urrent4ds5/7

    public oid commandAction41ommand c8Displa*able d537

    public oid pauseApp4537

    public oid destro*App4boolean unconditional537

    7

    class Dra&Sna+e etends 1anas implements 9unnable8 1ommandistener 3

    int 8*8dir/$hread th/1ommand )uit/

    public Dra&Sna+e4536/*6/dir6/)uit6ne& 1ommand4;Q#0$;81ommand.S19EE

  • 8/15/2019 FINAL W.T Shree Ram College

    15/60

    add1ommand4)uit5/set1ommandistener4this5/th6ne& $hread4this5/th.start45/7

    public oid commandAction41ommand c8Displa*able d53

    if4c66)uit537 >>notif*Destro*ed45/

    7

    public oid +e*!ressed4int cd53

    s&itch4get?ameAction4cd55

    3 case 1anas.#!:*-6@/dir6=/

      brea+/case 1anas.D"W

  • 8/15/2019 FINAL W.T Shree Ram College

    16/60

    -6@/else if4dir66(56@/

    repaint45/tr*3th.sleep4@5/7catch 4Eception ee53

    7

    77

     public oid paint4?raphics g53

      g.set1olor4=B2B=B5/  g.fill9ect48 *8 =8 =5/

    g.dra&String4;9#!A 9A#SCA

  • 8/15/2019 FINAL W.T Shree Ram College

    17/60

  • 8/15/2019 FINAL W.T Shree Ram College

    18/60

    PRACTICAL No. 6 

    Que: Write a program in J2ME to create a simple application &ith an addressboo+ &ith the help of 9ecordStore.

     import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.rms.*;

    public class 1ecord0toreDemo extends MIDlet implements CommandListener {  private Display disp;  private Form rm;  private Command add" exit" delete"update"retrived;  private TextField txtrecid" txtname"txttelno;

      private 1ecord0tore rs;  0trin( recid" name" telno;

      public 1ecord0toreDemo%&  {  disp ' Display.(etDisplay%t)is&; 

    exit ' ne Command%+2xit+"Command.0C122"!&;  add ' ne Command%+,dd+"Command.0C122"!&;  delete ' ne Command%+Delete+"Command.0C122"!&;  update ' ne Command%+Apdate+"Command.0C122"!&;

      retrived ' ne Command%+1etrived+"Command.0C122"!&;

      try  {  rs ' 1ecord0tore.open1ecord0tore%+recorddemo+" true&;  4catc)%2xception e&  { e.print0tacETrace%&;  4 

    txtrecid ' ne TextField%+1ecord Id+"++ " $#" TextField.,/&;  txtname ' ne TextField%+ame+"++ " $#" TextField.,/&;  txttelno ' ne TextField%+Telep)one o.+"++ " $#" TextField.,/&;  rm ' ne Form%+Customer Details+&; 

    rm.append%txtrecid&;  rm.append%txtname&;  rm.append%txttelno&;

      rm.addCommand%exit&;

  • 8/15/2019 FINAL W.T Shree Ram College

    19/60

      rm.addCommand%add&;  rm.addCommand%delete&;  rm.addCommand%update&;  rm.addCommand%retrived&;  rm.setCommandListener%t)is&;

      4

      public void start,pp%&{

      disp.setCurrent%rm&;  4

      public void pause,pp%& {  4

      public void destroy,pp%boolean unconditional& {

      4

      public void command,ction%Command cmd" Displayable d&  {  i%cmd''exit&  {  destroy,pp%true&;  notiyDestroyed%&;  4  else i%cmd''add&  {

      recid ' txtrecid.(et0trin(%&;  name ' txtname.(et0trin(%&;  telno ' txttelno.(et0trin(%&;  0trin( data ' %recid5+;+5name5+;+5telno&;  0ystem.out.println%data&;  byte bJK ' data.(et=ytes%&;  try  {  int result ' rs.add1ecord%b" -" b.len(t)&;

      i%result'!&  {  ,lert a ' ne ,lert%+,dd+"+1ecord ,dded+"null",lertType.IF6&;  a.setTimeout%,lert.F612B21&;  disp.setCurrent%a&;  txtrecid.set0trin(%++&;  txtname.set0trin(%++&;  txttelno.set0trin(%++&;  4

  • 8/15/2019 FINAL W.T Shree Ram College

    20/60

  • 8/15/2019 FINAL W.T Shree Ram College

    21/60

      rs.delete1ecord%Inte(er.parseInt%txtrecid.(et0trin(%&&&;  txtname.set0trin(%++&;  txttelno.set0trin(%++&;  txtrecid.set0trin(%++&;  ,lert a ' ne ,lert%+Delete+"+1ecord Deleted+"null",lertType.IF6&;

      a.setTimeout%,lert.F612B21&;  disp.setCurrent%a&;  4catc)%Invalid1ecordID2xception e&  {  ,lert a ' ne ,lert%+2rror+"+o 1ecord to Delete+"null",lertType.21161&;  a.setTimeout%,lert.F612B21&;  disp.setCurrent%a&;  4  catc)%2xception e&  {  e.print0tacETrace%&;

      4 4

      else i%cmd''update&  {  try  {  recid ' txtrecid.(et0trin(%&;  name ' txtname.(et0trin(%&;  telno ' txttelno.(et0trin(%&;  0trin( data ' %recid5+;+5name5+;+5telno&;

      0ystem.out.println%data&;  byte bJK ' data.(et=ytes%&;  rs.set1ecord%Inte(er.parseInt%recid&" b" -" b.len(t)&;  ,lert a ' ne ,lert%+Apdate+"+1ecord Apdated+"null",lertType.IF6&;  a.setTimeout%,lert.F612B21&;  disp.setCurrent%a&;  txtrecid.set0trin(%++&;  txtname.set0trin(%++&;  txttelno.set0trin(%++&;  4  catc)%Invalid1ecordID2xception e&  {  ,lert a ' ne ,lert%+2rror+"+o 1ecord to Apdate+"null",lertType.21161&;  a.setTimeout%,lert.F612B21&;  disp.setCurrent%a&;  4  catc)%2xception e&  {  e.print0tacETrace%&;

  • 8/15/2019 FINAL W.T Shree Ram College

    22/60

      4  4  44

    6utput

     

  • 8/15/2019 FINAL W.T Shree Ram College

    23/60

    PRACTICAL No. 7 

    Que: Write a program in J2ME to create a simple database application &ith anaddress boo+ &ith the follo&ing operations:

    a. 0nsert

    !rogram:import java.io.*;import java.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.io.*;

    public class My0LConn extends MIDlet implements CommandListener {  private 0trin( username;  private 0trin( url ' +)ttp99local)ostG-GN9servlets7examples9(et+;

      private Display display;  private Command exit ' ne Command%+23IT+" Command.23IT" !&;;  private Command connect ' ne Command%+Connect+"Command.0C122" !&; 

    private Form menu;  private TextField tb!;  private TextField tb#;  D=Conn db;

      public My0LConn%& t)ros 2xception {

      display ' Display.(etDisplay%t)is&;

      4

      public void start,pp%& {  displayMenu%&;  4

      public void displayMenu%& {  menu ' ne Form%+Connect+&;

    tb! ' ne TextField%+lease input username +"++"$-"TextField.,/&;  tb# ' ne TextField%+lease input passord+"++"$-"TextField.,00?61D&;  menu.append%tb!&;  menu.append%tb#&;  menu.addCommand%exit&;  menu.addCommand%connect&;  menu.setCommandListener%t)is&;  display.setCurrent%menu&;

  • 8/15/2019 FINAL W.T Shree Ram College

    24/60

      4

      public void pause,pp%& {4

      public void destroy,pp%boolean unconditional& {4

      public void command,ction%Command command" Displayable screen& {  i %command '' exit& {  destroy,pp%alse&;  notiyDestroyed%&;  4 else i %command '' con& {  db ' ne D=Conn%t)is&;  db.start%&;  db.connectDb%tb!.(et0trin(%&"tb#.(et0trin(%&&;  4  4

      public class D=Conn implements 1unnable {  My0LConn midlet;  private Display display;  0trin( db;  0trin( user;  0trin( pd;  public D=Conn%My0LConn midlet& {  t)is.midlet ' midlet;  display ' Display.(etDisplay%midlet&;  4

      public void start%& {  T)read t ' ne T)read%t)is&;  t.start%&;  4

      public void run%& {  0trin(=uer sb ' ne 0trin(=uer%&;  try {  OttpConnection c ' %OttpConnection& Connector.open%url&;  c.set1eHuestroperty%+Aser7,(ent+"+roile9MID7!.-"Coni(uration9CLDC7!.-+&;  c.set1eHuestroperty%+Content7Lan(ua(e+"+en7A0+&;  c.set1eHuestMet)od%OttpConnection.60T&;

    Data6utput0tream os '%Data6utput0tream&c.openData6utput0tream%&;

      99os.riteATF%db.trim%&&;  os.riteATF%user.trim%&&;

  • 8/15/2019 FINAL W.T Shree Ram College

    25/60

      os.riteATF%pd.trim%&&;  os.lus)%&;  os.close%&;

      99 >et t)e response rom t)e servlet pa(e.

      DataInput0tream is'%DataInput0tream&c.openDataInput0tream%&;  99is ' c.openInput0tream%&;  int c);  sb ' ne 0trin(=uer%&;  )ile %%c) ' is.read%&& P' 7!& {  sb.append%%c)ar&c)&;  4  s)o,lert%sb.to0trin(%&&;  is.close%&;  c.close%&;

      4 catc) %2xception e& {  s)o,lert%e.(etMessa(e%&&;  4  4  9* T)is met)od taEes input rom user liEe db"user and pd and pass toservlet *9  public void connectDb%0trin( user"0trin( pd& {  99t)is.db ' db;  t)is.user ' user;  t)is.pd ' pd;  4

      9* Display 2rror 6n screen*9  private void s)o,lert%0trin( err& {  ,lert a ' ne ,lert%++&;  a.set0trin(%err&;  a.setTimeout%,lert.F612B21&;  display.setCurrent%a&;  4

    4;4

    0ervlet Codeimport java.io.*;import javax.servlet.*;import javax.servlet.)ttp.*;import java.sHl.*;

    public class >etConnection extends Ottp0ervlet{

  • 8/15/2019 FINAL W.T Shree Ram College

    26/60

      Connection conn;

      public void doost%Ottp0ervlet1eHuest reHuest" Ottp0ervlet1esponseresponse& t)ros 0ervlet2xception" I62xception {response.setContentType%+text9)tml+&;

    rint?riter out ' response.(et?riter%&;DataInput0tream in ' neDataInput0tream%%Input0tream&reHuest.(etInput0tream%&&;

    0trin( user ' in.readATF%&;0trin( pd ' in.readATF%&;0ystem.out.println%+received data is''+5user5pd&; try  {

      99 connect%user.toLoerCase%&.trim%&" pd.toLoerCase%&.trim%&&;

    Class.orame%+sun.jdbc.odbc.dbc6dbcDriver+&; conn ' DriverMana(er.(etConnection%+jdbcodbcOars)ad+&; 0tatement stmt ' conn.create0tatement%&; int i ' stmt.executeApdate%+insert into Lo(in values%Q+5user5+Q"Q+5pd5+Q&+&;  i%iP'-&{out.println%+data )as been inserted+&;4else

    {out.println%+data is not inserted+&;4  4catc)%2xception e&  { e.print0tacETrace%&; 4

     

    out.println%+Data+5user5pd&;in.close%&;

    out.close%&;out.lus)%&;

    4public void do>et%Ottp0ervlet1eHuest reHuest" Ottp0ervlet1esponseresponse& t)ros 0ervlet2xception" I62xception {doost%reHuest"response&;

  • 8/15/2019 FINAL W.T Shree Ram College

    27/60

    4

     9* private void connect% 0trin( user"0trin( pd& t)ros 2xception {

    4*94

  • 8/15/2019 FINAL W.T Shree Ram College

    28/60

  • 8/15/2019 FINAL W.T Shree Ram College

    29/60

    PRACTICAL No. 8 

    Program in J2MEto perform the following tasks:A) Create a form1 that contain Label &e!t"o!# $e!t "%tton

    ") Create a form2 that contain check"o!# ra'io"%tton #e!tArea& $e!t# "ack "%tton

    C) Create a form( that contains ispla* of all abo+e forms

    Co'e:

    import javax.microedition.lcdui.*;

    import javax.microedition.midlet.*;

    import java.io.*;

     public class Commander extends MIDlet implements CommandListener 

    {

     private CanvasDemo cd; public Commander()

    {

    }Displa displa ! null;

    "orm #$ ! null;

    "orm #% ! null;"orm #& ! null;

     private C'oiceroup ender;

     private int currentIndex; private int enderIndex;

     private C'oiceroup 'obies;

     private int 'obiesIndex;

     private ext"ield tb+ame, tbInstitute, tb-'one, tbCel, tbCit, tbrea; public ic/er tic+ame;

    Command #irst"ormCommand ! ne0 Command(1$st "orm1, 1o to "irst "orm1,

    Command.2C344+, 5);

    Command second"ormCommand ! ne0 Command(1%nd "orm1, 1o to 2econd "orm1,Command.2C344+, 5);

    Command t'ird"ormCommand ! ne0 Command(1&rd "orm1, 1o to 'ird "orm1,

    Command.2C344+, 5);

    Command exitCommand ! ne0 Command(14xit1, Command.46I, $);Command bac/Command$ ! ne0 Command(17ac/$1, Command.7C8, $);

    Command bac/Command% ! ne0 Command(17ac/%1, Command.7C8, $);

     public void startpp(){

    cd!ne0 CanvasDemo(t'is);

    displa ! Displa.etDispla(t'is);

  • 8/15/2019 FINAL W.T Shree Ram College

    30/60

    #$!ne0 "orm(1"orm $1);

    #$.addCommand(second"ormCommand);

    #$.addCommand(exitCommand);#$.setCommandListener(t'is);

    tb+ame!ne0 ext"ield(14nter 9our +ame : 1,11,%5,ext"ield.+9);tbInstitute!ne0 ext"ield(1+ame o# Institute : 1,11,%5,ext"ield.+9);

    tb-'one!ne0 ext"ield(1-'one +o. : 1,11,%5,ext"ield.+9);

    tbCel!ne0 ext"ield(1Mobile +o. : 1,11,%5,ext"ield.+9);tbCit!ne0 ext"ield(1Cit : 1,11,%5,ext"ield.+9);

    tic+ame!ne0 ic/er(1Milind'orat1);

    #$.append(tb+ame);

    #$.append(tbInstitute);#$.append(tb-'one);

    #$.append(tbCel);

    #$.append(tbCit);

    #$.setic/er(tic+ame);#%!ne0 "orm(1"orm %1);

    #%.addCommand(t'ird"ormCommand);#%.addCommand(bac/Command$);

    #%.setCommandListener(t'is);

    'obies!ne0 C'oiceroup(12elect 9our obies1,C'oice.M

  • 8/15/2019 FINAL W.T Shree Ram College

    31/60

     public void pausepp() {}

     public void destropp(boolean unconditional) {

      } public void commandction(Command c, Displaable d)

    {

    2trin label ! c.etLabel();i#(label.e>uals(14xit1))

    {

    noti#Destroed();}

    else i#(label.e>uals(1$st "orm1))

    {

    Displa.etDispla(t'is).setCurrent(#$);

    }

    else i#(label.e>uals(17ac/$1)){

    Displa.etDispla(t'is).setCurrent(#$);}

    else i#(label.e>uals(1%nd "orm1))

    {Displa.etDispla(t'is).setCurrent(#%);

    }

    else i#(label.e>uals(17ac/%1)){

    Displa.etDispla(t'is).setCurrent(#%);

    }else i#(label.e>uals(1&rd "orm1))

    {

    Displa.etDispla(t'is).setCurrent(#&);

    2trinItem ms$!ne0 2trinItem(null,1?n+ame: 1@ tb+ame.et2trin());

    2trinItem ms%!ne0 2trinItem(null,1?nInstitute: 1@

    tbInstitute.et2trin());2trinItem ms&!ne0 2trinItem(null,1?n-'one +o: 1@

    tb-'one.et2trin());

    2trinItem msA!ne0 2trinItem(null,1?nMobile +o: [email protected]());

    2trinItem msB!ne0 2trinItem(null,1?nCit: 1@ tbCit.et2trin());

    #&.append(1Displa 3esult:1);#&.append(ms$);

    #&.append(ms%);

    #&.append(ms&);

    #&.append(msA);

  • 8/15/2019 FINAL W.T Shree Ram College

    32/60

    #&.append(msB);

     boolean pic/s ! ne0 boolean'obies.siEe();2trinItemmessae ! ne0 2trinItem'obies.siEe();

    'obies.et2elected"las(pic/s);

    2trinItem msF! ne0 2trinItem(null,1?n obies:1);#&.append(msF);

    #or (int x ! 5; x Gpic/s.lent'; x@@)

    {i# (pic/sx)

    {

    messaex ! ne0 2trinItem(11,1 1@'obies.et2trin(x));

    #&.append(messaex);}

    }

    #&.delete('obiesIndex);

    currentIndex ! ender.et2electedIndex();2trinItem messae$ ! ne0 2trinItem(1ender:

    1,ender.et2trin(currentIndex));#&.append(messae$);

    #&.delete(enderIndex);

    2trinItem msH!ne0 2trinItem(null,1?nddress: 1@ tbrea.et2trin());#&.append(msH);

    }

    }

    }classCanvasDemo extends Canvas

    {

     public Commander parent; publicint0idt','ei't;

     publicCanvasDemo(Commander parent)

    {t'is.parent!parent;

    0idt'!etidt'();

    'ei't!etei't();

    Displa.etDispla(parent).setCurrent(t'is);}

     public void paint(rap'ics )

    {.setColor(5,%BB,5);

    .#ill3ect(5,5,0idt','ei't);

    }}

    ,%tp%t:

  • 8/15/2019 FINAL W.T Shree Ram College

    33/60

  • 8/15/2019 FINAL W.T Shree Ram College

    34/60

  • 8/15/2019 FINAL W.T Shree Ram College

    35/60

    PRACTICAL No. 9

    -rite a program in J2ME to perform the simple calc%lator operations s%ch as

    a A''ition

    b .%btraction

    c M%ltiplication

    ' i+ision

    Co'e :

    importjavax.microedition.midlet.*;

    importjavax.microedition.lcdui.*;

     public class Calc extends MIDlet implements CommandListener 

    {

    Displa disp;ext"ield t#$,t#%,t#&;

    "orm #orm;

    Command add,sub,mul,div,mod,exit; public Calc()

    {

    disp!Displa.etDispla(t'is);#orm!ne0 "orm(1Jperation on t0o numbers1);

    t#$!ne0 ext"ield(1"irstno.1,151,&5,ext"ield.+9);

    t#%!ne0 ext"ield(12econdno.1,151,&5,ext"ield.+9);t#&!ne0 ext"ield(13esult1,151,&5,ext"ield.+9);

    #orm.append(t#$);

    #orm.append(t#%);#orm.append(t#&);

    add!ne0 Command(1add1,Command.2C344+,$);sub!ne0 Command(1sub1,Command.2C344+,$);

    mul!ne0 Command(1mul1,Command.2C344+,$);

    div!ne0 Command(1div1,Command.2C344+,$);mod!ne0 Command(1mod1,Command.2C344+,$);

    exit!ne0 Command(1exit1,Command.46I,$);

    #orm.addCommand(add);#orm.addCommand(sub);

    #orm.addCommand(mul);

    #orm.addCommand(div);#orm.addCommand(mod);

    #orm.addCommand(exit);

  • 8/15/2019 FINAL W.T Shree Ram College

    36/60

    #orm.setCommandListener(t'is);

    }

     public void startpp(){

    disp.setCurrent(#orm);

    } public void pausepp()

    {

    } public void destropp(boolean unconditional)

    {

    }

     public void commandction(Command c,Displaable d){

    i#(c!!add)

    {

    int a!Inteer.parseInt(t#$.et2trin());int b!Inteer.parseInt(t#%.et2trin());

    int c$!a@b;t#&.set2trin(2trin.valueJ#(c$));

    }

    i#(c!!sub){

    int a!Inteer.parseInt(t#$.et2trin());

    int b!Inteer.parseInt(t#%.et2trin());

    int c$!aKb;t#&.set2trin(2trin.valueJ#(c$));

    }

    i#(c!!mul){

    int a!Inteer.parseInt(t#$.et2trin());

    int b!Inteer.parseInt(t#%.et2trin());int c$!a*b;

    t#&.set2trin(2trin.valueJ#(c$));

    }

    i#(c!!div){

    int a!Inteer.parseInt(t#$.et2trin());

    int b!Inteer.parseInt(t#%.et2trin());i#(b!!5)

    t#&.set2trin(1Divisor cannot be Eero1);

    else{

    int c$!ab;

    t#&.set2trin(2trin.valueJ#(c$));

    }

  • 8/15/2019 FINAL W.T Shree Ram College

    37/60

    }

    i#(c!!mod)

    {int a!Inteer.parseInt(t#$.et2trin());

    int b!Inteer.parseInt(t#%.et2trin());

    i#(b!!5)t#&.set2trin(1Divisor cant be Eero1);

    else

    {int c$!ab;

    t#&.set2trin(2trin.valueJ#(c$));

    }

    }i#(c!!exit)

    {

    destropp(#alse);

    noti#Destroed();}

    }

    }

    ,%tp%t:

  • 8/15/2019 FINAL W.T Shree Ram College

    38/60

  • 8/15/2019 FINAL W.T Shree Ram College

    39/60

    PRACTICAL No. 10 

    -rite a program in J2ME to create a simple /%i0 which content ( to %estions an' also

    'ispla* the score

    Co'e:

    importjavax.microedition.midlet.*;

    importjavax.microedition.lcdui.*;importjava.lan.*;

     public class NuiEDemo extends MIDlet implements CommandListener,Item2tateListener 

    {

     private Displa disp;

     private "orm #orm$,#orm%,#orm&,#ormA; private Command exit,next$,next%,next&,submit;

     privateext7oxms;

     private Item selection;

     privateC'oiceroup radiobuttons,rdb%,rdb&,rdbA;2trinItem ms$,ms%,ms&,msA;

     privateintde#aultIndex; privateintradio7uttonIndex;

    int #la!$;

     publicNuiEDemo()

    {

    disp!Displa.etDispla(t'is);

    ms$!ne0 2trinItem(null,10'ic' #ollo0in cit is capital o# IndiaO1);radiobuttons!ne0 C'oiceroup(12elect our

    ans0er1,C'oice.46CL

  • 8/15/2019 FINAL W.T Shree Ram College

    40/60

    rdbA.append(1peru1,null);

    rdbA.append(13ome1,null);

    rdbA.append(18airo1,null);rdbA.append(12dne1,null);

    #orm$!ne0 "orm(1Nuestion $1);

    #orm$.append(ms$);radio7uttonIndex!#orm$.append(radiobuttons);

    #orm%!ne0 "orm(1Nuestion %1);

    #orm%.append(ms%);radio7uttonIndex!#orm%.append(rdb%);

    #orm&!ne0 "orm(1Nue2tion &1);

    #orm&.append(ms&);

    radio7uttonIndex!#orm&.append(rdb&);#ormA!ne0 "orm(1Nuestion A1);

    #ormA.append(msA);

    radio7uttonIndex!#ormA.append(rdbA);

    exit!ne0 Command(14xit1,Command.46I,$);submit!ne0 Command(12ubmit1,Command.2C344+,$);

    next$!ne0 Command(1+ext1,Command.2C344+,$);

    next%!ne0 Command(1+ext1,Command.2C344+,$);

    next&!ne0 Command(1+ext1,Command.2C344+,$);ms!ne0 ext7ox(1Messae1,1Conrats1,Q5,5);

    #orm$.addCommand(next$);

    #orm%.addCommand(next%);#orm&.addCommand(next&);

    #ormA.addCommand(submit);

    #ormA.addCommand(exit);

    #orm$.setCommandListener(t'is);

    #orm%.setCommandListener(t'is);#orm&.setCommandListener(t'is);

    #ormA.setCommandListener(t'is);

    #orm$.setItem2tateListener(t'is);#orm%.setItem2tateListener(t'is);

    #orm&.setItem2tateListener(t'is);

    #ormA.setItem2tateListener(t'is);}

     public void startpp()

    {disp.setCurrent(#orm$);

    }

     public void pausepp()

    {

  • 8/15/2019 FINAL W.T Shree Ram College

    41/60

    }

     public void destropp(boolean unconditional)

    {}

     public void item2tateC'aned(Item item){

    i#(item!!radiobuttons)

    {2trin

    ans!(radiobuttons.et2trin(radiobuttons.et2electedIndex()));

    i#(ans.e>uals(1Del'i1))

    {#la@@;

    }

    }

    i#(item!!rdb%){

    2trin ans!(rdb%.et2trin(rdb%.et2electedIndex()));i#(ans.e>uals(1o/io1))

    {

    #la@@;}

    }

    i#(item!!rdb&)

    {2trin ans!(rdb&.et2trin(rdb&.et2electedIndex()));

    i#(ans.e>uals(1London1))

    {#la@@;

    }

    }i#(item!!rdbA)

    {

    2trin ans!(rdbA.et2trin(rdbA.et2electedIndex()));

    i#(ans.e>uals(1/airo1))

    {

    #la@@;}

    }}

     public void commandction(Command com, Displaable disp$)

    {

    i#(com!!next$)

  • 8/15/2019 FINAL W.T Shree Ram College

    42/60

    {

    disp.setCurrent(#orm%);

    }i#(com!!next%)

    {

    disp.setCurrent(#orm&);}

    i#(com!!next&)

    {disp.setCurrent(#ormA);

    }

    i#(com!!exit)

    {destropp(#alse);

    noti#Destroed();

    }

    i#(com!!submit){

    2trinItem ms$!ne0 2trinItem(null,19ou 'ave Correct ns0er1@ #la);

    #ormA.append(ms$);

    }}

    }

    ,%tp%t:

  • 8/15/2019 FINAL W.T Shree Ram College

    43/60

  • 8/15/2019 FINAL W.T Shree Ram College

    44/60

  • 8/15/2019 FINAL W.T Shree Ram College

    45/60

    PRACTICAL No. 11

    -rite a program in J2ME to create a c%rrenc* con+erter an' also 'ispla* the

    res%lt

    Co'e :

    importjavax.microedition.midlet.*;importjavax.microedition.lcdui.*;

     public class currenc extends MIDlet implements CommandListener {

     private Displa disp;

     private "orm #;

     privateext"ieldtb; privateext"ield tb$;

     privateC'oiceroup c,c$;

     private Command resul;

     private Command ans; public currenc()

    {tb!ne0 ext"ield(11,11,%5,ext"ield.+

  • 8/15/2019 FINAL W.T Shree Ram College

    46/60

    {

    }

     public void commandction(Command c, Displaable s){

    int n,n$,res!5;

    2trin res$;n!c$.et2electedIndex();

    n$!Inteer.parseInt(tb.et2trin());

    s0itc'(n){

    case 5:

    res!n$QB;

     brea/;case $:

    res!n$HB;

     brea/;

    case %: res!n$AQ;

     brea/;case &:

    res!n$*%;

     brea/;}

    res$!Inteer.to2trin(res);

    2stem.out.println(1#irst!1@n$@1?nJperation

    Index!1@n@1?n3esult!1@res);tb$.set2trin(res$);

    }

    }

    ,%tp%t :

  • 8/15/2019 FINAL W.T Shree Ram College

    47/60

  • 8/15/2019 FINAL W.T Shree Ram College

    48/60

    PRACTICAL No. 12 

    -rite a program in J2ME to generate a calen'ar

    Co'e:importjavax.microedition.lcdui.*;

    importjavax.microedition.midlet.MIDlet;

    importjava.util.Date;importjava.util.imeRone;

     public class CalenderMIDlet extends MIDlet{

     private "orm #orm; private Displa displa;

     privateDate"ieldcalender;

     private static #inal int D4 ! 5;

     publicCalenderMIDlet(){

    calender ! ne0 Date"ield(1Date In:1, Date"ield.D4, imeRone.etimeRone(1M1));  }

     public void startpp(){displa ! Displa.etDispla(t'is);

      "orm #orm ! ne0 "orm(1Calender1);

    #orm.append(calender);

    displa.setCurrent(#orm);  }

     public void pausepp(){}

     public void destropp(boolean destro){

    noti#Destroed();  }

    }

  • 8/15/2019 FINAL W.T Shree Ram College

    49/60

    ,%tp%t:

  • 8/15/2019 FINAL W.T Shree Ram College

    50/60

    PRACTICAL No. 13 

    -rite a program in J2ME to 'emonstrate simple animation thro%gh snake mo+ement

    Co'e:

    importjavax.microedition.midlet.*;

    importjavax.microedition.lcdui.*;

     public class M2na/e extends MIDlet implements CommandListener 

    {Dra02na/e ds;

    Displa dis;

     publicM2na/e(){

    dis !Displa.etDispla(t'is);

    ds!ne0 Dra02na/e();

    } public void startpp()

    {dis.setCurrent(ds);

    }

     public void commandction(Command c, Displaable d){}

     public void pausepp()

    {}

     public void destropp(boolean unconditional){}

    }

    classDra02na/e extends Canvas implements 3unnable, CommandListener 

    {

    intx,,dir;'read t';

    Command >uit;

     publicDra02na/e()

    {x!5;

    !5;

    dir!5;>uit!ne0 Command(1Nuit1,Command.2C344+,$);

    addCommand(>uit);

    setCommandListener(t'is);t'!ne0 'read(t'is);

    t'.start();

    }

     public void commandction(Command c,Displaable d)

  • 8/15/2019 FINAL W.T Shree Ram College

    51/60

    {

    i#(c!!>uit)

    {}}

     public void /e-ressed(int cd)

    { s0itc'(etamection(cd))

    {

    caseCanvas.

  • 8/15/2019 FINAL W.T Shree Ram College

    52/60

    }

    }

     public void paint(rap'ics ){

    .setColor(5x$"%"$");

    .#ill3ect(x,,$5,$5);.dra02trin(1Milind 'orat1,%B,%B,rap'ics.J- S rap'ics.L4");

    }

    }

    ,%tp%t:

  • 8/15/2019 FINAL W.T Shree Ram College

    53/60

  • 8/15/2019 FINAL W.T Shree Ram College

    54/60

    PRACTICAL No. 14 

    -rite a program in J2ME to create a simple 'atabase application with an a''ress book

    with the following operations:

    a 3nsert

    b eletec 4p'ate' 5etrie+e

    Co'e:

    import java.io.*;

    importjava.util.*;

    importjavax.microedition.midlet.*;

    importjavax.microedition.lcdui.*;

    import javax.microedition.io.*;

     public class M2NLConn extends MIDlet implements CommandListener 

    {

     private 2trin username; private 2trin url!1'ttp:local'ost:Q5Q5jjetConnection1;

     private Displa displa;

     private Command exit!ne0 Command(146I1, Command.46I,$); private Command connect!ne0 Command(1Connect1, Command.2C344+,$);

     private "orm menu; privateext"ield tb$;

     privateext"ield tb%;

    D7Conndb;

     publicM2NLConn() t'ro0s 4xception

    {

    displa!Displa.etDispla(t'is);}

     public void startpp()

    {displaMenu();

    }

     public void displaMenu()

    {menu!ne0 "orm(1Connect1);

    tb$!ne0 ext"ield(1-lease input username:1,11,&5,ext"ield.+9);

    tb%!ne0 ext"ield(1-lease input pass0ord:1,11,&5,ext"ield.-22J3D);menu.append(tb$);

    menu.append(tb%);

    menu.addCommand(exit);menu.addCommand(connect);

  • 8/15/2019 FINAL W.T Shree Ram College

    55/60

    menu.setCommandListener(t'is);

    displa.setCurrent(menu);

    } public void pausepp()

    {}

     public void destropp(boolean unconditional){}

     public void commandction(Command command,Displaable screen){

    i#(command!!exit)

    {

    destropp(#alse);noti#Destroed();

    }

    else i#(command!!connect)

    { db!ne0 D7Conn(t'is);

    db.start();db.connectDb(tb$.et2trin(),tb%.et2trin());

    }

    } public class D7Conn implements 3unnable

    {

    M2NLConnmidlet;

     private Displa displa;2trin db;

    2trin user;

    2trin p0d; publicD7Conn(M2NLConnmidlet)

    {

    t'is.midlet!midlet;displa!Displa.etDispla(midlet);

    }

     public void start()

    {'read t!ne0 'read(t'is);

    t.start();

    } public void run()

    {

    2trin7u##ersb!ne0 2trin7u##er();tr

    {

    ttpConnection c!(ttpConnection) Connector.open(url);

  • 8/15/2019 FINAL W.T Shree Ram College

    56/60

  • 8/15/2019 FINAL W.T Shree Ram College

    57/60

    importjavax.servlet.*;

    importjavax.servlet.'ttp.*;

    import java.s>l.*;

     public class etConnection extends ttp2ervlet

    { Connection conn;

     public void do-ost(ttp2ervlet3e>uest re>uest, ttp2ervlet3esponse response)

    t'ro0s2ervlet4xception, IJ4xception{

    response.setContentpe(1text'tml1);

    -rintriter out!response.etriter();DataInput2tream in!ne0

    DataInput2tream((Input2tream)re>uest.etInput2tream());

    2trin user!in.read

  • 8/15/2019 FINAL W.T Shree Ram College

    58/60

    {

    do-ost(re>uest,response);

    }}

    ,%tp%t:

  • 8/15/2019 FINAL W.T Shree Ram College

    59/60

  • 8/15/2019 FINAL W.T Shree Ram College

    60/60