السلام عليكم
هذا مشروع انشاء غرفة محادثة للموبايلات بين سيرفير وأكثر من كلاينت.... الكود التالي يحتوى على الواجهات فقط..... فهل من خبير يستطيع مساعدتى ويعطيني كود الاتصال؟.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MobileCommunication;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
/**
* @author i7948162
*/
public class MobileCommunication extends MIDlet implements CommandListener,ItemStateListener {
private Display display;
private Form selectionForm;
private Form clientForm;
private Form serverForm;
private Form ServerChat;
private Form ClientChat;
private ChoiceGroup options;
private TextField receivedTextSer;
private TextField transmitTextSer;
private TextField receivedTextClit;
private TextField transmitTextClit;
private TextField portNumberServer;
private TextField portNumberClient;
private TextField IPaddress;
static final Command transmittCommand = new Command("Transmit", Command.OK,1);
static final Command backCommand = new Command("Back", Command.BACK,0);
static final Command ConfCommand = new Command("Confirm", Command.OK,0);
static final Command GoCommand = new Command("Go", Command.OK,0);
static final Command ExitCommand = new Command("Exit", Command.EXIT,0);
public MobileCommunication() {
selectionForm = new Form("select what to be");
serverForm = new Form("Server.");
clientForm = new Form("Client.");
ServerChat = new Form("Server Chat.");
ClientChat = new Form("Client Chat.");
receivedTextSer = new TextField("Received Text:","",32,TextField.UNEDITABLE);
transmitTextSer = new TextField("Transmit Text:","",32,TextField.UNEDITABLE);
receivedTextClit = new TextField("Received Text:","",32,TextField.UNEDITABLE);
transmitTextClit = new TextField("Transmit Text:","",32,TextField.UNEDITABLE);
portNumberServer = new TextField("Port Number:","",32,TextField.UNEDITABLE);
portNumberClient = new TextField("Port Number:","",32,TextField.UNEDITABLE);
IPaddress = new TextField("IP Address:","",32,TextField.UNEDITABLE);
options = new ChoiceGroup("Client or Server",Choice.EXCLUSIVE);
ServerChat.append(receivedTextSer);
ServerChat.append(transmitTextSer);
serverForm.append(portNumberServer);
ClientChat.append(receivedTextClit);
ClientChat.append(transmitTextClit);
clientForm.append(portNumberClient);
clientForm.append(IPaddress);
options.append("Client.",null);
options.append("Server.",null);
selectionForm.append(options);
serverForm.addCommand(backCommand);
clientForm.addCommand(backCommand);
clientForm.addCommand(ConfCommand);
serverForm.addCommand(GoCommand);
ClientChat.addCommand(transmittCommand);
ClientChat.addCommand(ExitCommand);
ServerChat.addCommand(transmittCommand);
ServerChat.addCommand(ExitCommand);
serverForm.setCommandListener(this);
clientForm.setCommandListener(this);
selectionForm.setCommandListener(this);
selectionForm.setItemStateListener(this);
ServerChat.setCommandListener(this);
ClientChat.setCommandListener(this);
Date d = new Date();
Calendar c = Calendar.getInstance();
c.setTime(d);
String time = c.get(Calendar.HOUR_OF_DAY) + ":" +
c.get(Calendar.MINUTE) + ":" +
c.get(Calendar.SECOND);
}
public void itemStateChanged (Item item) {
if (item == options) {
String selected = options.getString(options.getSelectedIndex());
if(selected.equals("Server.")) {
System.out.println("You are a server.");
display.setCurrent(serverForm);
} else {
System.out.println("You are a Client.");
display.setCurrent(clientForm);
}
}
}
public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(selectionForm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command c, Displayable d) {
String event = null;
event = c.getLabel();
if (event.equals ("Back"))
display.setCurrent(selectionForm);
else if (event.equals ("Confirm"))
display.setCurrent(ClientChat);
else if (event.equals ("Go"))
display.setCurrent(ServerChat);
else if (event.equals("Exit"))
destroyApp(true);
}
}
