It is a screen mostly like message box appear public Alert ... · It is a screen mostly like...

18

Transcript of It is a screen mostly like message box appear public Alert ... · It is a screen mostly like...

Page 1: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors
Page 2: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

It is a screen mostly like message box appear to user as monition about specific procedure

This object have two constructors :

public Alert(String title)

Alert(String title, String alertText, Image alertImage, AlertType alertType)

Page 3: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

Title : appear above the box alertText : the text appear inside alert box and

the user read it alertImage : icon or image appear above the

alert box, write null if you don’t want image alertType : type of alert is one of these

WARNING , INFO , ERROR , CONFIRMATION , ALARM And the type written as follow AlertType.TYPE , replacing TYPE by one of

alert types

Page 4: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

public void addCommand(Command cmd)

public void setString(String str)

public void setTimeout(int time)

Set the time for which the Alert is to be shown. This must either be a positive time value in milliseconds, or the special value FOREVER.

Parameters : time - timeout in milliseconds, or FOREVER

Example : alert.setTimeout(5000);

Page 5: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

If we want to stay the show forever it done by written FOREVER in the Alert class

alert.setTimeout(Alert.FOREVER)

Example explain alert types and how to create it :

Page 6: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class MyAlert extends MIDlet implements CommandListener { private Display display; Command cmdExit = new Command( "Exit“ , Command.EXIT, 0); Command cmdAlert = new Command("Alert", Command.SCREEN, 0); Command cmdAlertError = new Command("Error", Command.SCREEN, 0);

Page 7: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

Command cmdAlertSave = new Command("Save", Command.SCREEN, 0); Form form; Alert alert; public MyAlert () { display =Display.getDisplay(this); form = new Form("Form Title"); alert = new Alert ( " Alert Title “ ); }

Page 8: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

public void startApp() { form.append("This is My Form"); form.addCommand(cmdExit); form.addCommand(cmdAlert); form.addCommand(cmdAlertError); form.addCommand(cmdAlertSave); form.setCommandListener(this); display.setCurrent(form);

}

Page 9: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

public void pauseApp(){ } public void destroyApp(boolean unconditional){} /************* implements CommandListener ****************/ public void commandAction(Command c, Displayable s) { if ( s == form ) { if (c == cmdExit) { destroyApp(false); notifyDestroyed(); }

Page 10: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

else if (c == cmdAlert) { alert.setString("Alert with command Ignore\n _____\n Alarm Type "); alert.setType(AlertType.ALARM); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert);} else if (c == cmdAlertError) { alert.setString("Alert with 5 second waitting \n _____\n Error Type"); alert.setType(AlertType.ERROR); alert.setTimeout(5000); display.setCurrent(alert); }

Page 11: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

else if (c == cmdAlertSave) { alert.setString("Alert with 3 second waitting

\n _____\n Confirmation Type"); alert.setType(AlertType.CONFIRMATION); alert.setTimeout(3000); display.setCurrent(alert); }} } // end commandAction

} // end Class

Page 12: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

Example explain : (Command cmdAlert = new Command("Alert",

Command.SCREEN, 0);

Command cmdAlertSave = new Command ("Save", Command.SCREEN,0);

Command cmdAlertError = new Command("Error", Command.SCREEN,0);

Define three commands and will used to show Alert types

Page 13: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

Form form;

used to show commands on it

Alert alert;

Alert appear on the screen and will change the type

public MyAlert () {

put the initial statement in the constructor

alert = new Alert (" Alert Title ");

Alert Title

Create object from Alert type and give it a title

{

Page 14: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

form.append("This is My Form");

Add text to the form

form.addCommand(cmdExit);

form.addCommand(cmdAlert);

form.addCommand(cmdAlertError);

form.addCommand(cmdAlertSave);

Add commands to form

Page 15: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

else if (c == cmdAlert)

choose this commands

alert.setString("Alert with command Ignore\n _____\n Alarm Type ");

Text appear in the alert object

alert.setType(AlertType.ALARM);

Set the type of alert ALARM

Page 16: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

alert.setTimeout(Alert.FOREVER); this alert will stay until user press done or ignore display.setCurrent(alert); show alert on screen after gave it’s properties else if (c == cmdAlertError) If we choose this command alert.setString("Alert with 5 second waitting

\n _____\n Error Type");

Show this text in alert object

Page 17: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors

alert.setType(AlertType.ERROR);

Set alert type ERROR and it like to alert “saved”

alert.setTimeout(3000);

Alert will appear just three seconds

display.setCurrent(alert);

Show this alert on screen

Page 18: It is a screen mostly like message box appear public Alert ... · It is a screen mostly like message box appear to user as monition about specific procedure This object have two constructors