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);
        }
    }
}
Read More..

Tugas Reservasi Hotel

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

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

/**
 * @author Marthin CH
 */
public class Reservation extends MIDlet implements CommandListener {

    private Command mContinueCommand, mDoneCommand, mCancelCommand, mExitCommand;
    private Form fListMenu, fRoom, fBookingAndPayment;
    private Display dDisplay;
    private TextField txtName, txtPhone;
    private DateField dfCheckIn, dfCheckOut;
    private ChoiceGroup cgGender, cgRoomList, cgFoodService, cgFacilities;
    private Alert aAlert;
    private StringItem sName, sGender, sPhone, sCheckIn, sCheckOut, sRoomList, sFacilities, sFoodService;

    public void startApp() {

        mContinueCommand = new Command("Continue", Command.OK, 0);
        mDoneCommand = new Command("Done", Command.OK, 0);
        mCancelCommand = new Command("Cancel", Command.OK, 0);
        mExitCommand = new Command("Exit", Command.OK, 1);

        if (fListMenu == null) {
            fListMenu = new Form("Register Menu");

            txtName = new TextField("Full Name : ", "", 100, TextField.INITIAL_CAPS_WORD);
            txtName.getString();
            fListMenu.append(txtName);

            cgGender = new ChoiceGroup("Gender : ", ChoiceGroup.EXCLUSIVE);
            cgGender.append("Male", null);
            cgGender.append("Female", null);
            fListMenu.append(cgGender);

            dfCheckIn = new DateField("Check In : ", DateField.DATE);
            fListMenu.append(dfCheckIn);

            dfCheckOut = new DateField("Check Out : ", DateField.DATE);
            fListMenu.append(dfCheckOut);

            txtPhone = new TextField("Phone Number : ", "", 100, TextField.PHONENUMBER);
            txtPhone.getString();
            fListMenu.append(txtPhone);

            fListMenu.addCommand(mExitCommand);
            fListMenu.addCommand(mContinueCommand);
            fListMenu.setCommandListener(this);

            dDisplay = Display.getDisplay(this);
        }

        if (fRoom == null) {
            fRoom = new Form("Hotel Room List's, Food Service, Facilities & Views");
            fRoom.addCommand(mCancelCommand);
            fRoom.addCommand(mDoneCommand);
            fRoom.setCommandListener(this);

            cgRoomList = new ChoiceGroup("Please select which room would like to use : ", List.EXCLUSIVE);
            cgRoomList.append("Standard", null);
            cgRoomList.append("Deluxe", null);
            cgRoomList.append("President Suite", null);
            fRoom.append(cgRoomList);

            cgFacilities = new ChoiceGroup("Please select which's one of addition facility in your room : ", List.EXCLUSIVE);
            cgFacilities.append("Internet + TV Analog", null);
            cgFacilities.append("Internet + Tv Cable", null);
            cgFacilities.append("Internet + Internet TV", null);
            fRoom.append(cgFacilities);

            cgFoodService = new ChoiceGroup("Please select which's your food service : ", List.EXCLUSIVE);
            cgFoodService.append("Breakfast & Lunch", null);
            cgFoodService.append("Lunch & Dinner", null);
            cgFoodService.append("Breakfast & Dinner", null);
            fRoom.append(cgFoodService);

            dDisplay = Display.getDisplay(this);
        }

        if (fBookingAndPayment == null) {
            fBookingAndPayment = new Form("Room's Booking and Payment");
            fBookingAndPayment.addCommand(mCancelCommand);
            fBookingAndPayment.addCommand(mExitCommand);
            fBookingAndPayment.setCommandListener(this);

            sName = new StringItem("Name                        : ", null);
            sGender = new StringItem("Gender                    : ", null);
            sPhone = new StringItem("Phone                      : ", null);
            sRoomList = new StringItem("RoomList                : ", null);
            sFacilities = new StringItem("Facilities            : ", null);
            sFoodService = new StringItem("Food Service         : ", null);
         
            //Set the string item into summary form
            fBookingAndPayment.append(sName);
            fBookingAndPayment.append(sGender);
            fBookingAndPayment.append(sPhone);
            fBookingAndPayment.append(sFacilities);
            fBookingAndPayment.append(sRoomList);
            fBookingAndPayment.append(sFoodService);
        }

        Display.getDisplay(this).setCurrent(fListMenu);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == mExitCommand) {
            destroyApp(true);
            notifyDestroyed();
        } else if (c == mContinueCommand) {
            if (cgFacilities.equals("Internet + Internet TV")) {
                aAlert = new Alert("This facility is only available fo president suite");
                dDisplay.setCurrent(aAlert, fListMenu);
            }
            dDisplay.setCurrent(fRoom);
        } else if (c == mDoneCommand) {
            String stName, stGender, stPhone, stRoomList, stFacilities, stFoodService = null;
           
            stName = txtName.getString();
            stGender = cgGender.getString(cgGender.getSelectedIndex());
            stPhone = txtPhone.getString();
            stRoomList = cgRoomList.getString(cgRoomList.getSelectedIndex());
            stFacilities = cgFacilities.getString(cgFacilities.getSelectedIndex());
            stFoodService = cgFoodService.getString(cgFoodService.getSelectedIndex());
           
            sName.setText(stName);
            sGender.setText(stGender);
            sPhone.setText(stPhone);
            sRoomList.setText(stRoomList);
            sFacilities.setText(stFacilities);
            sFoodService.setText(stFoodService);
           
            dDisplay.setCurrent(fBookingAndPayment);
        }
    }
}

