src.doc

braintreesmileΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 6 μέρες)

284 εμφανίσεις

/*


* To change this template, choose Tools | Templates


* and open the template in the editor.


*/


package hello;


import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import org.netbeans.microedition.lcdui.LoginScreen;

import org.netbe
ans.microedition.lcdui.SplashScreen;

import org.netbeans.microedition.lcdui.WaitScreen;

import org.netbeans.microedition.util.SimpleCancellableTask;


/**


* @author Kunal


*/

public class HelloMIDlet extends MIDlet implements CommandListener {



private

boolean midletPaused = false;



//<editor
-
fold defaultstate="collapsed" desc=" Generated Fields ">


private Command exitCommand;


private Command login;


private Command exitCommand1;


private LoginScreen loginScreen;


private SplashScreen splashScreen;


private WaitScreen waitScreen;


private Alert alertSuccess;


private Alert alertFailure;


private SimpleCancellableTask task;


private SimpleCancellableTask task1;


//</editor
-
fold>




/**


* The HelloMIDlet constructor.


*/


public HelloMIDlet() {


}



//<editor
-
fold defaultstate="collapsed" desc=" Generated Methods ">


//</editor
-
fold>



//<editor
-
fold defaults
tate="collapsed" desc=" Generated Method: initialize ">


/**


* Initilizes the application.


* It is called only once when the MIDlet is started. The method is called before the
<code>startMIDlet</code>

method.


*/


private void initialize() {


// write pre
-
initialize user code here




// write post
-
initialize user code here


}



//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">


/**


* Performs an action assigned to the Mobile Device
-

MIDlet Star
ted point.


*/


public void startMIDlet() {


// write pre
-
action user code here


switchDisplayable(null, getSplashScreen());


// write post
-
action use
r code here


}


//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">


/**


* Performs an action
assigned to the Mobile Device
-

MIDlet Resumed point.


*/


public void resumeMIDlet() {


// write pre
-
action user code here




// write post
-
action user cod
e here


}


//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable
">


/**


* Switches a c
urrent displayable in a display. The <code>display</code> instance is
taken from <code>getDisplay</code> method. This method is used by all actions in the
design for switching displayable.


* @param alert the Alert which is temporarily set to the displ
ay; if
<code>null</code>, then <code>nextDisplayable</code> is set immediately


* @param nextDisplayable the Displayable to be set


*/


public void switchDisplayable(Alert alert, Displayable nextDisplayable) {



// write pre
-
switch user code here


Display display = getDisplay();


if (alert == null) {


display.setCurrent(nextDisplayable);


} else {


display.se
tCurrent(alert, nextDisplayable);


}


// write post
-
switch user code here


}


//</editor
-
fold>



//<editor
-
fold defaults
tate="collapsed" desc=" Generated Method: commandAction for
Displayables ">


/**


* Called by a system to indicated that a command has been invoked on a particular
displayable.


* @param command t
he Command that was invoked


* @param displayable the Displayable where the command was invoked


*/


public void commandAction(Command command, Displayable displayable) {


// write pre
-
action

user code here


if (displayable == loginScreen) {


if (command == LoginScreen.LOGIN_COMMAND) {


// write pre
-
action user code here





// write post
-
action user code here


} else if (command == exitCommand1) {


// write pre
-
action user code here


switchDi
splayable(null, getSplashScreen());


// write post
-
action user code here


}


} else if (displayable == splashScreen) {


if (co
mmand == SplashScreen.DISMISS_COMMAND) {


// write pre
-
action user code here


switchDisplayable(null, getLoginScreen());


// wr
ite post
-
action user code here


}


} else if (displayable == waitScreen) {


if (command == WaitScreen.FAILURE_COMMAND) {


// wri
te pre
-
action user code here


switchDisplayable(getAlertFailure(), getLoginScreen());


// write post
-
action user code here


} else if (command == WaitScreen.SUCCESS_COMMAND
) {


// write pre
-
action user code here


switchDisplayable(getAlertSuccess(), getLoginScreen());


// write post
-
action user c
ode here


}


}


// write post
-
action user code here


}


//</editor
-
fold>





//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">


/**


* Returns an initiliazed instance of exitCommand component.


* @return the initialized component instance



*/


public Command getExitCommand() {


if (exitCommand == null) {


// write pre
-
init user code here


exitCommand = new Command("Exit", Command.EXIT, 0);


// write post
-
init user code here


}


return exitCommand;


}


//</editor
-
fold>







//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: loginScreen ">



/**


* Returns an initiliazed instance of loginScreen component.


* @return the initialized component instance


*/


public LoginScreen getLoginScreen() {


if (loginScreen == null) {



// write pre
-
init user code here


loginScreen = new LoginScreen(getDisplay());


loginScreen.setLabelTexts("Username", "Password");


loginScreen.setTitle("loginScre
en");


loginScreen.addCommand(LoginScreen.LOGIN_COMMAND);


loginScreen.addCommand(getExitCommand1());


loginScreen.setCommandListener(this);


loginScreen.setBGColor(
-
3355444);


loginScreen.setFGColor(0
);


loginScreen.setUseLoginButton(false);


loginScreen.setLoginButtonText("Login");


// write post
-
init user code here


}


return loginScreen;


}



//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: login ">


/**


* Returns an initiliazed instance of login component.


* @return the initialized c
omponent instance


*/


public Command getLogin() {


if (login == null) {


// write pre
-
init user code here


login = new Command("Screen", Command.SCREEN, 0);



// write post
-
init user code here


}


return login;


}


//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: splashScreen ">



/**


* Returns an initiliazed instance of splashScreen component.


* @return the initialized component instance


*/


public SplashScreen getSplashScreen() {


if (splashScreen == null) {



// write pre
-
init user code here


splashScreen = new SplashScreen(getDisplay());


splashScreen.setTitle("splashScreen");


splashScreen.setCommandListener(this);



splashScreen.setText("Kunal
\
's Example");


// write post
-
init user code here


}


return splashScreen;


}


//</editor
-
fold>



//<e
ditor
-
fold defaultstate="collapsed" desc=" Generated Getter: waitScreen ">


/**


* Returns an initiliazed instance of waitScreen component.


* @return the initialized component instance


*/


public WaitS
creen getWaitScreen() {


if (waitScreen == null) {


// write pre
-
init user code here


waitScreen = new WaitScreen(getDisplay());


waitScreen.setTit
le("waitScreen");


waitScreen.setCommandListener(this);


waitScreen.setTask(getTask1());


// write post
-
init user code here


}


return waitScreen;



}


//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: alertSuccess ">


/**


* Returns an initiliazed instance of alertSuccess component.


* @return

the initialized component instance


*/


public Alert getAlertSuccess() {


if (alertSuccess == null) {


// write pre
-
init user code here


alertSuccess = new Alert("alert", "Welcome Kunal
!!!", null, null);


alertSuccess.setTimeout(Alert.FOREVER);


// write post
-
init user code here


}


return alertSuccess;


}


//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: alertFailure ">


/**


* Returns an initiliazed instance of alertFailure component.


* @return t
he initialized component instance


*/


public Alert getAlertFailure() {


if (alertFailure == null) {


// write pre
-
init user code here


alertFailure = new Alert("alert", "Login Failed !!!
", null, null);


alertFailure.setTimeout(Alert.FOREVER);


// write post
-
init user code here


}


return alertFailure;


}



//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: task ">


/**


* Returns an initiliazed instance of task component.


* @return the initialized comp
onent instance


*/


public SimpleCancellableTask getTask() {


if (task == null) {


// write pre
-
init user code here


task = new SimpleCancellableTask();


task.setExecutable(new org.netbeans.microedition.util.Executable() {


public void execute() throws Exception {


login();


}



});


// write post
-
init user code here


}


return task;


}


//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Gen
erated Getter: task1 ">


/**


* Returns an initiliazed instance of task1 component.


* @return the initialized component instance


*/


public SimpleCancellableTask getTask1() {


if (task1 == null)

{


// write pre
-
init user code here


task1 = new SimpleCancellableTask();


task1.setExecutable(new org.netbeans.microedition.util.Executable() {



public void execute() throws Exception {


login();


}


});


// write post
-
init user code h
ere


}


return task1;


}


//</editor
-
fold>



//<editor
-
fold defaultstate="collapsed" desc=" Generated Getter: exitCommand1 ">


/**


* Returns a
n initiliazed instance of exitCommand1 component.


* @return the initialized component instance


*/


public Command getExitCommand1() {


if (exitCommand1 == null) {


// write pre
-
init user code
here


exitCommand1 = new Command("Exit", Command.EXIT, 0);


// write post
-
init user code here


}


return exitCommand1;


}


//</editor
-
fold>




/**


* Returns a display instance.


* @return the display instance.


*/


public Display getDisplay () {


return Display.getDisplay(this);


}



/**


* Exits MIDlet.


*/


public void exitMIDlet() {



switchDisplayable (null, null);


destroyApp(true);


notifyDestroyed();


}



/**


* Called when MIDlet is started.


* Checks whether the MIDlet have been already started and initialize/starts or resumes
the MIDlet.


*/


p
ublic void startApp() {


if (midletPaused) {


resumeMIDlet ();


} else {


initialize ();


startMIDlet ();


}


midletPaused = false;


}



/**


* Called when MIDlet is paused.


*/



public void pauseApp() {


midletPaused = true;


}



/**


* Called to signal the MIDlet to terminate.


* @param unconditional if true, then the MIDlet has to be unconditionally terminated
and all resources has to be released.


*/



public void destroyApp(boolean unconditional) {


}




private void login() throws Exception {




if(getLoginScreen().getUsername().equals("kunal") &&
getLoginScreen().getPassword().equals("kunal")) {


return;



}


throw new Exception("The login was not successful");


}



}