Results 1 to 2 of 2

Thread: ถาม เรื่องการทำ list สินค้า แล้วเอาไปเก็บใน RMS

  1. #1


    คือ ผมเอา โค๊ด textbox ที่ สามารถ เพิ่ม ลบ ได้เอามา แปลง ให้เป็น list ซึ่งจะเอาไปเก็บใน ฐานข้อมูล RMS เหมือน textbox แตมันติด error ครับ

    คือผม เพิ่งจะหัดเล่นอ่ะคราฟ ไม่ค่อยจะเข้าใจสักหน่อยอ่ะคราฟ ยังไงรบกวน ด้วยนะคราฟ

  2. #2


    เพิ่มเติมคับ

    นี่ตัวอย่างโค้ด ที่เป็น text boxx อ่ะคับ

    อย่างให้แปลงเป็น List แบบ Multi



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

    public class RMSTest extends MIDlet implements CommandListener{

    private Display mDisplay;
    private Form mForm1, mForm2;
    private TextField nameText, numText;
    private StringItem listString;
    private Command saveCommand, listCommand, deleteCommand,
    exitCommand, backCommand;
    private static String DATABASE = "order";

    public RMSTest(){
    mForm1 = new Form("Record Manager");
    nameText = new TextField("Order", "", 20, TextField.ANY);
    numText = new TextField("Price", "", 20, TextField.NUMERIC);

    saveCommand = new Command("Save", Command.SCREEN, 1);
    listCommand = new Command("List all", Command.SCREEN, 2);
    deleteCommand = new Command("Delete all", Command.SCREEN, 3);
    exitCommand = new Command("Exit", Command.EXIT, 4);

    mForm1 .append(nameText);
    mForm1 .append(numText);

    mForm1 .addCommand(saveCommand);
    mForm1 .setCommandListener(this);
    mForm1 .addCommand(listCommand);
    mForm1 .setCommandListener(this);
    mForm1 .addCommand(deleteCommand);
    mForm1 .setCommandListener(this);
    mForm1 .addCommand(exitCommand);
    mForm1 .setCommandListener(this);

    mForm2 = new Form("List Record");

    listString = new StringItem(null,null);

    backCommand = new Command("Back", Command.SCREEN, 0);

    mForm2.append(listString);
    mForm2.addCommand(backCommand);
    mForm2.setCommandListener(this);


    }

    public void startApp(){

    mDisplay = Display.getDisplay(this);
    mDisplay.setCurrent(mForm1);

    }

    public void pauseApp(){}
    public void destroyApp(boolean uncondition){}
    public void commandAction(Command c, Displayable d){

    if (c == exitCommand){
    destroyApp(false);
    notifyDestroyed();
    }


    if (c == saveCommand){
    SaveData();
    }



    if (c == listCommand){
    ListData();
    }



    if (c == deleteCommand){
    DeleteData();
    }


    if (c == backCommand){
    mDisplay.setCurrent(mForm1);
    }


    }




    public void SaveData(){

    RecordStore rs;
    String name = nameText.getString();
    String num = numText.getString();
    String str = name + " [" + num + "]";

    byte[] data = str.getBytes();

    try{

    rs = RecordStore.openRecordStore(DATABASE, true);
    rs.addRecord(data, 0, data.length);
    rs.closeRecordStore();

    nameText.setString(null);
    numText.setString(null);

    }
    catch (RecordStoreException e){
    System.out.println(e);
    }
    }


    public void ListData(){

    RecordStore rs;
    StringBuffer strRecord = new StringBuffer();
    StringBuffer strAll = new StringBuffer();
    mDisplay.setCurrent(mForm2);
    listString.setText(null);

    try{
    rs = RecordStore.openRecordStore(DATABASE, true);
    try{
    int lastID = rs.getNumRecords();
    byte[] data = new byte[100];
    int size;

    for (int i = 1; i <=lastID; ++i )
    {
    try{
    size = rs.getRecordSize(i);
    rs.getRecord(i, data, 0);
    strRecord.setLength(0);

    for (int j = 0; j < size; j++){
    strRecord.append((char) data[j]);
    }
    strAll.append(i + ". " + strRecord + "\n");

    }catch (InvalidRecordIDException e){
    continue;
    }
    }

    }catch (RecordStoreException e){
    System.out.println("Exception reading record store: " + e);
    }

    listString.setText(strAll.toString());
    rs.closeRecordStore();


    }catch (RecordStoreException e){
    System.out.println(e);
    }
    }



    public void DeleteData(){
    try
    {
    RecordStore.deleteRecordStore(DATABASE);
    }
    catch (RecordStoreException e){
    System.out.println(e);
    }
    }




    };

Similar Threads

  1. Sexoffender List
    By newsbot in forum World Hacking/Security News
    Replies: 0
    Last Post: 19-03-2008, 07:14 PM
  2. Game CD Key List
    By SheLLniX in forum Gaming, Bot, Cheating and Tweaking tool
    Replies: 0
    Last Post: 09-02-2008, 10:02 PM
  3. เรื่องการทำ E-book
    By Ekk in forum Request Room
    Replies: 1
    Last Post: 16-09-2007, 08:18 PM
  4. FTP WAREZ List
    By newsbot in forum Window Application
    Replies: 1
    Last Post: 02-09-2005, 03:12 PM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

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