2 つの RecordStores player1_recordStore と
player2_recordStore 。のすべてのレコードを取得するための 2 つのメソッド method SearchCarded_team1
player1_recordStore、およびメソッド SearchCarded_team2 のすべてのレコードを取得する
player2_recordStore 。4 ボタン b1 は player1_recordStore に新しいレコードを追加するため、b2 は新しいレコードを追加するため
player2_recordStore へのレコード、プレーヤー1_recordStore のすべてのレコードを取得するための b3、および b4 への
player2_recordStore のすべてのレコードを取得します。
アプリケーションにいくつか問題があります
1- b3 ボタンまたは b4 を押すと、最初のレコードが表示されない!
2- player2_recordStore のレコードが、players1_recordStore のレコードの横に表示される理由
b3ボタンを押すと逆になります。
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 ");
}
}
}