I need help in doing the following - i must have a log in screen and when the user name and password is entered (hey are always same length) 10 for username and 2 for password i connect to a text file on the net and then check the username against the password. At the minute all i can do is read the entire text file in. Would someone please give me some help in this ?? I have searched the net all day and cant find a thing. The code so far is:
/*
* ProjectMIDlet.java
*
* Created on 20 November 2003, 14:33
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
/**
*
* @author Diane McKeaveney
* @version
*/
public class ProjectMIDlet extends MIDlet implements CommandListener{
private Display display;
String url="http:www.cs.qub.ac.uk/~A.Bouridane/marks.txt";
private TextField username;
private TextField password;
private Form form;
private Command cancel;
private Command login;
public ProjectMIDlet(){
username=new TextField("LoginID: ", "",10,TextField.ANY);
password=new TextField("Password: ", "",10,TextField.PASSWORD);
form=new Form("Log In");
cancel=new Command("Cancel", Command.CANCEL,2);
login=new Command("Login",Command.OK,2);
}
public void startApp() {
display=Display.getDisplay(this);
form.append(username);
form.append(password);
form.addCommand(cancel);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);
}
void gettheinput()
{
try{
getViaStreamConnection(url);
}
catch(IOException e){
System.out.println("IOException "+e);
e.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
void getViaStreamConnection(String url) throws IOException{
StreamConnection c=null;
InputStream s=null;
StringBuffer b=new StringBuffer();
TextBox t=null;
try{
c=(StreamConnection)Connector.open(url);
s=c.openInputStream();
int ch;
while ((ch=s.read())!=-1){
b.append((char) ch);
}
// System.out.println(b.getChars(1,10,char[]name, 0));
System.out.println(b.toString());
t=new TextBox("Assignment 1 Student Marks", b.toString(), 1024, 0);
}finally{
if(s!=null){
s.close();
}
if(c!=null){
c.close();
}
}
display.setCurrent(t);
}
public void commandAction(Command c, Displayable d){
String label=c.getLabel();
if(label.equals("Cancel")){
destroyApp(true);
}else if (label.equals("Login")){
gettheinput();
}
}
}
Please email me at
[email protected]