Create and Display Alert Objects using java and netbeans

Alert
Alert is a screen that displays data to the user and waits for a period of time before returning to the previous screen.

Alert Type:
Indicates the types of Alert objects to display.

Form
Form is a screen object that can be occupied by other items.

Work steps

  1. Opening Netbeans already installed.
    1.jpg

  2. Select File, then select New Project.
    2.jpg

  3. Next select Java ME in Categories
    3.jpg

  4. Then choose Mobile Application on Project.
    4.jpg

  5. Next press the Next button.
    5.jpg

  6. After that give the project name.
    6.jpg

  7. Then Select Platform in Device Configuration: CLDC-1.0 and Device Profile: MIDP-2.0.
    7.jpg

  8. Finish
    8.jpg

Program Files

Input :

import javax.microedition.midlet.;
import javax.microedition.lcdui.
;
public class Midlet extends MIDlet implements CommandListener {
private Display display;

to display on the desktop

private Form form;

create new coding

private Alert alert;

create for show alert

private Command cmdkeluar;

for command exit

private Command cmdalert;

public Midlet(){
display = Display.getDisplay(this);
form = new Form("Contoh Alert");
form.append("Contoh teks didalam form");
cmdkeluar = new Command("end",Command.EXIT,1);
cmdalert = new Command("alert",Command.SCREEN,2);

form.addCommand(cmdkeluar);
        form.addCommand (cmdalert);
form.setCommandListener(this);
}   

public void startApp() {
    display.setCurrent(form);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}


private void showAlert(){
        String info =   "ini adalah contoh pesan"+
                        "atau informasi yang akan"+
                        "disampaikan kepada user";
       # For show massage

alert = new Alert("Informasi",info,null,AlertType.ALARM);

alert.setTimeout(5000);
display.setCurrent(alert, form);
    }

public void commandAction(Command c,Displayable s){
if(c == cmdkeluar){
    destroyApp(true);
    notifyDestroyed();
}else if (c == cmdalert){   
    showAlert();
    }
}

}

Output :
o1.jpg
o2.jpg
o3.jpg

The Final Result

hasil.jpg

Analysis Program

In this experimental program 4 is a program that uses the Alert object, the following syntax used in this experiment.

  • private Alert alert;
    Syntax used as a Variable of Alert.

  • private Form form;
    This syntax is used as a Variable of the Form.

Conclusion

Alert is a screen that displays data to the user and waits for a period of time before returning to the previous screen.
Form is a screen object that can be occupied by other items.



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center