আসসালামুআলাইকুম

আসা করি আপনারা সকলেই আল্লাহর রহমতে ভালো আছেন। আমিও ভালো আছি। আর ভালো না থাকলে তো ভালো লাগার ওয়েবসাইট TrickBD আছেই। যেখানে আমরা নিত্য নতুন টিপস এবং Trick পেয়ে থাকি।

তো যায় হোক, এত কথা না বলে আজকের টপিক এ চলে যাই। আজকে আমি আপনাদের সাথে J2me Alert নিয়ে আলোচনা করবো। কিভাবে আপনারা J2me বা Java Me te Alert তৈরি করবেন?

সেটাই আজকের এই পোস্ট এ আমি আপনাদের দেখাব।

তো Alert তৈরি করতে হলে নিচের step গুলো অনুসরন করুন।

প্রথমে আমরা global variable গুলো declare করে নেই।

 Display disp;
 Form f;
 Command exit, alarm, warning, error, info;

একাধিক variable declare এর জন্যে কমা ব্যবহার করুন।

এখন আমরা constructor এর ভিতরে variable গুলো initialize করবো।

disp = Display.getDisplay(this);
f = new Form("Hello World Alert");

আমরা Display এবং Form class লিখলাম। এখন, Command গুলো লিখব।

exit = new Command("Exit", Command.EXIT,0);
alarm = new Command("Alarm", Command.OK,0);
warning = new Command("Warning", Command.OK,0);
error = new Command("Error", Command.OK,0);
info = new Command("Info", Command.OK,0);

এখন আমরা Command গুলো Form এ যুক্ত করবো।

f.addCommand(exit);
f.addCommand(alarm);
f.addCommand(warning);
f.addCommand(error);
f.addCommand(info);
f.setCommandListener(this);

এখন আমরা Form টা startApp() Display তে show করাব।

disp.setCurrent(f);

এখন একটা alarmAlert() method তৈরি করবো।

public void alarmAlert() {

 }

এর ভিতরে আমরা Alert Type Alarm তৈরি করবো।

Alert a = new Alert("Alert","Alarm Alert Excuted", null, AlertType.ALARM);
 a.setTimeout(3000);

Alarm Alert তৈরি করা হল এবং এটি ৩ second স্থায়ি হবে। setTimeout এ আপনারা নিজের ইচ্ছে মতো milliseconds দিতে পারেন। এখন এই Alert টা Display তে show করাব। যখন alarm command এ click করা হবে তখন এটি excute হবে।

disp.setCurrent(a, f);

Alert তৈরির Structure নিচে দেখে নিন

new Alert("Title","Body", Image, AlertType);
 setTimeout(milliseconds);

এরপর, আমরা warningAlert() তৈরি করবো আগের টার মতো।

public void warningAlert() {

 }

এখন এটার ভিতরে আমরা Warning Alert তৈরি করবো and Display তে show করাব। যখন, Warning command এ click করা হবে তখন এটা Display তে show করবে।

Alert w = new Alert("Alert","Warning Alert Excuted", null, AlertType.WARNING);
w.setTimeout(3000);
disp.setCurrent(w, f);

তারপর, errorAlert() তৈরি করবো।

public void errorAlert() {

}

এখন আমরা এই errorAlert() এর ভিতরে Error Type Alert তৈরি করবো। যখন Error command এ click করা হবে তখন এটি excuted হবে।

Alert e = new Alert("Alert","Error Alert Excuted, null, AlertType.ERROR);
e.setTimeout(3000);
disp.setCurrent(e, f);

এখন, আমরা infoAlert() তৈরি করবো।

public void infoAlert() {

}

এখন, এটার ভিতরে info Alert তৈরি করবো জা Info Command এ click করলে Display তে Excute হবে।

Alert i = new Alert("Alert","Info Alert Excuted", null, AlertType.INFO);

এখন আমরা commandAction() এর কাজ করবো।

public void commandAction(Command c, Displayable d) {

}

এখন , আমরা Command গুলো কে handle করবো এটার ভিতর

if (c == exit) {
notifyDestroyed();
}

উক্ত Command এপ exit করতে ব্যবহার করা হয়েছে।
else if (c == alarm) {
alarmAlert();
}

Alarm এ Click করার পর alarmAlert() function টি excute হবে।

else if(c == warning) {
warningAlert();
}

Warning command এ click করার পর warningAlert() excute হবে

else if (c == error) {
errorAlert();
}

Error command click করার পর errorAlert() excute হবে।

else if (c == info) {
infoAlert();
}

Info command এ ক্লিক করার পর infoAlert() excute হবে।

এই পর্যন্তই ছিলো আজকের আলোচনা

নিচ থেকে পুরো Source কোড টি ডাউনলোড করে নেন

Download AlertExample

Show the full source code below

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

public class AlertExample extends MIDlet implements CommandListener {
 Display disp;
 Form f;
 Command exit, alarm, warning, error, info;

 public AlertExample() {
 disp = Display.getDisplay(this);
 f = new Form("Hello World Alert");
 exit = new Command("Exit", Command.EXIT,0);
 alarm = new Command("Alarm", Command.OK,0);
 warning = new Command("Warning", Command.OK,0);
 error = new Command("Error", Command.OK,0);
 info = new Command("Info", Command.OK,0); 
 f.addCommand(exit);
 f.addCommand(alarm);
 f.addCommand(warning);
 f.addCommand(error);
 f.addCommand(info);
 f.setCommandListener(this);
 f.append("Code With Nayeem24");
 }

 public void startApp() {
 disp.setCurrent(f);
 }

 public void pauseApp() {
 }

 public void destroyApp(boolean unconditional) {
 }

 public void alarmAlert() {
 Alert a = new Alert("Alert","Alarm Alert Excuted", null, AlertType.ALARM);
 a.setTimeout(3000);
 disp.setCurrent(a, f);
 }

 public void warningAlert() {
 Alert w = new Alert("Alert", "Warning Alert Excuted", null, AlertType.WARNING);
 w.setTimeout(3000);
 disp.setCurrent(w, f);
 }

 public void errorAlert() {
 Alert e = new Alert("Alert","Error Alert Excuted", null, AlertType.ERROR);
 e.setTimeout(3000);
 disp.setCurrent(e, f);
 }

 public void infoAlert() {
 Alert i = new Alert("Alert", "Info Alert Excuted", null, AlertType.INFO);
 i.setTimeout(3000);
 disp.setCurrent(i , f);
 }


 public void commandAction(Command c, Displayable d) {
 if (c == exit) {
 notifyDestroyed();
 } else if (c == alarm) {
 alarmAlert();
 } else if (c == warning) {
 warningAlert();
 } else if (c == error) {
 errorAlert();
 } else if (c == info) {
 infoAlert();
 }




 }
}

Thanks for read this post



13 thoughts on "J2me বা Java ME প্রোগ্রামিং শিখুন। এবং তৈরী করে ফেলুন Java ME Application আপনার হাতে থাকা জাভা ফোন টি দিয়ে (part: 7)"

    1. Nayeem24 Author Post Creator says:
      Thanks
    1. Nayeem24 Author Post Creator says:
      Thanks
    1. Nayeem24 Author Post Creator says:
      Thanks
    2. abir Author says:
      Wlc
  1. Levi Author says:
    সুন্দর।
    1. Nayeem24 Author Post Creator says:
      Thanks
    2. Levi Author says:
      Welcome.
    1. Nayeem24 Author Post Creator says:
      Thanks
  2. Shakib Expert Author says:
    keep it up vai ?

Leave a Reply