Tugas Ujian Online Java Mobile

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import java.util.Date;

/**
 * @author Marthin CH
 */
public class UjianOnline extends MIDlet implements CommandListener{
   
    //Initializing the commands
    private Command mExitCommand, mStartCommand, mDoneCommand, mBackCommand;
   
    //Initializing the forms
    private Form mRegister, mQuestion, mSummary;
   
    //Initializing the display
    private Display mDisplay;
   
    //Initializing the textfield
    private TextField mName, mClass;
   
    //Initializing the date
    private DateField mDate;
   
    //Initializing the choicegroup
    private ChoiceGroup mGender, mQ1, mQ2, mQ3, mQ4, mQ5;
   
    //Initializing the string item
    private StringItem sName, sClass, sGender, sDate, sQ1, sQ2, sQ3, sQ4, sQ5;
 
    public void startApp() {
        if(mRegister == null){
            //Build registration form
            mRegister = new Form("Register account");
           
            //Instantiation of command exit & start
            mExitCommand = new Command ("Exit", Command.OK, 0);
            mStartCommand = new Command ("Start", Command.OK, 0);
           
            //Build textfield of name
            mName = new TextField("Name : ", "", 100, TextField.ANY);
            mName.getString();
            mRegister.append(mName);
           
            //Build datefield of date of birth
            mDate = new DateField("Date of Birth : ", DateField.DATE);
            mRegister.append(mDate);
           
            //Build choicegroup of gender
            mGender = new ChoiceGroup("Gender : ", ChoiceGroup.EXCLUSIVE);
            mGender.append("Male", null);
            mGender.append("Female", null);
            mRegister.append(mGender);
           
            //Build textfield of class
            mClass = new TextField("Class : ", "", 18, TextField.ANY);
            mClass.getString();
            mRegister.append(mClass);
           
            //Set command start & exit
            mRegister.addCommand(mStartCommand);
            mRegister.addCommand(mExitCommand);
            mRegister.setCommandListener(this);
           
            //Set display
            mDisplay = Display.getDisplay(this);
            Display.getDisplay(this).setCurrent(mRegister);
        }
       
        if(mQuestion == null){
            //Build question form
            mQuestion = new Form("Questions List");
           
            //Instantiation of command done & back
            mDoneCommand = new Command ("Done", Command.OK, 0);
            mBackCommand = new Command ("Back", Command.OK, 0);
           
            //Set the choicegroup as question in form
            mQ1 = new ChoiceGroup("What is the result of 0 + 1 = ..... ", ChoiceGroup.EXCLUSIVE);
            mQ1.append("0", null);
            mQ1.append("1", null);
            mQ1.append("2", null);
            mQ1.append("3", null);
            mQuestion.append(mQ1);
           
            //Set the choicegroup as question in form
            mQ2 = new ChoiceGroup("What is the result of 1 + 1 = ..... ", ChoiceGroup.EXCLUSIVE);
            mQ2.append("0", null);
            mQ2.append("1", null);
            mQ2.append("2", null);
            mQ2.append("3", null);
            mQuestion.append(mQ2);
           
            //Set the choicegroup as question in form
            mQ3 = new ChoiceGroup("What is the result of 1 + 2 = ..... ", ChoiceGroup.EXCLUSIVE);
            mQ3.append("0", null);
            mQ3.append("1", null);
            mQ3.append("2", null);
            mQ3.append("3", null);
            mQuestion.append(mQ3);
           
            //Set the choicegroup as question in form
            mQ4 = new ChoiceGroup("What is the result of 2 + 3 = ..... ", ChoiceGroup.EXCLUSIVE);
            mQ4.append("2", null);
            mQ4.append("3", null);
            mQ4.append("4", null);
            mQ4.append("5", null);
            mQuestion.append(mQ4);
           
            //Set the choicegroup as question in form
            mQ5 = new ChoiceGroup("What is the result of 3 + 4 = ..... ", ChoiceGroup.EXCLUSIVE);
            mQ5.append("6", null);
            mQ5.append("7", null);
            mQ5.append("8", null);
            mQ5.append("9", null);
            mQuestion.append(mQ5);
           
            //Set command back & done
            mQuestion.addCommand(mBackCommand);
            mQuestion.addCommand(mDoneCommand);
            mQuestion.setCommandListener(this);
           
            //Set display
            mDisplay = Display.getDisplay(this);
        }
     
        if(mSummary == null){
            //Build summary form
            mSummary = new Form("Summary");
           
            //Instantiation of command exit
            mSummary.addCommand(mExitCommand);
            mSummary.setCommandListener(this);

            //Instantiation of string items
            sName = new StringItem("Name            : ", null);
            sGender = new StringItem("Gender        : ", null);
            sClass = new StringItem("Class          : ", null);
            sQ1 = new StringItem("Answer's Question 1 : ", null);
            sQ2 = new StringItem("Answer's Question 2 : ", null);
            sQ3 = new StringItem("Answer's Question 3 : ", null);
            sQ4 = new StringItem("Answer's Question 4 : ", null);
            sQ5 = new StringItem("Answer's Question 5 : ", null);
         
            //Set the string item into summary form
            mSummary.append(sName);
            mSummary.append(sGender);
            mSummary.append(sClass);
            mSummary.append(sQ1);
            mSummary.append(sQ2);
            mSummary.append(sQ3);
            mSummary.append(sQ4);
            mSummary.append(sQ5);
        }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }
   
    public void commandAction(Command c, Displayable d){
        if(c == mExitCommand){
            destroyApp(true);
            notifyDestroyed();
        }
       
        //Set up register form after clicked on back command
        else if(c == mBackCommand){
            mDisplay.setCurrent(mRegister);
        }
       
        //Set up question form after clicked on start command
        else if(c == mStartCommand){
            mDisplay.setCurrent(mQuestion);
        }
       
        //Set up summary form after clicked on done command
        else if(c == mDoneCommand){
            //Initializing some strings
            String stName, stGender, stClass, stQ1, stQ2, stQ3, stQ4, stQ5 = null;
           
            //Getting the value of each item in all of form
            stName = mName.getString();
            stGender = mGender.getString(mGender.getSelectedIndex());
            stClass = mClass.getString();
            stQ1 = mQ1.getString(mQ1.getSelectedIndex());
            stQ2 = mQ2.getString(mQ2.getSelectedIndex());
            stQ3 = mQ3.getString(mQ3.getSelectedIndex());
            stQ4 = mQ4.getString(mQ4.getSelectedIndex());
            stQ5 = mQ5.getString(mQ5.getSelectedIndex());
           
            //Setting the value of each item in all of form to be displayed
            sName.setText(stName);
            sGender.setText(stGender);
            sClass.setText(stClass);
            sQ1.setText(stQ1);
            sQ2.setText(stQ2);
            sQ3.setText(stQ3);
            sQ4.setText(stQ4);
            sQ5.setText(stQ5);  
           
            mDisplay.setCurrent(mSummary);
        }
    }
}
Comments
0 Comments

0 Bacotan:

Related Posts Plugin for WordPress, Blogger...