The last article describes the development of the environment and some relevant knowledge of the introduction, this article is going to introduce how to achieve the mobile phone and mobile phone through the Bluetooth communication program, and then the next day may write a simple mobile phone via the Bluetooth internet games (other things more, plus the author more lazy, Oh, forgive me ~).
This small program is a C/s structure, but only one jar package. After running the program, the first page will have a two option (server or client), when you select the server, click the Select button will enter the server interface, click the Setup button, then open the server side of the program, and loop listening to the Bluetooth connection from the client; And if you choose the Client option, will enter the client interface, click Connect will start to search around the device and traverse the target services on the device, if the search to the service will be connected to the server, you can enter the text box and click to send information, the server will feedback the appropriate information.
Oh, although the realization of the function is simple, but want to do more complex applications, this step or must go ~ First look at my program file structure:
---core//CORE package name
---bluemessage.java//midlet main class, program entry
---components//Component Package name
---mainform.java//Start main interface (select client or server side here)
---blueclient.java//Client interface, inherit from form, implement Commandlistener interface
---blueserver.java//server-side interface, inherit from form, implement Commandlistener interface
---bluetooth
---blueclientservice.java//encapsulates a client-side Bluetooth service class that implements Runnable and Discoverylistener interfaces
---blueserverservice.java//encapsulates the server-side Bluetooth service class and implements the Runnable interface
Well, for the program file structure has a certain understanding, look at the next part of the code:
Bluemessage.java file:
/**
* MIDlet Application main class
* @author royen
* @since 2010.1.24
*/
public class Bluemessag E extends MIDlet {
Public bluemessage () {
MainForm form=new mainform (this);
Display.getdisplay (This). Setcurrent (form);
}
/**
* Exit Application
*/
public void Exitmidlet () {
try{
This.destroyapp (TRUE);
}
catch (Exception ex) {
System.out.println ("Occur Exception" +ex.getmessage ());
}
/**
* Navigating to other interfaces
* @param dis
*/
public void NavigateTo (displayable dis) {
Display.getdisplay (this). setcurrent (dis);
}
protected void startApp () throws midletstatechangeexception {
}
protected void Destroyap P (Boolean arg0) throws Midletstatechangeexception {
}
Protectedvoid Pauseapp () {
//TOdo auto-generated Method stub}