Click here to Skip to main content
15,908,115 members
Home / Discussions / Java
   

Java

 
AnswerRe: How do i go about this Pin
jschell16-May-11 8:46
jschell16-May-11 8:46 
Questionhow to make a listener to receive from HttpConnection Pin
williamroma13-May-11 1:40
williamroma13-May-11 1:40 
AnswerRe: how to make a listener to receive from HttpConnection Pin
jschell13-May-11 8:57
jschell13-May-11 8:57 
GeneralRe: how to make a listener to receive from HttpConnection Pin
williamroma13-May-11 9:08
williamroma13-May-11 9:08 
GeneralRe: how to make a listener to receive from HttpConnection Pin
jschell13-May-11 12:19
jschell13-May-11 12:19 
GeneralRe: how to make a listener to receive from HttpConnection Pin
williamroma13-May-11 12:39
williamroma13-May-11 12:39 
GeneralRe: how to make a listener to receive from HttpConnection Pin
jschell13-May-11 12:55
jschell13-May-11 12:55 
GeneralRe: how to make a listener to receive from HttpConnection Pin
williamroma13-May-11 13:12
williamroma13-May-11 13:12 
the code in Client j2me
i beggin received when i pressed

receivedChat


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package myPage;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
*
* @author William
*/
public class Main extends MIDlet implements CommandListener {

//HTTPCONNECTION
// HttpConnection hc = null;
OutputStream out = null;
InputStream in = null;
String URL = "http://localhost:8080/DeleteWebApplication/RomaServlet";
//GUI IN J2ME
Display display = null;
Form mainScreem = null;
TextField emailTextfield = null;
TextField passwordTextfield = null;
Form contactScreem = null;
Command loginCommand = null;
Command getContactsCommand = null;
//ACCONT IN MSN
String sessionId;
//GUI FOR ERROR CONNECTION
Form errorScreem = null;
StringItem errorMessege = null;
Command back = null;
//MY ACCOUNT IN MSN
int numberOfContacts;
//GUI FOR CONTACTS FRIENDLYNAMES
Form ContactsList = null;
StringItem[] contactsListGui = null;
//GUI FOR CHAT WITH ONE CONTACTS
Form chatScreem = null;
Command backToContactsList = null;
Command sendIMToContact = null;

public Main() {
display = Display.getDisplay(this);
mainScreem = new Form("Welcome...");
emailTextfield = new TextField("Email", "", 100, TextField.ANY);
passwordTextfield = new TextField("Password", "", 100, TextField.PASSWORD);
contactScreem = new Form("Your Contacts are:");
loginCommand = new Command("login", Command.BACK, 1);
getContactsCommand = new Command("get commands", Command.OK, 2);
mainScreem.append(emailTextfield);
mainScreem.append(passwordTextfield);
mainScreem.addCommand(loginCommand);
mainScreem.addCommand(getContactsCommand);

errorScreem = new Form("ERROR");
errorMessege = new StringItem("", "Cann't Connection to " + URL);
back = new Command("back", Command.BACK, 1);
errorMessege.addCommand(back);
errorScreem.append(errorMessege);
errorScreem.setCommandListener(this);

mainScreem.setCommandListener(this);
display.setCurrent(mainScreem);
}

protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
}

protected void pauseApp() {
}

protected void startApp() throws MIDletStateChangeException {
}

