The Visual Mobile Designer (VMD) is a graphical interface within NetBeans Mobility that enables you to design mobile applications using drag and drop components. The VMD allows you to define the application flow and design your GUI using the components supplied by the IDE or components you design yourself. The VMD contains many standard User Interface (UI) components that you can use to create applications such as Lists, Alerts, Forms and Images. It also includes custom components that simplify the creation of more complex features, such as Wait Screens, Splash Screens, Table Items and more.
The Login Screen custom component provides a useful user interface with standard elements such as Username Field, Password Field and Login Button. You can use this custom component to create the login interface for accessing protected features such as GSM banking.
This example shows how to use the Login Screen custom component within a client application and how to connect it to server resources using authenticated access. In addition to the NetBeans Mobility Project we also need to use a NetBeans Web Project. To complete this tutorial it is necessary to know how to work with NetBeans Web Projects and to have local or remote access to a web application server like GlassFish or Tomcat.
If you are new to NetBeans Mobility or J2EE, you should start with the NetBeans Java ME MIDP Quick Start Guide and Introduction to Developing Web Applications before continuing.
For help getting your system set up, please see the installation instructions.
Before we begin you might want to see final result of the tutorial.
Take the following steps to install the LoginScreenExample application:
The Navigator Window for Mobility Project LoginScreenExample should look like the following:
In the Projects window, right-click the project LoginScreenServletExample node and choose Run Project (or press F6 key). Make sure that your application server works on the port 8080. Second step is to right-click the project LoginScreenExample node and choose Run Project. As the application runs, an emulator window opens and displays the application running in the default device emulator. In the Emulator window, click the button underneath "Launch."
alertSuccess component displayed on the screen with a "Login Successful" message.Now that you have seen the Login Screen component in action, let's go back to the beginning and create this application from scratch. In this tutorial we are only going to create a Java ME client using NetBeans Mobility pack. If you'd like to learn more about server side of this application look at the LoginScreenServletExample project sources. To create a Java ME client application do the following:
LoginScreenExample in the Project Name field. Change the Project Location to a directory on your system. Let's refer to this directory as $PROJECTHOME. Uncheck the Create Hello MIDlet checkbox. Click Next. Leave the Sun Java Wireless Toolkit as the selected Target Platform. Click Next, the Finish. Note: The project folder contains all of your sources and project metadata, such as the project Ant script. The application is displayed in the Flow Design window of the Visual Mobile Designer.LoginScreenExample project in the Project Window, then choose File > New File (Ctrl-N) . Under Categories, select Java Classes. Under File Types, select Java Package. Click Next. Enter loginscreenexample in the Package Name field. Click Finish. Choose the loginscreenexample package in the Project window, then choose File > New File (Ctrl-N) . Under Categories, select MIDP. Under File Types, select Visual MIDlet. Click Next. Enter LoginScreenExample into MIDlet Name and MIDP Class Name fields. Click Finish.
private boolean login = false;. At the end of the source code paste following code:
private void login() throws IOException {
//URL
String url = "http://localhost:8080/LoginScreenExample/"
+ "?username=" + getLoginScreen().getUsername()
+ "&password=" + getLoginScreen().getPassword();
//Clean up alertSuccess
getAlertSuccess().setString("");
//Connect to the server
HttpConnection hc = (HttpConnection) Connector.open(url);
//Authentication
if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
login = true;
}
//Closing time...
hc.close();
//Take action based on login value
if (login) {
getAlertSuccess().setString("Login Succesfull");
} else {
getAlertSuccess().setString("Wrong Username or Password");
}
login = false;
}
This code is responsible for sending a request with information about the username and password to the server and receiving an answer if the login process was successful. You can correct source code imports by pressing Ctrl+Shift+I.
The NetBeans IDE provides API Javadocs for the Login Screen component, as well as other components you can use in the VMD. To read the Javadocs for the Login Screen component:
org.netbeans.microedition.lcdui to see links for the component information.You are viewing a mobilized version of this site...
View original page here