Minggu, 19 April 2015

Hotel Reservation Berbasis J2ME Java Netbeans Politeknik Negeri Medan - Computer Engineering

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mobileapplication01tugas;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.lang.Math;
import java.util.Date;

public class HotelReservation extends MIDlet implements CommandListener {

    private static final String kReservation = "Reservation";
    private static final String kJKamar = "Jenis Kamar";
    private static final String kOpsiTambahan = "Opsi Tambahan";
    private static final String kSummary = "Summary";
    private static final String kExit = "Exit";
    private Display mDisplay;
    private List lJKList;
    private Form fReservation, fJKamar, fOT, fSummary;
    private Command mNextCommand = new Command("Next", Command.OK, 0);
    private Command mExitCommand = new Command("Exit", Command.EXIT, 0);
    private Command mBackCommand = new Command("Back", Command.BACK, 0);
    private DateField toCIn = new DateField("Check In :", DateField.DATE);
    private DateField toCOut = new DateField("Check Out :", DateField.DATE);
    private TextField toJumOrg = new TextField("Jumlah Orang :", "", 5, TextField.NUMERIC);
    private TextField toNama = new TextField("Nama :", "", 50, TextField.ANY);
    private TextField toPhone = new TextField("Phone :", "", 12, TextField.PHONENUMBER);
    private TextField toEmail = new TextField("Email :", "", 100, TextField.EMAILADDR);
    private ChoiceGroup toView = new ChoiceGroup("Choose The View", Choice.POPUP);
    private TextField toExtraBed = new TextField("Extra Bed :", "", 5, TextField.NUMERIC);
    private ChoiceGroup toLantai = new ChoiceGroup("Choose The Floor", Choice.POPUP);
    private TextField toLainnya = new TextField("More :", "", 500, TextField.ANY);
    private Date toCin1;
    private StringItem tiNama, tiPhone, tiEmail, tiCIn, tiCOut, tiJumOrg, tiJK, tiEB, tiV, tiLan, tiEtc;
    private String sNama, sPhone, sEmail, sCIn, sCOut, sJumOrg, sJK, sEB, sV, sLan, sEtc = null;

    public void startApp() {
        if (mDisplay == null) {
            fReservation = new Form("Enter your Reservation");
            fReservation.append(toNama);
            fReservation.append(toPhone);
            fReservation.append(toEmail);
            fReservation.append(toCIn);
            fReservation.append(toCOut);
            fReservation.append(toJumOrg);
            fReservation.addCommand(mNextCommand);
            fReservation.addCommand(mExitCommand);
            fReservation.setCommandListener(this);

            fOT = new Form("Fill This Form If You Want More");
            fOT.append(toExtraBed);
            toView.append("City", null);
            toView.append("Village", null);
            toView.append("Lake", null);
            toView.append("Garden", null);
            fOT.append(toView);
            for (int l = 0; l <= 30; l++) {
                String m = Integer.toString(l);
                toLantai.append(m, null);
            }
            fOT.append(toLantai);
            fOT.append(toLainnya);
            fOT.addCommand(mNextCommand);
            fOT.addCommand(mExitCommand);
            fOT.setCommandListener(this);

            JKList();

            tiNama = new StringItem("nama    : ", null);
            tiPhone = new StringItem("nim    : ", null);
            tiEmail = new StringItem("alamat : ", null);
            tiCIn = new StringItem("tempat tanggal lahir    : ", null);
            tiCOut = new StringItem("D/M/Y   : ", null);
            tiJumOrg = new StringItem("Study   : ", null);
            tiJK = new StringItem("Room Type : ", null);
            tiEB = new StringItem("Extra Bed : ", null);
            tiV = new StringItem("View : ", null);
            tiLan = new StringItem("Floor  :", null);
            tiEtc = new StringItem("More :", null);

            fSummary = new Form("Your Reservation");
            fSummary.append(tiNama);
            fSummary.append(tiPhone);
            fSummary.append(tiEmail);
            fSummary.append(tiCIn);
            fSummary.append(tiCOut);
            fSummary.append(tiJumOrg);
            fSummary.append(tiEB);
            fSummary.append(tiV);
            fSummary.append(tiLan);
            fSummary.append(tiEtc);
            fSummary.addCommand(mNextCommand);
            fSummary.addCommand(mExitCommand);
            fSummary.setCommandListener(this);
            mDisplay = Display.getDisplay(this);
        }
        mDisplay.setCurrent(fReservation);
    }

    public void JKList() {
        lJKList = new List("Choose Your Rooms Type", List.MULTIPLE);
        lJKList.append("President Suit", null);
        lJKList.append("Extra Deluxe", null);
        lJKList.append("Deluxe", null);
        lJKList.append("Sandard", null);
        lJKList.addCommand(mNextCommand);
        lJKList.addCommand(mBackCommand);
        lJKList.setCommandListener(this);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == mExitCommand) {
            destroyApp(true);
            notifyDestroyed();
        } else if (c == mNextCommand) {
            if (d == fReservation) {
                mDisplay.setCurrent(lJKList);
                int actionIndex = lJKList.getSelectedIndex();
                if (actionIndex < 0) {
                    return;
                }
                else if (actionIndex >= 0 && actionIndex <= 3) {
                    for (int i = 0; i < actionIndex; i++) {
                        String alert = "Anda memilih :" + lJKList.getString(actionIndex);
                        lJKList.append(alert, null);
                        JKList();
                    }

                }
            } else if (d == lJKList) {

                mDisplay.setCurrent(fOT);
             
            } else {
                sNama = toNama.getString();
                sPhone = toPhone.getString();
                sEmail = toEmail.getString();
                sCIn = String.valueOf(toCIn);
                sCOut = String.valueOf(toCOut);
                sJumOrg = toJumOrg.getString();
                sJK = lJKList.getString(lJKList.getSelectedIndex());
                sEB = toExtraBed.getString();
                sV = toView.getString(toView.getSelectedIndex());
                sLan = toLantai.getString(toLantai.getSelectedIndex());
                sEtc = toLainnya.getString();

                tiNama.setText(sNama);
                tiPhone.setText(sPhone);
                tiEmail.setText(sEmail);
                tiCIn.setText(sCIn);
                tiCOut.setText(sCOut);
                tiJumOrg.setText(sJumOrg);
                tiJK.setText(sJK);
                tiEB.setText(sEB);
                tiV.setText(sV);
                tiLan.setText(sLan);
                tiEtc.setText(sEtc);

                mDisplay.setCurrent(fSummary);
            }
        }
    }
}




Hasil Program Di Atas :