public void commandAction(Command c, Displayable d) {
if (c == loginCommand) {
String email = emailTextfield.getString();
String password = passwordTextfield.getString();
try {
HttpConnection hc = (HttpConnection) Connector.open(URL);
if (sessionId != null) {
hc.setRequestProperty("cookie", sessionId);
}
emailTextfield.setString("totti_william88@hotmail.com");
passwordTextfield.setString("williamroma");
hc.setRequestProperty("type", 1 + "");
byte len = (byte) email.length();
out = hc.openOutputStream();
out.write(len);
byte[] emailBytes = email.getBytes();
byte[] passwordBytes = password.getBytes();
for (int i = 0; i < emailBytes.length; i++) {
out.write(emailBytes[i]);
}
for (int i = 0; i < passwordBytes.length; i++) {
out.write(passwordBytes[i]);
}
out.flush();
out.close();
in = hc.openInputStream();
String cookie = hc.getHeaderField("Set-cookie");
if (cookie != null) {
int semicoln = cookie.indexOf(";");
sessionId = cookie.substring(0, semicoln);
}
StringBuffer sb = new StringBuffer();
int cha;
while ((cha = in.read()) != -1) {
sb.append((char) cha);
}
in.close();
hc.close();
System.out.println(sb.toString());
} catch (IOException ex) {
display.setCurrent(errorScreem);
}
}
if (c == back && d == errorScreem) {
display.setCurrent(mainScreem);
}
if (c == getContactsCommand) {
try {
HttpConnection hc = (HttpConnection) Connector.open(URL);
hc.setRequestProperty("type", 2 + "");
if (sessionId != null) {
hc.setRequestProperty("cookie", sessionId);
}
in = hc.openInputStream();
int ch;
String data = "";
/*while((ch=in.read())!=-1){
data+=(char)ch;
}
System.out.println("Data received :"+data);*/
data += (char) in.read();
numberOfContacts = Integer.parseInt(data);
System.out.println("The Number Of Contacts You Have are :" + numberOfContacts);
List list = new List("Contacts...", Choice.IMPLICIT);
contactsListGui = new StringItem[numberOfContacts];
ContactsList = new Form("Contacts...");
for (int i = 0; i < numberOfContacts; i++) {
data = "";
char stop = 0;
ch = in.read();
stop = (char) ch;
while (stop != '_') {
data += (char) ch;
ch = in.read();
stop = (char) ch;
}
int LenOfContactFrindlyName = Integer.parseInt(data);
System.out.println(LenOfContactFrindlyName);
data = "";
for (int j = 0; j < LenOfContactFrindlyName; j++) {
ch = in.read();
data += (char) ch;
}
System.out.println(data);
contactsListGui[i] = new StringItem("", data);
list.append(data, null);
ContactsList.append(contactsListGui[i]);
}
//display.setCurrent(ContactsList);
list.setCommandListener(this);
list.addCommand(help);
display.setCurrent(list);
} catch (IOException ex) {
ex.printStackTrace();
}

}
if (c == help) {
chatScreem = new Form("WilliamRoma");
chatScreem.append(textToSend);
chatScreem.setCommandListener(this);
sendIMToContact = new Command("send", Command.BACK, 1);
chatScreem.addCommand(sendIMToContact);
chatScreem.addCommand(receivedChat);
display.setCurrent(chatScreem);
}
if (c == sendIMToContact) {
String dataToSend = textToSend.getString();
textToSend.setString("");
try {
HttpConnection hc = (HttpConnection) Connector.open(URL);
hc.setRequestProperty("type", 3 + "");
if (sessionId != null) {
hc.setRequestProperty("cookie", sessionId);
}
out = hc.openOutputStream();
byte b[] = dataToSend.getBytes();
for (int i = 0; i < b.length; i++) {
out.write(b[i]);
}
out.flush();
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
if (c == receivedChat) {
try {
HttpConnection hc = (HttpConnection) Connector.open(URL);
hc.setRequestProperty("type", 4 + "");
if (sessionId != null) {
hc.setRequestProperty("cookie", sessionId);
}


in = hc.openInputStream();
int ch;
String data = "";
while ((ch = in.read()) != -1) {
data += (char) ch;
}

textToSend.setString(data);

/*in = hc.openInputStream();
int ch;
String data = "";
while ((ch = in.read()) != -1) {
data += (char) ch;
}
textToSend.setString(data);*/
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Command help = new Command("help", Command.BACK, 1);
TextField textToSend = new TextField("", "chat", 100, TextField.ANY);
Command receivedChat = new Command("receive", Command.CANCEL, 2);
}
GeneralRe: how to make a listener to receive from HttpConnection Pin
williamroma13-May-11 13:13
williamroma13-May-11 13:13 
GeneralRe: how to make a listener to receive from HttpConnection Pin
williamroma13-May-11 13:15
williamroma13-May-11 13:15 
GeneralRe: how to make a listener to receive from HttpConnection Pin
williamroma13-May-11 9:11
williamroma13-May-11 9:11 
GeneralRe: how to make a listener to receive from HttpConnection Pin
jschell13-May-11 12:15
jschell13-May-11 12:15 
Questionhow to read exact content of word in java Pin
priya218411-May-11 0:03
priya218411-May-11 0:03 
AnswerRe: how to read exact content of word in java Pin
Nagy Vilmos11-May-11 0:13
professionalNagy Vilmos11-May-11 0:13 
AnswerRe: how to read exact content of word in java Pin
JP_Rocks29-May-11 22:34
JP_Rocks29-May-11 22:34 
Questionhow to read exact content of word in java Pin
priya218411-May-11 0:02
priya218411-May-11 0:02 
AnswerRe: how to read exact content of word in java Pin
Nagy Vilmos11-May-11 0:17
professionalNagy Vilmos11-May-11 0:17 
QuestionCreating an object of a superclass Pin
kurt110-May-11 9:20
kurt110-May-11 9:20 
AnswerRe: Creating an object of a superclass [modified] Pin
Luc Pattyn10-May-11 12:43
sitebuilderLuc Pattyn10-May-11 12:43 
AnswerRe: Creating an object of a superclass Pin
Nagy Vilmos10-May-11 23:11
professionalNagy Vilmos10-May-11 23:11 
GeneralRe: Creating an object of a superclass Pin
Luc Pattyn11-May-11 0:54
sitebuilderLuc Pattyn11-May-11 0:54 
AnswerRe: Creating an object of a superclass Pin
jschell11-May-11 8:49
jschell11-May-11 8:49 
QuestionHow to get only modified files from vss using ant scripts [modified] Pin
Payam Rastogi9-May-11 19:27
Payam Rastogi9-May-11 19:27 
AnswerRe: How to get only modified files from vss using ant scripts Pin
Richard MacCutchan9-May-11 22:06
mveRichard MacCutchan9-May-11 22:06 
GeneralRe: How to get only modified files from vss using ant scripts Pin
David Skelly9-May-11 22:35
David Skelly9-May-11 22:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.