2013-04-03 43 views
2

我有一个LWUIT应用程序,涉及两个RecordStores players1_recordStore和当为特定记录库添加记录时,它也被添加到另一个记录库!

players2_recordStore。两种方法方法SearchCarded_team1为retriving

players1_recordStore的所有记录,以及方法SearchCarded_team2为retriving的

所有记录players2_recordStore。添加新记录players1_recordStore,B2增加新

记录players2_recordStore 4点按钮B1,B3检索players1_recordStore的所有记录和B4到

检索players2_recordStore的所有记录。

我有一对夫妇的问题,在我的应用

1-当B3按钮或按下B4不显示的第一条记录!

2-为什么players2_recordStore的记录按压按钮B3时,显示players1_recordStore

记录旁边,正好相反。

import javax.microedition.rms .*; 

import com.sun.lwuit.plaf.*; 
import javax.microedition.midlet.*; 

import com.sun.lwuit.*; 
import com.sun.lwuit.events.*; 

public class HelloLWUITMidlet extends MIDlet { 

    private RecordStore players1_recordStore; 
    private RecordStore players2_recordStore; 



    public String [] SearchCarded_team1() 
{ 

    String[] str = null; 
    int counter = 0; 
    try 
    { 
    RecordEnumeration enumeration = players1_recordStore.enumerateRecords(null, null, false); 
     str = new String[players1_recordStore.getNumRecords()]; 

     while(enumeration.hasNextElement()) 
     { 
      try 
      { 
       str[counter] = (new String(enumeration.nextRecord())); 
       counter ++; 
      } 
      catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 


    return str; 
} 

public String [] SearchCarded_team2() 
{ 

    String[] str = null; 
    int counter = 0; 
    try 
    { 


     RecordEnumeration enumeration = players2_recordStore.enumerateRecords(null, null, false); 
     str = new String[players2_recordStore.getNumRecords()]; 

     while(enumeration.hasNextElement()) 
     { 
      try 
      { 
       str[counter] = (new String(enumeration.nextRecord())); 
       counter ++; 
      } 
      catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 


    return str; 
} 




    public void startApp() 

    { 

     com.sun.lwuit.Display.init(this); 

int bgColor =0x0066CC; 
try 
{ 
players1_recordStore.openRecordStore("My Record Store", true); 

} 
catch(Exception e){} 

try 
{ 
players2_recordStore.openRecordStore("My Record Store", true); 

} 

catch(Exception e){} 

final form5 gggg =new form5(); 
gggg.setTitle("Cards ' Record"); 

final com.sun.lwuit.List mylist = new com.sun.lwuit.List(); 


final com.sun.lwuit.Form f = new com.sun.lwuit.Form("Soccer Software"); 
    f.getStyle().setBgColor(0X99CCFF); 

    final com.sun.lwuit.TextField tf =new com.sun.lwuit.TextField(); 
    final com.sun.lwuit.TextField txtfield3 =new com.sun.lwuit.TextField(); 

final com.sun.lwuit.TextField  tf3 =new com.sun.lwuit.TextField(); 
    final com.sun.lwuit.TextField txtfield4 =new com.sun.lwuit.TextField(); 

    final com.sun.lwuit.TextField tf4 =new com.sun.lwuit.TextField(); 
    final com.sun.lwuit.TextField txtfield6 =new com.sun.lwuit.TextField(); 


    final Button cards = new Button(""+"Cards Status"); 
    cards.getStyle().setBgColor(0X0066CC); 

final Button b1 = new Button("Yellow Cards "); 
final Button b2 = new Button("Red Cards"); 
final Button b3 = new Button("All yellow carded players"); 
final Button b4 = new Button("All red carded players"); 

b2.getStyle().setBgColor(0X0066CC); 

    b1.getStyle().setBgColor(0X0066CC); ; 
    b2.getStyle().setBgColor(0X0066CC); 
    b3.getStyle().setBgColor(0X0066CC); ; 
b4.getStyle().setBgColor(0X0066CC); 


    com.sun.lwuit.Command back = new com.sun.lwuit.Command("Main Screen"); 



final com.sun.lwuit.TextArea text = new com.sun.lwuit.TextArea(); 

final Label lll = new Label(""); 


f.addComponent(cards); 

txtfield3.setLabelForComponent(lll); 


gggg.getStyle().setBgColor(0X99CCFF); 
gggg.addComponent(b1); 
gggg.addComponent(b2); 
gggg.addComponent(b3); 
gggg.addComponent(b4); 
gggg.addComponent(txtfield6); 


gggg.addCommand(back); 


cards.addActionListener(new ActionListener() { 

    public void actionPerformed(ActionEvent ae) { 


gggg.show(); 
    } 

    } 
); 


gggg.addCommandListener(new ActionListener() 

{ 


    public void actionPerformed(ActionEvent ae) { 



f.show(); 
    } 



} 
     ); 



b1.addActionListener(new ActionListener() { 

public void actionPerformed(ActionEvent ae) { 

String player1 =txtfield6.getText(); 

    { } 

if(player1!=null && player1.length() > 0) 

{ 


try 
{ 
players1_recordStore.openRecordStore("My Record Store", true); 
     } 

catch(Exception e){} 


try{ 
    byte bytestream[] = player1.getBytes() ; 

      int i = players1_recordStore.addRecord(bytestream, 0, bytestream.length); 

    } 

catch(Exception ex) { } 


    Dialog validDialog = new Dialog(" "); 
    Style Dialogstyle = validDialog.getSelectedStyle() ; 

     validDialog.setScrollable(false); 
validDialog.getDialogStyle().setBgColor(0x0066CC); 
     validDialog.setTimeout(1000); 
     TextArea textArea = new TextArea("...."); 
     textArea.setFocusable(false); 

     textArea.setText(player1+"-"+"has been carded"); 
     validDialog.addComponent(textArea); 

     validDialog.show(0, 10, 10, 10, true); 

txtfield6.clear(); 


} 


else 

{ 

    Dialog validDialo = new Dialog(" "); 
     validDialo.setScrollable(false); 
validDialo.getDialogStyle().setBgColor(0x0066CC); 
     validDialo.setTimeout(5000); 
     TextArea textArea = new TextArea("...."); 

     textArea.setFocusable(false); 
     textArea.setText("please Enter the record "); 
     validDialo.addComponent(textArea); 


     validDialo.show(50, 50, 50, 50, true); 
     txtfield6.clear(); 
} 




    } 
    } 
); 

b2.addActionListener(new ActionListener() { 


public void actionPerformed(ActionEvent ae) { 

String player2 =txtfield6.getText(); 


    { } 

if(player2!=null && player2.length() > 0) 

{ 

try{ 
    byte bytestream[] = player2.getBytes() ; 

      int i = players2_recordStore.addRecord(bytestream, 0, bytestream.length); 

    } 

catch(Exception ex) { } 


    Dialog validDialog = new Dialog(" "); 
    Style Dialogstyle = validDialog.getSelectedStyle() ; 

     validDialog.setScrollable(false); 
validDialog.getDialogStyle().setBgColor(0x0066CC); 
     validDialog.setTimeout(1000); 
     TextArea textArea = new TextArea("...."); 
     textArea.setFocusable(false); 

     textArea.setText(player2+"-"+"has been expluded"); 
     validDialog.addComponent(textArea); 

     validDialog.show(0, 10, 10, 10, true); 

txtfield6.clear(); 


} 


else 

{ 

    Dialog validDialo = new Dialog(" "); 
     validDialo.setScrollable(false); 
validDialo.getDialogStyle().setBgColor(0x0066CC); 
     validDialo.setTimeout(5000); 
     TextArea textArea = new TextArea("...."); 

     textArea.setFocusable(false); 
     textArea.setText("please Enter Record"); 
     validDialo.addComponent(textArea); 


     validDialo.show(10, 10, 10, 10, true); 
     txtfield6.clear(); 
} 




    } 
    } 
); 


b3.addActionListener(new ActionListener() { 


    public void actionPerformed(ActionEvent ae) { 

    try{ 
     players1_recordStore = RecordStore.openRecordStore("My Record Store", true); 

     } 


    catch(Exception ex) 
    { 
     ex.printStackTrace(); 
    } 

String [] carded = SearchCarded_team1(); 
int j; 
String valueToBeInserted=""; 

for(j=0;j< SearchCarded_team1().length;j++) 
    { 


valueToBeInserted=valueToBeInserted + " " + carded[j]; 







     } 
Dialog hilal = new Dialog(" "); 
    Style Dialogstyle = hilal.getSelectedStyle() ; 
hilal.setTitle("All Yellow Carded Players"); 
     hilal.setScrollable(false); 
hilal.getDialogStyle().setBgColor(0x0066CC); 
     hilal.setTimeout(10000); 
     TextArea textArea = new TextArea(); 
     textArea.setFocusable(false); 

     textArea.setText(valueToBeInserted+"     "+"\t"); 
     hilal.addComponent(textArea); 

     hilal.show(0, 10, 10, 10, true); 

    } 

    } 
); 


b4.addActionListener(new ActionListener() { 


    public void actionPerformed(ActionEvent ae) { 

    try{ 
     players2_recordStore = RecordStore.openRecordStore("My Record Store", true); 

     } 


    catch(Exception ex) 
    { 
     ex.printStackTrace(); 
    } 

String [] carded2 = SearchCarded_team2(); 
int j; 
String valueToBeInserted2=""; 

for(j=0;j< SearchCarded_team2().length;j++) 
    { 


valueToBeInserted2=valueToBeInserted2 + " " + carded2[j]; 


     } 
Dialog hilal2 = new Dialog(" "); 
    Style Dialogstyle = hilal2.getSelectedStyle() ; 
hilal2.setTitle("All red carded players"); 
     hilal2.setScrollable(false); 
hilal2.getDialogStyle().setBgColor(0x0066CC); 
     hilal2.setTimeout(5000); 
     TextArea textArea = new TextArea(); 
     textArea.setFocusable(false); 

     textArea.setText(valueToBeInserted2+"     "+"\t"); 
     hilal2.addComponent(textArea); 

     hilal2.show(0, 10, 10, 10, true); 
txtfield6.clear(); 
    } 

    } 
); 

     f.show(); 

    } 

    public void pauseApp() {} 

    public void destroyApp(boolean unconditional) {} 

    public void actionPerformed(ActionEvent ae) { 
     notifyDestroyed(); 
    } 

public class form5 extends com.sun.lwuit.Form 


    { 



    public form5() 

      { 

    com.sun.lwuit.Form form5 = new com.sun.lwuit.Form("Cards' Records "); 


      } 


} 





} 

回答

4

openRecordStore()方法的第一个参数是RecordStore名称。您打开两次相同的RecordStore; “我的唱片店”。如果你想让他们成为两家不同的唱片店,那么你需要给他们两个不同的名字。