This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Mirza - www.mirzaahcmad.ml

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Kamis, 02 Juni 2016

Memasukkan Aplikasi Skype ke Dalam Program Chat

Kali ini kita akan mencoba melakukan link skype lain di aplikasi chat yang telah kita buat, hal ini bisa digunakan sebagai launcher aplikasi dengan basis pemrograman java.


pertama silahkan buka aplikasi netbean, dan sebagai contoh kita akan menggunakan project chat client yang telah kita buat sebelumnya.
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
*
* @author andik
*/
public class ChatClient extends javax.swing.JFrame {

/**
* Creates new form ChatClient
*/
private ObjectInputStream input;
private ObjectOutputStream output;
private Socket socket;
private String server, username;
private int port;
private List clients;
private List dialogs;

public ChatClient() {
clients = new ArrayList<>();
dialogs = new ArrayList<>();
initComponents();
}

public boolean start() {
try {
socket = new Socket(server, port);
} catch (Exception ec) {
System.out.println("Error connectiong to server:" + ec);
return false;
}

String msg = "Connection accepted " + socket.getInetAddress() + ":" + socket.getPort();
System.out.println(msg);

try {
input = new ObjectInputStream(socket.getInputStream());
output = new ObjectOutputStream(socket.getOutputStream());
} catch (IOException eIO) {
System.out.println("Exception creating new Input/output Streams: " + eIO);
return false;
}

new ChatClient.ListenFromServer().start();

try {
output.writeObject("login~" + username + "~" + username + " sedang login...~server~\n");
output.writeObject("list~" + username + "~" + username + " sedang login...~server~\n");

} catch (IOException eIO) {
System.out.println("Exception doing login : " + eIO);
disconnect();
return false;
}

return true;
}

private void disconnect() {
try {
// TODO add your handling code here:
output.writeObject("logout~" + username + "~" + username + " sudah logout...~Server~\n");
} catch (IOException ex) {
//Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
}

try {
if (input != null) {
input.close();
}
} catch (Exception e) {
}
try {
if (output != null) {
output.close();
}
} catch (Exception e) {
}
try {
if (socket != null) {
socket.close();
}
} catch (Exception e) {
}
}

class ListenFromServer extends Thread {

@Override
public void run() {
while (true) {
try {
String msg = (String) input.readObject();
String res;
String type = msg.split("~")[0];
String pengirim = msg.split("~")[1];
String text = msg.split("~")[2];
String kepada = msg.split("~")[3];
switch (type) {
case "recieveText":
res = pengirim + ": " + text;
viewTextArea.setText(viewTextArea.getText() + res + "\n");
break;
case "recievePrivateText":
res = pengirim + ": " + text;

if (kepada.equals(username)) {
for (PMDialog pMDialog : dialogs) {
if (pMDialog.getName().equals(pengirim)) {
pMDialog.display(res);
pMDialog.setVisible(true);
break;
}
}
}

break;
case "login":
viewTextArea.setText(viewTextArea.getText() + pengirim + " sedah login..." + "\n");
clients.add(pengirim);
break;
case "logout":
viewTextArea.setText(viewTextArea.getText() + pengirim + " telah logout..." + "\n");
clients.remove(pengirim);
for (PMDialog pMDialog : dialogs) {
if (pMDialog.getName().equals(pengirim)) {
dialogs.remove(pMDialog);
break;
}
}
break;
case "list":
setTable(text);
break;
}
} catch (IOException e) {
System.out.println("Server has close the connection: " + e);
break;
} catch (ClassNotFoundException e2) {
}
}
}

private void setTable(String text) {
int rows = text.split(":").length - 1;
Object[][] data = new Object[rows][1];

for (int i = 0; i < rows; i++) { String t = text.split(":")[i]; data[i][0] = t; boolean ada = false; for (PMDialog pMDialog : dialogs) { if (pMDialog.getName().equals(t)) { ada = true; } } if (!ada) { PMDialog pmd = new PMDialog(ChatClient.this, socket, input, output, username, t); pmd.setName(t); pmd.setTitle(username + "/" + t); dialogs.add(pmd); } } String[] header = {"Clients"}; clientTable.setModel(new DefaultTableModel(data, header) { @Override public boolean isCellEditable(int row, int column) { return false; } }); } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") //
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
popupMenu1 = new java.awt.PopupMenu();
popupMenu2 = new java.awt.PopupMenu();
jPanel3 = new javax.swing.JPanel();
usernameTextField = new javax.swing.JTextField();
masukButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
viewTextArea = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
clientTable = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
postTextField = new javax.swing.JTextField();
serverTextField = new javax.swing.JTextField();
kirimButton = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
portTextField = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);

popupMenu1.setLabel("popupMenu1");

popupMenu2.setLabel("popupMenu2");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel3.setBackground(new java.awt.Color(0, 102, 255));

usernameTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
usernameTextFieldActionPerformed(evt);
}
});

masukButton.setText("Masuk");
masukButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
masukButtonActionPerformed(evt);
}
});

viewTextArea.setColumns(20);
viewTextArea.setRows(5);
jScrollPane1.setViewportView(viewTextArea);

clientTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
clientTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
clientTableMouseClicked(evt);
}
});
jScrollPane2.setViewportView(clientTable);

jLabel1.setText("Server");

postTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
postTextFieldActionPerformed(evt);
}
});

kirimButton.setText("Kirim");
kirimButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kirimButtonActionPerformed(evt);
}
});

jLabel2.setText("Port");

jLabel3.setText("Username");

jLabel4.setFont(new java.awt.Font("Liberty Island Laser", 1, 24)); // NOI18N
jLabel4.setText("Aplikasi MultiChatClient");

jButton1.setFont(new java.awt.Font("Alien Encounters", 1, 12)); // NOI18N
jButton1.setText("Call");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(postTextField)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(kirimButton))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(portTextField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(serverTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(10, 10, 10)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(usernameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
.addComponent(masukButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(220, 220, 220)
.addComponent(jLabel4)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(14, 14, 14)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(3, 3, 3)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(serverTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(portTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(masukButton)))
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(postTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
.addComponent(kirimButton)))
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addContainerGap())
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
}//

private void masukButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.server = serverTextField.getText();
this.port = new Integer(portTextField.getText());
this.username = usernameTextField.getText();
setTitle(server + ":" + port + "/" + username);
start();
}

private void kirimButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
String message = "postText~" + username + "~" + postTextField.getText() + "~all~\n";
output.writeObject(message);
postTextField.setText("");
} catch (IOException ex) {
Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
}
}

private void postTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
kirimButtonActionPerformed(evt);
}

private void clientTableMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (evt.getClickCount() == 2 && clientTable.getSelectedRow() >= 0) {
String kepada = (String) clientTable.getValueAt(clientTable.getSelectedRow(), 0);
for (PMDialog pMDialog : dialogs) {
if (pMDialog.getName().equals(kepada) && !kepada.equals(username)) {
pMDialog.setTitle(username + "/" + kepada);
pMDialog.display("Silakan tulis pesan kepada " + kepada);
pMDialog.setVisible(true);
return;
}
}
}
}

private void usernameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String path = new String("C:\\Program Files (x86)\\Skype\\\\Phone\\Skype.exe");
System.out.println("Menjalankan MS Word");
try {
Process theProcess = Runtime.getRuntime().exec(path);
} catch(IOException e)
{
System.err.println("Error on exec() method");
e.printStackTrace();
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ChatClient().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JTable clientTable;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton kirimButton;
private javax.swing.JButton masukButton;
private java.awt.PopupMenu popupMenu1;
private java.awt.PopupMenu popupMenu2;
private javax.swing.JTextField portTextField;
private javax.swing.JTextField postTextField;
private javax.swing.JTextField serverTextField;
private javax.swing.JTextField usernameTextField;
private javax.swing.JTextArea viewTextArea;
// End of variables declaration
}
lalu, tambahkan jbutton dan rubah captionnya menjadi video.
lalu klik kanan pilih event >> action >> actionperformed
lalu masukan kode berikut

try {
proc = rt.exec(“C:\\Program Files\\Skype\\Phone\\Skype.exe”);
}
catch(Exception e) {
System.out.println(“Cannot execute application”);
}
disini kita menggunakan aplikasi skype sebagai contoh.
kalian bisa menggunakan aplikasi lain seperti camstudio, steam, origin dll.
lalu tambahkan deklarasi berikut agar java dapat memanggil aplikasinya.

Process proc;
Runtime rt = Runtime.getRuntime();
lalu silahkan di jalankan di netbean.
untuk lebih lengkapnya kalian bisa mengunduh kode lengkapnya disini.

Rabu, 01 Juni 2016

Aplikasi kirim SMS Menggunakan Sun JAVA Wireless Toolkit

Kali ini kita akan membahas mengenai bagaimana membuat aplikasi kirim sms dengan

menggunakan java. Untuk membuatnya, kita memerlukan alat-alat sebagai berikut.
 
1.   1 buah laptop/ komputer
2.   Software Sun Java (TM) Wireless Toolkit 2.5.2_01 for CLDC
3.   Notepad, Notepad++ atau TextPad untuk mengetik listing programnya

Langkah Langkah :
1. Kita jalankan dulu Sun Java (TM) Wireless Toolkit 2.5.2_01 for CLDC. Setelah itu, klik New Project, di ProjectName kita ketikkan nama project kita sesuai keinginan, misalnya smsKu, di MIDlet Class Name ketikkan tulisan yang sama, Lalu klik Create Project.


2. Selanjutnya akan  muncul kotak dialog setting,  kita klik OK saja.  Setelah itu akan tampil tulisan
§    Creating project smsKu
§    Place Java source files in C:\MyDocuments\ Java\j2mewtk\252\apps\smsKu\src”
§    Ket: Disinilah tempat kita menyimpan source atau koding program yang kita
buat yaitu pada direktori SRC
§    Place Aplication resource files in C:\MyDocuments\ Java\j2mewtk\252\apps\smsKu\res”
§    Ket: Disinilah tempat kita menyimpan file gambar atau animasi yang kita buat
yaitu pada direktori RES

§    Place Aplication library files in C:\MyDocuments\ Java\j2mewtk\252\apps\smsKu\lib”
§    Ket:  Disinilah  tempat  kita  menyimpan  file  fungsi  yang  kita  buat  yaitu  pada
 direktori LIB
3. Kita beralih ke Notepad, dan ketikkan listing program berikut:
import java.util.*;
import java.io.IOException; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.wireless.messaging.*; import javax.microedition.midlet.*;
public class smsKu extends MIDlet implements CommandListener, Runnable, MessageListener {
Display display; Form form;
List menuList; //list untuk menu awal
Command exitCom, replyCom, backCom, clrCom, sendCom; //command yg digunakan TextBox textSmsMasuk, textSmsKeluar; //tempat text sms yg masuk & yg mau dikirim TextField textNo; //untuk tempat memasukan no tujuan
String port, isiSmsKeluar; //port dan isi sms
Thread thread; String[] connections; boolean done;
MessageConnection smsconn; Message msg;
public smsKu() {
display = Display.getDisplay(this);
form = new Form("sms-an Yuk");
exitCom = new Command("keluar", Command.EXIT, 1);
replyCom = new Command("Adriansyah MS", Command.SCREEN, 1);


backCom = new Command("Kembali", Command.BACK, 3); clrCom = new Command("Hapus Tulisan", Command.OK, 2); sendCom = new Command("Adriansyah MS", Command.OK, 1); menuList = new List("Menu sms Ku", List.IMPLICIT);
port = "4321"; //port yang aku gunakan, ganti sesuai keinginan masing masing
textSmsMasuk = new TextBox(null, null, 500, TextField.ANY);
textSmsKeluar = new TextBox("Silakan Menulis Sms", null,
500, TextField.ANY);
textNo = new TextField("Masukan Nomor Tujuan", "",
15, TextField.PHONENUMBER);
}
public void startApp() {
bukaKoneksi(); //disini membuka koneksi untuk siap menerima sms masuk menu(); // bikin tampilan menu awal
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
//sebelum aplikasinya keluar ato mati koneksi ditutup dulu done = true;
thread = null;
if (smsconn != null) {
try {
smsconn.close();
} catch (IOException e) {
}
}


//disini mati deh aplikasi kita notifyDestroyed();
}
public void menu() { //membuat menu awal untuk sementara ini baru ada 3 menu menuList.append("Tulis Sms", null);//1. menu tulis sms baru menuList.append("about", null);//2. menu about (dak penting jugo sebenarnya) menuList.append("Keluar", null);//3. menu untuk keluar aplikasi menuList.addCommand(exitCom); //add command keluar menuList.setCommandListener(this);
display.setCurrent(menuList);
}
public void tulisSms() { //membuat textbox untuk menulis sms baru textSmsKeluar.addCommand(sendCom); //add command untuk kirim textSmsKeluar.addCommand(clrCom); // add command untuk clear text textSmsKeluar.addCommand(backCom); //add command untuk kembali kemenu awal textSmsKeluar.setCommandListener(this);
display.setCurrent(textSmsKeluar);
}
public void masukNo() { //disini untuk memasukan nomor tujuan form.setTitle("Sms Siap dikirim"); //udah taukan yang ini? form.append(textNo); //menambahkan textField untuk nomor tujuan
form.addCommand(backCom);  //menambahkan  command  untuk  kembali  ke  menu awal
form.addCommand(sendCom); //menambahkan command untuk mengirim form.setCommandListener(this);
display.setCurrent(form);
}
public void kirim() { //disini sms yang udah ditulis dikirim dgn perintah


new Thread(new Runnable() {
//perhatiin ya public void run() { try {
String isiSms = isiSmsKeluar;
String noTujuan = textNo.getString();
String address = "sms://" + noTujuan + ":" + port; MessageConnection smsConnKir = null;
Message isiSmsNya = null;
smsConnKir = (MessageConnection) Connector.open(address); TextMessage txtmessage =
(TextMessage) smsConnKir.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address); txtmessage.setPayloadText(isiSms); isiSmsNya = txtmessage; smsConnKir.send(isiSmsNya);
} catch (Throwable t) {
t.printStackTrace();
}
}
}).start();
}
public void terima(String isi, String no, Date tgl) { //tempat sms masuk
String nonya = fixNomer(no);
textSmsMasuk = new TextBox("Sms dari:" + nonya + " " + tgl, isi, isi.length(), TextField.ANY); textSmsMasuk.addCommand(replyCom); textSmsMasuk.addCommand(exitCom); textSmsMasuk.setCommandListener(this); display.setCurrent(textSmsMasuk);


}
public void bukaKoneksi() { //membuka koneksi agar bisa menerima sms yg masuk
String smsConnection = "sms://:" + port;
done = true;
thread = null;
try {
smsconn = (MessageConnection) Connector.open(smsConnection);
smsconn.setMessageListener(this);
} catch (IOException ioe) {
ioe.printStackTrace();
}
connections = PushRegistry.listConnections(true);
done = false;
thread = new Thread(this);
thread.start();
}
public void tutupKoneksi() { //untuk menutup koneksi sms try {
smsconn.close();
} catch (IOException e) {
}
}
public String fixNomer(String no) {
//dari format no gini "sms://+6285XXXX" jadi "+6285XXX" gitu fungsinya
String hs = null;


hs = no.substring(6, no.length());
return hs;
}
public void commandAction(Command c, Displayable d) {
if (c == exitCom) {
destroyApp(true);
}
if (d == menuList) {
if (menuList.isSelected(0)) {
tulisSms();
} else if (menuList.isSelected(1)) {
Alert about = new Alert("About", "Aplikasi SMS menggunakan j2me, " + "source-nya saya dapatkan dari “KAMU” J ",
null, AlertType.INFO);
display.setCurrent(about);
} else if (menuList.isSelected(2)) {
destroyApp(true);
}
}
if (d == textSmsKeluar) { if (c == sendCom) { form.deleteAll(); masukNo();
} else if (c == clrCom) {
textSmsKeluar.setString("");
} else if (c == backCom) {
display.setCurrent(menuList);
}
}
if (d == textSmsMasuk) {
if (c == exitCom) {


display.setCurrent(menuList);
} else if (c == replyCom) {
tulisSms();
}
}
if (d == form) {
if (c == backCom) { form.deleteAll(); display.setCurrent(textSmsKeluar);
} else if (c == sendCom) {
isiSmsKeluar = textSmsKeluar.getString();
textSmsKeluar.setString("");
kirim();
}
}
}
public void run() { //untuk menerima sms yang masuk try {
msg = smsconn.receive();
String senderAddress = msg.getAddress(); Date waktuSms = msg.getTimestamp();
if (msg instanceof TextMessage) {
String isiSmsMasuk = ((TextMessage) msg).getPayloadText();
terima(isiSmsMasuk, senderAddress, waktuSms);//memasukan sms ke texbok
} tutupKoneksi(); bukaKoneksi();
} catch (IOException e) {
}
}


public void notifyIncomingMessage(MessageConnection conn) {
if (thread == null) {
done = false;
thread = new Thread(this);
thread.start();
}
}
}
Simpan  program  tersebut  pada  direktori  src  seperti  di  atas  dengan  nama  smsKu.java (nama file harus sama dengan nama kelas pada saat kita membuat new project). Selanjutnya kita kembali lagi ke Sun Java (TM) Wireless Toolkit 2.5.2_01 for CLDC.
4. Kemudian, klik Build untuk mengetahui apakah program yang kita buat sudah benar atau belum. Jika masih terdapat kesalahan maka perhatikan kesalahannya pada baris kesalahan   dan   lokasi   kesalahan   yang   ditunjukan   pada   layar   konsul.   Perbaiki kesalahan program tersebut hingga selesai simpan dan ulangi Build kembali. Setelah proses build selesai jika tidak terdapat kesalahan, klik Run. Kita bisa coba jalankan aplikasi buatan kita. Dalam percobaan aplikasi ini, kita klik Run sebanyak 2kali atau lebih agar tampilan handphone menjadi 2-3 buah dengan nomor yang berbeda.
hasil tampilan 
 untuk lebih lengkapnya bisa anda download disini