⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientform.java

📁 Bluetooth echo between pc server and client
💻 JAVA
字号:
// ClientForm.java// Andrew Davison, ad@fivedots.coe.psu.ac.th, August 2005/* This class is the GUI in front of an EchoClient object   which manages the sending and receiving of messages with   the chosen echo service.   A message is input via messageTF, and send to the   service using EchoClient's echoMessage() method.    This method _waits_ for an answer from the server.    ClientForm shows the response in responseSI.   If EchoClient detects an error when communicating with   the server, it notifies the client by setting the   statusSI field, and disabling any further input from   ClientForm's messageTF field. It also writes the current    status of the interaction into statusSI.*/import javax.microedition.lcdui.*;import javax.bluetooth.*;public class ClientForm extends Form implements CommandListener{  // GUI elements  private Command sendCmd, exitCmd;  private TextField messageTF;    // message to send  private StringItem statusSI, responseSI;                     // for info coming from the server  private EchoClient echoClient;       // handles the bluetooth communication with the server  private Display display;  private EchoClientMIDlet ecm;  public ClientForm(ServiceRecord sr, EchoClientMIDlet ecm, Display d)  {    super("Bluetooth Echo Client");    this.ecm = ecm;    display = d;     // GUI    sendCmd = new Command("Send", Command.SCREEN, 2);    exitCmd = new Command("Exit", Command.EXIT, 1);    addCommand(exitCmd);    messageTF = new TextField("Enter message here: ", "", 25,                         TextField.ANY | TextField.UNEDITABLE);                                  // will change to editable later    responseSI = new StringItem("Response: ", "");    statusSI = new StringItem("Status: ", "Starting...");    append(messageTF);    append(responseSI);    append(statusSI);    setCommandListener(this);    echoClient = new EchoClient(sr, this);    echoClient.start();   // connect to the server          } // end of ClientForm()  public void commandAction(Command c, Displayable d)   {    if (c == exitCmd) {      echoClient.closeDown();      ecm.destroyApp(true);    }    else if (c == sendCmd) {         String resp = echoClient.echoMessage( messageTF.getString() );         /* Pass the input message to EchoClient, and _wait_ for a            reply. The answer can be an error message. */      responseSI.setText(resp);  // show the response      // messageTF.setString("");    }  }  // end of commandAction()  // ------- called from EchoClient --------------------------  public void setStatus(String msg)  // report the status of the server connection   {  statusSI.setText(msg);  }  public void setEnable(boolean isEnabled)  /* Enable/disable the message text field. The text field is     disabled when the server is unable to process any messages     e.g. when the server link has broken.  */  {  if (isEnabled) {       messageTF.setConstraints(TextField.ANY);       addCommand(sendCmd);     }     else {   // disable the text field       messageTF.setConstraints(TextField.ANY | TextField.UNEDITABLE);       removeCommand(sendCmd);     }  }} // end fo ClientForm class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -