Joel Karimpil

Ranch Hand
+ Follow
since Oct 04, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joel Karimpil

sorry...am in a hurry so i'm pasting the whole code.
19 years ago
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
import java.lang.*;
import java.lang.Thread;

public class Authenticate extends MIDlet implements CommandListener,Runnable {

Display display = null;

TextField txtUserID;
TextField txtPassword;
String strBlank;
Form Form;

String url = "http://localhost/authenticate.jsp";

static final Command cmdLogin = new Command("Login", Command.OK, 2);
static final Command cmdClear = new Command("clear", Command.STOP, 2);

String clientUserID, clientPassword;

public Authenticate(){

display = Display.getDisplay(this);
txtUserID = new TextField("Enter UserID:","",15, TextField.ANY);
txtPassword = new TextField("Enter Password:","",15, TextField.PASSWORD);
form = new Form("Authenticate Urself");
strBlank = new String(" ");
}

public void startApp() throws MIDletStateChangeException{

form.append(txtUserID);
form.append(strBlank);
form.append(txtPassword);
form.addCommand(cmdClear);
form.addCommand(cmdLogin);
form.setCommandListener(this);
display.setCurrent(form);

}

public void pauseApp() {

}

public void destroyApp(boolean unconditional) {

notifyDestroyed();
}

void invokeJSP(String url) throws IOException {

HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
StringBuffer b = new StringBuffer();

TextBox txtDetails = null;

try{

c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("IF-Modified-Since", "25 Nov 2001 15:17:19 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-CA");
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

os = c.openOutputStream();
os.write(("&UserID=" + clientUserID).getBytes());
os.write(("&Password=" + clientPassword).getBytes());

is = c.openDataInputStream();
int ch;
while ((ch = is.read()) != -1) {

b.append((char) ch);
System.out.print((char)ch);
}
txtDetails = new TextBox("", b.toString(), 1024, 0);
txtDetails.setCommandListener(this);
is.close();
os.close();
c.close();
}
catch(Exception exc){

System.out.println(exc.toString());
}
display.setCurrent(txtDetails);
}

public void commandAction(Command c, Displayable d) {

String label = c.getLabel();
if(label.equals("clear")) {

destroyApp(true);
}
else if (label.equals("Login")) {

System.out.println(url);
Thread t = new Thread(this);
t.start();
System.out.println(url);
}
}

public void run(){

clientUserID = txtUserID.getString();
clientPassword = txtPassword.getString();
clientUserID = Trim(clientUserID);
clientPassword = Trim(clientPassword);
try{

System.out.println(clientUserID + "\t" + clientPassword);
invokeJSP(url);
}
catch(IOException e) {
}
}

String LTrim(String str)
{
String whitespace = new String(" \t\n\r");

String s = new String(str);

if (whitespace.indexOf(s.charAt(0)) != -1) {

int j=0, i = s.length();

while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
j++;

// Get the substring from the first non-whitespace
// character to the end of the string...
s = s.substring(j, i);
}
return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
String RTrim(String str)
/*
PURPOSE: Remove trailing blanks from our string.
IN: str - the string we want to RTrim

*/
{
// We don't want to trip JUST spaces, but also tabs,
// line feeds, etc. Add anything else you want to
// "trim" here in Whitespace
String whitespace = new String(" \t\n\r");

String s = new String(str);

if (whitespace.indexOf(s.charAt(s.length()-1)) != -1) {
// We have a string with trailing blank(s)...

int i = s.length() - 1; // Get length of string

// Iterate from the far right of string until we
// don't have any more whitespace...
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
i--;


// Get the substring from the front of the string to
// where the last non-whitespace character is...
s = s.substring(0, i+1);
}

return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
String Trim(String str)
/*
PURPOSE: Remove trailing and leading blanks from our string.
IN: str - the string we want to Trim

RETVAL: A Trimmed string!
*/
{
return RTrim(LTrim(str));
}


}//end class
19 years ago
Hi Cesar,

could u tell me where u have downloaded the PocketPC emulator from?
19 years ago
u can use J9 from IBM.
try yospace.com for emulators.
19 years ago
plz be a little elaborate.
when does ur appn exactly hang?

a question like "u wanna disp Alert when ur app hangs" cannot be made much sense of as ur alert is part of the same app that hung.
19 years ago
For MIDP/CLDC devices u cannot use a db on the device. u will have to make do with the RMS classes in MIDP.
RMS is a method of storing data in persistent storage.
u can read mane articles regareding the same.
19 years ago
Palm Emulator supports only MIDP 1.0
so u can use only the API that is available in MIDP 1.0
19 years ago
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class MyMIDlet extends MIDlet{

Display display = null;
Form form = null;

public MyMIDlet(){
}

public void startApp(){

display = Display.getDisplay(this);
form = new Form("Details");
display.setCurrent(form);
}

public void pauseApp(){
}

public void destroyApp(boolean value){
}
}

//it couldn't get any simpler than this
19 years ago
download the toolkit (sun j2me wireless toolkit) - available from SUN;
create a few sample apps after checking out some coding;
have fun!
but above all...
keep logging on to this site with ur queries...
though we won't spoon-feed you, be sure that u will receive handy tips.
19 years ago
i have installed jdk1.4.2_06,
and set my JAVA_HOME variable to c:j2sdk1.4.2_06,
but still, when i run the command 'java -version' in the command prompt, it returns j2sdk1.3.1_02.
why is this?
19 years ago
Hi,
what config and profile is used to program for the pocketpc?
for mobiles and smartphones it is the CLDC and MIDP.
what abt PocketPC?
19 years ago
i think u have used MIDP 2.0 and the Nokia Emulator supports MIDP 1.0
19 years ago
Hi,

is it possible to check which thread is currently executing in MIDP?
actually i want to display a gauge for connection and download status and i
want to increment the gauge as per data download...
i already have implemented the Runnable interface..
now using another thread i need to increment the gauge value until a boolean
variable returns true.
but for this, i need to check which thread is executing ....
plz help.
19 years ago
the sun site...
u should get a bit of theory in the form of articles and a bit of sample code for beginners...
19 years ago
Hi,

i am using an image in the res folder to create an image using the Image.createImage("/progress.gif") function.
however it returns an IO exception .
i do not understand why?
plz somebody herlp soon.
19 years ago