Hotel Reservation menggunakan J2ME netbeans
package dlm.azwanty.irma;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.lang.Math;
import java.util.Date;
public class ReservasiHotelMidlet 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("Standard", 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);
}
}
}
}
Minggu, 19 April 2015
Jumat, 17 April 2015
Program Kirim SMS dan Terima SMS
KIRIMSMS
package mobileapplication2;
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.*;
public class KirimSMS extends MIDlet implements CommandListener, Runnable {
private Display display;
private Command cmdKeluar, cmdLanjut, cmdKembali, cmdKirim;
private Displayable prevScreen;
private TextBox tfNum, tfText;
private String port;
private Thread thread;
private Alert alert;
private final String INVALID_PHONE =
"Nomor yang dimasukkan tidak absah";
public KirimSMS() {
display = Display.getDisplay(this);
port = getAppProperty("Port-SMS");
cmdKeluar = new Command("Keluar", Command.EXIT, 1);
cmdLanjut = new Command("Lanjut", Command.SCREEN, 1);
cmdKembali = new Command("Kembali", Command.BACK, 1);
cmdKirim = new Command("Kirim", Command.SCREEN, 1);
alert = new Alert(null);
alert.setTimeout(3000);
}
public void startApp() {
tfNum = generatePhoneInput();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
notifyDestroyed();
} else if (c == cmdKembali) {
display.setCurrent(tfNum);
} else if (c == cmdLanjut) {
if (!isValidPhoneNumber(tfNum.getString())) {
alert.setType(AlertType.ERROR);
alert.setString(INVALID_PHONE);
display.setCurrent(alert, tfNum);
} else {
tfText = generateMessageInput();
}
} else {
thread = new Thread((java.lang.Runnable) this);
thread.start();
}
}
public void run() {
MessageConnection conn = null;
String alamat = "sms://" + tfNum.getString() + ":" + port;
try {
conn = (MessageConnection) Connector.open(alamat);
TextMessage pesan = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
pesan.setAddress(alamat);
pesan.setPayloadText(tfText.getString());
conn.send(pesan);
alert.setString("Sedang mengirim ke nomoe" + alamat.substring(6));
alert.setType(AlertType.INFO);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private TextBox generatePhoneInput() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private boolean isValidPhoneNumber(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private TextBox generateMessageInput() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
TERIMASMS
package mobileapplication2;
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
public class TerimaSMS extends MIDlet
implements CommandListener, Runnable, MessageListener {
private Display display;
private Alert alert;
private TextBox tfPesan;
private Thread thread;
private MessageConnection conn;
private Message pesan;
private String[] daftarKoneksi;
private boolean selesaiProses;
private String port;
private final Command cmdKeluar = new Command("Keluar", Command.EXIT, 1);
public TerimaSMS() {
port = getAppProperty("Port-SMS");
display = Display.getDisplay(this);
alert = new Alert("Terima SMS");
alert.setTimeout(Alert.FOREVER);
alert.addCommand(cmdKeluar);
alert.setCommandListener(this);
tfPesan = new TextBox(null, null, 500, TextField.ANY);
tfPesan.addCommand(cmdKeluar);
tfPesan.setCommandListener(this);
}
public void startApp() {
String alamatKoneksi = "sms://:" + port;
if (conn == null) {
try {
conn = (MessageConnection) Connector.open(alamatKoneksi);
conn.setMessageListener(this);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
daftarKoneksi = PushRegistry.listConnections(true);
if (daftarKoneksi == null || daftarKoneksi.length== 0) {
alert.setString("Menunggu SMS pada port" + port + "...");
}
startNewThread();
display.setCurrent(alert);
}
public void pauseApp() {
selesaiProses = true;
thread = null;
}
public void destroyApp(boolean unconditional) {
selesaiProses = true;
thread = null;
if (conn != null) {
try {
conn.close();
} catch (IOException e) {
}
}
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar || c == Alert.DISMISS_COMMAND) {
destroyApp(false);
notifyDestroyed();
}
}
// method ini ada karena kia mengimplementasikan
// interface Runnable
public void run() {
try {
pesan = conn.receive();
if (pesan != null) {
String alamatPengirim = pesan.getAddress();
tfPesan.setTitle("Pesan dari:" + alamatPengirim.substring(6));
if (pesan instanceof TextMessage) {
TextMessage pesanTeks = (TextMessage) pesan;
tfPesan.setString(pesanTeks.getPayloadText());
}
display.setCurrent(tfPesan);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
// method ini ada karena kita mengimplementasikan
// interface MessageListener
public void notifyIncomingMessage(MessageConnection conn) {
if (thread == null) {
startNewThread();
}
}
public void startNewThread() {
selesaiProses = false;
thread = new Thread(this);
thread.start();
}
}
Sabtu, 04 April 2015
Simulasi Web Browser dengan 4 Form Menggunakan Netbeans 7.3.1
package Irma Azwanty Dalimunthe;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class WebBrowser
extends MIDlet
implements CommandListener {
Display disp;
private Command exitCommand;
private Command page1;
private Command page2;
private Command page3;
private Command home;
public void startApp() {
Form formHome = new Form("Home");
formHome.append ("Selamat Datang Di Polmed");
exitCommand = new Command ("Exit", Command.EXIT, 1);
page1 = new Command ("Page 1", Command.SCREEN, 1);
page2 = new Command ("Page 2", Command.SCREEN, 1);
page3 = new Command ("Page 3", Command.SCREEN, 1);
formHome.addCommand(exitCommand);
formHome.addCommand(page1);
formHome.addCommand(page2);
formHome.addCommand(page3);
formHome.setCommandListener(this);
Display.getDisplay(this).setCurrent(formHome);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();
} else if (c == page1) {
Form formPage1 = new Form("Page 1");
formPage1.append ("Ini page 1");
home = new Command ("Home", Command.SCREEN,1);
page2 = new Command ("Page 2", Command.SCREEN, 1);
page3 = new Command ("Page 3", Command.SCREEN, 1);
exitCommand = new Command ("Exit", Command.EXIT, 1);
formPage1.addCommand(home);
formPage1.addCommand(page2);
formPage1.addCommand(page3);
formPage1.addCommand(exitCommand);
formPage1.setCommandListener(this);
Display.getDisplay(this).setCurrent(formPage1);
}
else if (c == page2) {
Form formPage2 = new Form("Page 2");
formPage2.append ("Ini page 2");
home = new Command ("Home", Command.SCREEN, 1);
page1 = new Command ("Page 1", Command.SCREEN, 1);
page3 = new Command ("Page 3", Command.SCREEN, 1);
exitCommand = new Command ("Exit", Command.EXIT, 1);
formPage2.addCommand(home);
formPage2.addCommand(page1);
formPage2.addCommand(page3);
formPage2.addCommand(exitCommand);
formPage2.setCommandListener(this);
Display.getDisplay(this).setCurrent(formPage2);
}
else if (c == page3){
Form formPage3 = new Form("Page 3");
formPage3.append ("Ini page 3");
home = new Command ("Home", Command.SCREEN, 1);
page1 = new Command ("Page 1", Command.SCREEN, 1);
page2 = new Command ("Page 2", Command.SCREEN, 1);
exitCommand = new Command ("Exit", Command.EXIT, 1);
formPage3.addCommand(home);
formPage3.addCommand(page1);
formPage3.addCommand(page2);
formPage3.addCommand(exitCommand);
formPage3.setCommandListener(this);
Display.getDisplay(this).setCurrent(formPage3);
}
else if (c == home){
Form formHome = new Form("Home");
formHome.append ("Selamat Datang Di Polmed");
exitCommand = new Command ("Exit", Command.EXIT, 1);
page1 = new Command ("Page 1", Command.SCREEN, 1);
page2 = new Command ("Page 2", Command.SCREEN, 1);
page3 = new Command ("Page 3", Command.SCREEN, 1);
formHome.addCommand(exitCommand);
formHome.addCommand(page1);
formHome.addCommand(page2);
formHome.addCommand(page3);
formHome.setCommandListener(this);
Display.getDisplay(this).setCurrent(formHome);
}
}
}
Langganan:
Postingan (Atom)