Java Reference
In-Depth Information
if (mustReturnToMainMenu) {
console.println("Please return to main menu.", Console.RED);
}
}
When receiving an error, we display its code in red, so the user
pays attention to what happened and acts accordingly. If the error
is severe and requires the game to go back to its main menu, the
mustReturnToMainMenu flag is set to true , and the game returns to
the main screen. Our implementation of the error handler is not very
sophisticated, but that's because little can go wrong when we are just
trying to say hello to the world.
After the login is successfully performed, our event listener is notified
with a call to Session :
public void loginSingleSignonSuccess(Session session,
Friend[] friendslist, Message[] motd) {
console.println("Login successful.", Console.GREEN);
smSession = session;
console.println("Sending echo...", Console.GREEN);
// send an echo
smSession.echo(10, "HelloWorld!");
}
In this method, we print out a success message and keep a reference
to the session instance, which is used to perform most of our requests.
We then send an echo request to the server, containing the 'HelloWorld!'
string, which is sent back to us by the SNAP Mobile server. This is
useful for testing that the connection remains alive. Figure B.6 shows our
application running on a mobile device.
Figure B.6 HelloWorld SNAP Mobile client running
Search WWH ::




Custom Search