Read More..

Push Registry

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

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.wireless.messaging.*;

/**
 * @author MA
 */
public class TextMessage extends MIDlet implements CommandListener{

    protected static final String kConnection = "sms://:50000";
    private Display mDisplay;
    private Form mForm;
    private Command mExitCommand;
    private Command mRegisterCommand, mUnregisterCommand;
   
   
    public void startApp() {
        if(mForm == null){
            mForm = new Form("Push MIDlet");
            mExitCommand = new Command("Exit", Command.OK, 0);
            mRegisterCommand = new Command("Register", Command.OK, 0);
            mUnregisterCommand = new Command("Unregister", Command.OK, 0);
            mForm.addCommand(mExitCommand);
            mForm.addCommand(mRegisterCommand);
            mForm.addCommand(mUnregisterCommand);
            mForm.setCommandListener(this);
            mDisplay = Display.getDisplay(this);
        }
        mDisplay.setCurrent(mForm);
        try{
            String[] connections;
            connections = PushRegistry.listConnections(false);
            if(connections.length > 0){
                mForm.append("Registered connections : ");
                for(int i=0; i<connections.length; i++)
                    mForm.append(connections[i]);
            }
           
            connections = PushRegistry.listConnections(true);
            if(connections.length > 0){
                mForm.append("Connections waiting ");
                for(int i=0; i<connections.length; i++)
                    mForm.append(" " + connections[i]);
            }
        }
        catch(Exception e){
            mForm.append(e.toString());
        }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }
   
    public void commandAction(Command c, Displayable d){
        if(c == mExitCommand){
            destroyApp(true);
            notifyDestroyed();
        }
        else if(c == mRegisterCommand){
            RegisterRunnable rr = new RegisterRunnable(mForm);
            Thread t = new Thread(rr);
            t.start();
        }
         else if(c == mUnregisterCommand){
            UnregisterRunnable ur = new UnregisterRunnable(mForm);
            Thread t = new Thread(ur);
            t.start();
        }
    }
}
   
    class RegisterRunnable implements Runnable{
        private Form mForm;
        public RegisterRunnable(Form f){
            mForm = f;
        }
       
        public void run()
        {
            try{
                PushRegistry.registerConnection(TextMessage.kConnection, "Push MIDlet", "*");
                mForm.append("Registered !");
            }
            catch(Exception e){
                mForm.append(e.toString());
            }
        }
    }
   
    class UnregisterRunnable implements Runnable{
        private Form mForm;
        public UnregisterRunnable(Form f){
            mForm = f;
        }
       
        public void run(){
            try{
                PushRegistry.unregisterConnection(TextMessage.kConnection);
                mForm.append("Unregistered !");
            }
            catch(Exception e){
                mForm.append(e.toString());
            }
        }
    }
Read More..
Related Posts Plugin for WordPress, Blogger...