Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,7 @@ | |||
#Thu, 19 Apr 2012 01:38:28 +0700 | #Thu, 19 Apr 2012 01:44:46 +0700 | ||
app-version.autoincrement=true | app-version.autoincrement=true | ||
config.active= | config.active= | ||
deployment.counter=62 | deployment.counter=63 | ||
deployment.number=0.0.61 | deployment.number=0.0.62 | ||
javadoc.preview=true | javadoc.preview=true | ||
netbeans.user=C\:\\Users\\Linh\\.netbeans\\7.1.1 | netbeans.user=C\:\\Users\\Linh\\.netbeans\\7.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,86 @@ | |||
package hello; | |||
|
|||
import com.cubeia.firebase.clients.java.connector.PacketListener; | |||
import com.cubeia.firebase.io.ProtocolObject; | |||
import com.cubeia.firebase.io.protocol.LoginRequestPacket; | |||
import com.cubeia.firebase.io.protocol.LoginResponsePacket; | |||
import java.io.IOException; | |||
import java.security.GeneralSecurityException; | |||
import javax.microedition.lcdui.*; | |||
import javax.microedition.midlet.MIDlet; | |||
import org.huy.firebase.clients.j2me.connector.SocketConnector; | |||
|
|||
/** | |||
* @author | |||
* Huy Thai | |||
*/ | |||
public class HelloMidlet extends MIDlet implements CommandListener { | |||
|
|||
private Form loginForm; | |||
private TextField usernameTextField; | |||
private TextField passwordTextField; | |||
private Command cancel; | |||
private Command login; | |||
private Display display; | |||
|
|||
private SocketConnector connector; | |||
|
|||
public void startApp() { | |||
loginForm = new Form("Login"); | |||
usernameTextField = new TextField("Username", "", 200, TextField.ANY); | |||
passwordTextField = new TextField("Password", "", 200, TextField.PASSWORD); | |||
cancel = new Command("Cancel", Command.CANCEL, 2); | |||
login = new Command("Login", Command.OK, 2); | |||
display = Display.getDisplay(this); | |||
loginForm.append(usernameTextField); | |||
loginForm.append(passwordTextField); | |||
loginForm.addCommand(cancel); | |||
loginForm.addCommand(login); | |||
loginForm.setCommandListener(this); | |||
display.setCurrent(loginForm); | |||
|
|||
try { | |||
connector = new SocketConnector("localhost", 4123); | |||
TestLoginListener listener = new TestLoginListener(); | |||
connector.addListener(listener); | |||
connector.connect(); | |||
|
|||
} catch (GeneralSecurityException ex) { | |||
} catch (IOException ex) { | |||
} | |||
} | |||
|
|||
public void pauseApp() { | |||
} | |||
|
|||
public void destroyApp(boolean unconditional) { | |||
connector.disconnect(); | |||
notifyDestroyed(); | |||
} | |||
|
|||
public void commandAction(Command c, Displayable d) { | |||
String label = c.getLabel(); | |||
if (label.equals("Cancel")) { | |||
destroyApp(true); | |||
} else if (label.equals("Login")) { | |||
login(usernameTextField.getString(), passwordTextField.getString()); | |||
} | |||
} | |||
|
|||
private void login(String username, String pass) { | |||
LoginRequestPacket pak = new LoginRequestPacket(); | |||
pak.user = username; | |||
pak.password = pass; | |||
pak.operatorid = 0; | |||
connector.send(pak); | |||
} | |||
|
|||
private class TestLoginListener implements PacketListener { | |||
|
|||
public void packetRecieved(ProtocolObject packet) { | |||
LoginResponsePacket re = (LoginResponsePacket) packet; | |||
Alert notice = new Alert("Welcome", "Welcom user: " + re.pid, null, AlertType.INFO); | |||
display.setCurrent(notice, loginForm); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,30 +1,3 @@ | |||
1. Download and install Netbeans and J2ME SDK 3.05 | 1. Download and install Netbeans and J2ME SDK 3.05 | ||
2. Build FirebaseJ2meClientTest project and run tests | 2. Build FirebaseJ2meClientTest project and run tests | ||
3. Connection example: | 3. See HelloMidlet.java for example | ||
try { | |||
SocketConnector connector = new SocketConnector("localhost", 4123); | |||
connector.connect(); | |||
|
|||
LoginListener listener = new LoginListener(); | |||
connector.addListener(listener); | |||
LoginRequestPacket pak = new LoginRequestPacket(); | |||
pak.user = "test"; | |||
pak.password = "1234"; | |||
pak.operatorid = 0; | |||
connector.send(pak); | |||
|
|||
// This is just an example to wait for result, you should implement call back listener | |||
while (listener.loginPacket == null) { | |||
try { | |||
Thread.sleep(50); | |||
} catch (InterruptedException ex) { | |||
} | |||
} | |||
|
|||
LoginResponsePacket result = (LoginResponsePacket) listener.loginPacket; | |||
// Get pid of current login user: result.pid; | |||
connector.disconnect(); | |||
|
|||
} catch (GeneralSecurityException ex) { | |||
} catch (IOException ex) { | |||
} |