How to add fields on screen with a loop running
Please Login to Remove!
Hi there,
I'm new to BB development and trying to have some buttons on the screen and a loop as a countdown timer running togather. But my codes only add the buttons on the screen after the loop finishes. Which kinds of Screen and Timer Classes should I use. My codes are as below and in the attachment. Thanks.
public class gameScreen extends MainScreen {
boolean answered;
long startTime;
RadioButtonGroup rbGroup;
String[] set;
RadioButtonField[] radioButton;
ButtonField submitButton;
FieldChangeListener submitFCL;
public gameScreen() {
answered = false;
startTime = System.currentTimeMillis();
rbGroup = new RadioButtonGroup();
radioButton = new RadioButtonField[4];
for (int i = 0; i < 4; i++) {
radioButton[i] = new RadioButtonField(set[i], rbGroup, false);
add(radioButton[i]);
}
submitButton = new ButtonField("Submit");
add(submitButton);
submitFCL = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
int valueOfRadioButton = rbGroup.getSelectedIndex();
if(set[valueOfRadioButton].equals("A"))
Dialog.alert("Answer is right!");
else Dialog.alert("Answer is wrong!");
answered = true;
}
};
submitButton.setChangeListener(submitFCL);
long leftTime = 3000-(System.currentTimeMillis() - startTime);
while ((leftTime >= 0) && !answered) {
leftTime = 3000-(System.currentTimeMillis() - startTime);
}
if (leftTime <= 0);
Dialog.inform("Time Out!");
}}
Last edited by zpluo; 06-09-2011 at 02:22 PM..
Reason: add attachment
|