Results 1 to 2 of 2
  1. #1
    coldvoice05's Avatar
    coldvoice05 is offline Member
    Join Date
    Jul 2009
    Posts
    12
    Rep Power
    0

    Smile wireless mobile midlet problem

    given this example

    /*
    * RmsExample1.java
    *
    * (c) 2005 J.E.D.I.
    */

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

    public class RmsExample1 extends MIDlet implements CommandListener {
    Display display;
    RecordStore recStore = null;
    int count = 0;

    public static final Command exitCommand =
    new Command("Exit", Command.EXIT, 1);
    public static final Command newCommand =
    new Command("New Record", Command.OK, 1);
    public static final Command deleteCommand =
    new Command("Delete Record", Command.OK, 1);

    ChoiceGroup items = new ChoiceGroup( "Items", Choice.MULTIPLE );

    public void startApp() {
    if( display == null ){
    display = Display.getDisplay( this );
    display.setCurrent(new RmsForm());
    loadStore();
    }
    }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional){
    //
    Quit();
    }

    public void loadStore(){
    byte[] data = new byte[16];
    int recLength;
    items.deleteAll();

    try {
    // Open or Create Record Store with name "RmsExample1"
    recStore = RecordStore.openRecordStore("RmsExample1", true);

    // Load contents of Record Store
    for (int recId=1; recId<=recStore.getNumRecords(); recId++){
    // getRecord returns the length of the record
    recLength = recStore.getRecord(recId, data, 0);

    // Convert the byte array into String
    String item = new String(data, 0, recLength);

    // update the display
    items.append(item, null);
    }
    } catch (Exception e){items.append(e.toString(), null); }
    }

    class RmsForm extends Form {
    RmsForm(){
    // Setup the Form
    super("RmsExample");
    addCommand(exitCommand);
    addCommand(newCommand);
    addCommand(deleteCommand);
    setCommandListener(RmsExample1.this);
    append(items);
    }
    }


    public void commandAction(Command c, Displayable d){
    if(c == exitCommand){
    Quit();
    }
    if (c == newCommand){
    try {
    // We will create a new Record
    // This is the String we will put into the Record
    String newItem = "Record #" + recStore.getNextRecordID();

    // Convert the String into a byte array
    byte[] bytes = newItem.getBytes();

    // Write the Record into the Store
    recStore.addRecord(bytes, 0, bytes.length);

    // Update our display
    items.append(newItem, null);
    } catch (Exception e){}
    }
    if (c == deleteCommand){
    try {
    // We will create a new Record
    // This is the String we will put into the Record
    recStore.deleteRecord(recStore.getNextRecordID()-1);
    items.delete (items.size()-1);
    } catch (Exception e){}
    }
    }

    public void Quit(){
    if (recStore != null){
    try {
    recStore.closeRecordStore();
    } catch (RecordStoreNotOpenException notopen){
    // record store is not open
    } catch (RecordStoreException rse){
    // record store-related exception occurred
    }
    }
    // Exit
    notifyDestroyed();
    }
    }
    1) Improve the program such that records a listed not using a sequential for loop.

    2) Improve the checkboxes such that if it is checked then upon clicking delete only the checked items are deleted.

    3) You should be able to delete 1 or more list items at a single instance.

    Improve your program this time that is create the contents of each record based on the inputs of the users in the text field based on the given requirements:
    1) The program will have three interfaces: Main interface, Add record interface and Delete Record interface.
    2) The main interface will have a welcome screen and two choices add record and delete record with an EXIT and LAUNCH button.
    3) The add record interface will result to 2 text boxes namely name and cellphone with two menu buttons BACK (which will return the main interface) and ADD which will create the record based on the content inputted in the textfield.
    4) The delete record interface will list all the records created in checkbox list and the same as Machine problem 6 the user will just select the records to be deleted by selecting the checkbox and Delete button. It should also have a BACK button the will return to the main interface.

    Hint bench mark on your MP #6, hence make sure your MP #6 is already functioning as prescribed.

    PLEASE HELP ME IN THIS WORK TO DO... IM JUST A WOMAN AND WEAK WHEN IT COMES TO PROGRAMMING PLEASE HELP!!!

    THANK YOU GENTLEMEN =)
    Last edited by coldvoice05; 09-23-2009 at 08:25 AM.

  2. #2
    dineinfotech is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default

    i m trying to run a project, it has three files one is servlet file and another one is normal java, then the third one is j2me wireless toolkit related file..

    i compiled servlet and executed normal java file.. then i started tomcat also, after build and running j2me wireless toolkit file, i got an message like hais what is this?...


    i not able to understand that hais message as output..

    The files are given below..



    second.java

    import java.sql.*;
    import java.sql.ResultSet.*;
    import java.util.*;
    import java.io.*;

    class second
    {
    static int code;
    static String name;
    public static void main(String args[])
    {
    try
    {
    BufferedReader in=new BufferedReader(new
    InputStreamReader(System.in));
    String s=new String("");

    //Connecting to the database with data source name as shut
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url ="jdbc:odbc:shut";
    Connection con =DriverManager.getConnection(url);
    ResultSet rs,rs1;
    Statement stmt =con.createStatement();
    int u;
    String k;
    //Code for retrieving and updating the database
    String sql ="select code,filename from codetab";
    String sql1="update codetab set code='0',path='',filename='' where
    code='1'";
    String sql2="update codetab set code='0',path='',filename='' where
    code='2'";
    String sql3="update codetab set code='0',path='',filename='' where
    code='3'";
    con.setAutoCommit(true);
    //Continuously listens the database for any data arrival
    while(true)
    {
    rs=stmt.executeQuery(sql);
    while(rs.next())
    {
    name=(rs.getString("code")); // check whether code is 1 for shutdown
    if(name.equals("1"))
    {
    u=stmt.executeUpdate(sql1);
    System.out.println(name);
    rs=stmt.executeQuery(sql)
    s=new String("C:\\Shutcat\\webapps\\ROOT\\WEB-INF\\classes\\shut.exe");
    Runtime r=Runtime.getRuntime();
    Process p=r.exec(s); }
    // check whether code is 2 for logoff
    if(name.equals("2"))
    {
    u=stmt.executeUpdate(sql2);
    System.out.println(name);
    rs=stmt.executeQuery(sql);
    s=new String("C:\\Shutcat\\webapps\\ROOT\\WEB-INF\\classes\\logoff.exe");
    Runtime r=Runtime.getRuntime();
    Process p=r.exec(s); }
    // check whether code is 3 for restart
    if(name.equals("3"))
    {
    u=stmt.executeUpdate(sql3);
    System.out.println(name);
    rs=stmt.executeQuery(sql);
    s=new String("C:\\Shutcat\\webapps\\ROOT\\WEB-INF\\classes\\reset.exe");
    Runtime r=Runtime.getRuntime();
    Process p=r.exec(s); System.out.println("logoff Please wait");
    }
    System.out.println("Listening");
    }
    Thread.sleep(1000);
    }
    }
    catch(Exception e)
    {
    System.exit(0);
    }
    }
    }


    server side code.. example.java

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class example extends HttpServlet
    {
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    {
    try
    {
    res.setContentType("text/html");
    PrintWriter pr=res.getWriter();
    //Connecting to the database with data source name shut.
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection
    ("jdbc:odbc:shut");
    Statement stmt=con.createStatement();

    /* Extracting the code which represents the operation from the
    request sent by mobile.
    */

    String code1=req.getParameter("code");

    /*Checks whether the code is 1 which represents shutdown.
    Update the database and sends the acknowledgement to the
    mobile simulator.
    */

    if(code1.equals("1"))
    {
    int u=stmt.executeUpdate("update codetab set code='1'
    where code='0'");
    rs=stmt.executeQuery("select * from codetab where
    code='1'");
    pr.println("The system is about to shutdown");
    }

    /*Checks whether the code is 2 which represents logoff. Update
    the database and sends the acknowledgement to the mobile
    simulator.
    */

    if(code1.equals("2"))
    {
    int u1=stmt.executeUpdate("update codetab set code='2'
    where code='0'");
    rs=stmt.executeQuery("select * from codetab where
    code='2'");
    pr.println("The system is about to logoff");
    }

    /*Checks whether the code is 3 which represents restart. Update
    the database and sends the acknowledgement to the mobile
    simulator.
    */

    if(code1.equals("3"))
    {

    int u1=stmt.executeUpdate("update codetab set code='3'
    where code='0'");
    rs=stmt.executeQuery("select * from codetab where
    code='3'");
    pr.println("The system is about to restart");
    }
    }
    catch(Exception e){}
    }
    }


    J2ME code

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    import javax.microedition.io.*;
    import java.lang.*;

    public class pcc extends MIDlet implements ItemStateListener,CommandListener
    {
    private Display display;
    private Form form1;
    private Command select,select1,exit;
    private Command back;
    private Item Selection;
    private ChoiceGroup rb1; //rb1 for radio buttons 1;

    public pcc()
    {
    menu=0;
    display=Display.getDisplay(this);
    rb1=new ChoiceGroup("Select Your
    Option",Choice.EXCLUSIVE);
    rb1.append("Run",null);
    rb1.append("Open txt File",null);
    rb1.append("Chatting",null);
    rb1.append("Administration",null);
    rb1.append("Error Msg",null);
    rb1.setSelectedIndex(0,true);
    exit=new Command("Exit",Command.EXIT,1);
    select=new Command("Select",Command.SCREEN,1);
    back=new Command("Back",Command.EXIT,1);
    form1=new Form("");
    rbindex=form1.append(rb1);
    form1.addCommand(exit);
    form1.addCommand(select);
    form1.setCommandListener(this);
    form1.setItemStateListener(this);
    select1=new Command("Select",Command.SCREEN,1);
    rb2=new ChoiceGroup("Administration",Choice.EXCLUSIVE);
    rb2.append("Shutdown.",null);
    rb2.append("Logoff.",null);
    rb2.append("Restart.",null);
    rb2.setSelectedIndex(0,true);
    form2=new Form("");
    form2.append(rb2);
    form2.addCommand(back);
    form2.addCommand(select1);
    form2.setCommandListener(this);
    form2.setItemStateListener(this);
    }
    public void startApp()
    {
    display.setCurrent(form1);
    }
    public void pauseApp()
    {
    }
    public void destroyApp(boolean unconditional)
    {
    }
    public void commandAction(Command c,Displayable d)
    {
    if(menu==1)
    {
    if(c == exit)
    {
    destroyApp(true);
    notifyDestroyed();
    }
    if(c == select)
    {
    if(rb1.getSelectedIndex()==3)
    {
    display.setCurrent(form2);
    rb2.setSelectedIndex(0,true);
    menu=2;//administration
    }
    System.out.println(rb1.getString(rb1.getSelectedIn dex()));
    }
    }
    if(menu==2)//administration
    {
    if(c == back)
    {
    display.setCurrent(form1);
    form1.setCommandListener(this);
    menu=1;
    }
    if(c == select1)
    {
    String s;
    s=rb2.getString(rb2.getSelectedIndex());
    System.out.println(s);
    if(s.equals("Shutdown."))
    {
    {
    HttpConnection connection=null;
    InputStream inputstream=null;
    String strr[]=new String[10];
    int m=0;
    //code=1 represents shutdown, sent to the
    web server
    String url=new String("http://localhost:8080
    /servlet/example?code=1");
    try
    {
    connection=(HttpConnection)
    Connector.open(url);
    connection.setRequestMethod
    (HttpConnection.GET);
    connection.setRequestProperty("Content-
    Type","//text plain");
    connection.setRequestProperty("Connection"
    ,"close" );
    if (connection.getResponseCode()=
    =HttpConnection.HTTP_OK)
    {
    String str;
    int l;
    inputstream = connection.
    openInputStream();
    int length=(int)connection.getLength();
    if (length!=-1)
    {
    byte incomingData[]=new
    byte[length];
    inputstream.read(incomingData);
    str=new String(incomingData);
    }
    else
    {
    ByteArrayOutputStream bytestream
    =new ByteArrayOutputStream();
    int ch;
    while((ch=inputstream.read())!=-1)
    {
    if(ch==10)
    {
    strr[m]=new
    String(bytestream.toByteArray());
    System.out.println(strr[m]);
    m++;
    bytestream.reset();
    }
    else
    {
    bytestream.write(ch);
    }
    }
    bytestream.close();
    }
    for(int l1=0;l1<m;l1++)
    {
    strr[l1]=strr[l1].trim();
    }
    }
    }
    catch(IOException error)
    {
    System.out.println("caught IOException:"
    +error.toString());
    }
    finally
    {
    if(inputstream!=null)
    {
    try
    {
    inputstream.close();
    }
    catch(Exception error)
    {}
    }
    if(connection !=null)
    {
    try
    {
    connection.close();
    }
    catch(Exception error)
    {}
    }
    }
    }
    }
    public void itemStateChanged(Item item)
    {
    if(item==rb1)
    {
    menu=1;
    }
    }
    };

Similar Threads

  1. custom midlet-servlet chat app problem
    By vukdavid in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-22-2009, 12:30 PM
  2. Replies: 1
    Last Post: 08-07-2009, 12:14 PM
  3. Sockets for computers in wireless network
    By etrynus in forum Networking
    Replies: 2
    Last Post: 12-02-2008, 11:39 PM
  4. Problem with Midlet back button
    By Poonam in forum CLDC and MIDP
    Replies: 5
    Last Post: 11-17-2008, 09:14 AM
  5. How to connect to a wireless nettwork?
    By KjetilB in forum Networking
    Replies: 3
    Last Post: 11-09-2008, 07:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •