Kali ini saya akan membahas bagaimana menampilkan MessageBox dengan menggunakan SWT di eclipse. Buatlah project baru dan beri nama project dengan “MessageBoxApp“

pada group Project layout pilih Create separate source and output folders.

Lalu klik tombol Finish.
Adapun Icon Style untuk MessageBox ini adalah:
SWT.ICON_ERROR
SWT.ICON_INFORMATION
SWT.ICON_QUESTION
SWT.ICON_WARNING
SWT.ICON_WORKING
Sekarang buatlah file visual class dengan memilih icon New Java Class pada toolbar IDE

Setelah window New Java Class tampil, isikan kolom Package dengan “myMessageBoxApp” dan kolom Name dengan “MessageBoxDemo”

Selanjutnya pada kategori Style pilih Shell dan yang terakhir aktifkan/beri tanda centang public static void main(String[] args) dan klik tombol Finish.

Setelah Form dari Visual Editor tampil, klik kanan Form lalu pilih Set Layout->null. Kemudian tambahkan Object button seperti gambar berikut

Style Button milik MessageBox sebagai berikut
SWT.OK -> menampilkan tombol OK
SWT.OK | SWT.CANCEL -> menampilkan tombol OK dan CANCEL
SWT.YES | SWT.NO -> menampilkan tombol YES dan NO
SWT.YES | SWT.NO | SWT.CANCEL -> menampilkan tombol YES, NO, dan CANCEL
SWT.RETRY | SWT.CANCEL -> menampilkan tombol RETRY dan CANCEL
SWT.ABORT | SWT.RETRY | SWT.IGNORE -> menampilkan tombol ABORT, RETRY, dan IGNORE
Sekarang kita coba untuk menuliskan kodenya. Klik kanan object button ICON ERROR, saat menu konteks tampil, pilih Events->widgetSelected, dan ketikkan kode berikut
int style = SWT.ICON_ERROR;
MessageBox msg = new MessageBox(sShell, style);
msg.setMessage(“Error message…”); // set isi pesan error
msg.setText(“Error”); // set judul window
msg.open(); // tampilkan messagebox
untuk actionListener widgeSelected button ICON INFORMATION, ketikkan kode berikut
int style = SWT.ICON_INFORMATION;
MessageBox msg = new MessageBox(sShell, style);
msg.setMessage(“Information Icon”);
msg.setText(“Information”);
msg.open();
untuk actionListener widgeSelected button ICON QUESTION, ketikkan kode berikut
int style = SWT.ICON_QUESTION | SWT.YES | SWT.NO;
MessageBox msg = new MessageBox(sShell, style);
msg.setMessage(“Question Icon..”);
msg.setText(“Question”);
msg.open();
untuk actionListener widgeSelected button ICON WARNING, ketikkan kode berikut
int style = SWT.ICON_WARNING;
MessageBox msg = new MessageBox(sShell, style);
msg.setMessage(“Warning Icon..”);
msg.setText(“Warning”);
msg.open();
untuk actionListener widgeSelected button ICON WORKING, ketikkan kode berikut
int style = SWT.ICON_WORKING;
MessageBox msg = new MessageBox(sShell, style);
msg.setMessage(“Working Icon..”);
msg.setText(“Working”);
msg.open();
Lalu jalankan program Anda.
