aspose file tools*
The moose likes Java Micro Edition and the fly likes How to convert this into a form? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "How to convert this into a form?" Watch "How to convert this into a form?" New topic
Author

How to convert this into a form?

Khushi Kapoor
Greenhorn

Joined: Apr 18, 2010
Posts: 11
Hi,

I have only developed midlets for performing simple operations like login etc. But now, I’m confused as to how to go about solving this problem which has been given to me.

There is a Midlet which has function calls for displaying various screens of the J2ME app. The Midlet code is given below:






It is calling the class MessageForm which is a text box where the user can enter data in any format . Ive been asked to convert this Message Form class into a Form which takes in user input in separate text fields like Username, Password etc. so that data comes in as a form.


The code for the existing Message form class has been given below.



Please help and let me know how to go about solving this problem .
lokesh jain
Ranch Hand

Joined: Feb 21, 2009
Posts: 58
hi, You can simply put Textboxes in MessageForm Class. You need to remove and insert the new textboxes as according to requirement. Hope it can solve the issue.

a million smiles
Lokesh
Khushi Kapoor
Greenhorn

Joined: Apr 18, 2010
Posts: 11
Thanks for the quick reply. Did try your suggestion. But removing the line having super is giving the error " Cannot find constructor for text box"..I'm still unable to understand how to make this class into a form which collects data according to the diff boxes:

Tried modifying the prev code with the foll code:




Sorry, but I'm confused about the whole thing and also about the changes that will have to be made in the main midlet for calling the function of this class.
Ashish Bhandurge
Greenhorn

Joined: Apr 22, 2010
Posts: 17
Its very simple, you have to just extend your MessageForm class by Form instead of TextBox , then you can easily add in the form whatever you want like TextField
or checkBox etc
Khushi Kapoor
Greenhorn

Joined: Apr 18, 2010
Posts: 11
Thanks a ton for your help and time. I tried the foll code, but, unfortunately, it gave an error saying that the getString(); is not found. i'm very sorry if the code I tried looks silly, but I am very new to all this and am trying to learn, The problem is to tackle this assignment at a point when I'm not able to handle it

This is what I had tried; I’m also enclosing the entire original code, as given in my question, of the Midlet from where this MessageForm class is being called, and of the original MessageForm class. Please have a look and let me know how to make this class into a form which collects data according to the diff boxes:

WHAT I tried:






ORIGINAL CODES of the MIDLET and the MessageForm class as given in the question:

MIDLET AS GIVEN IN QUESTION:




THE MESSAGEFORM class AS GIVEN IN QUES


Ashish Bhandurge
Greenhorn

Joined: Apr 22, 2010
Posts: 17
Hi,

dont panic , everything will clear ,its not a big task to learn J2ME.Regarding your problem,where is getString() method ?You are calling that method from commandAction() but where is that method ?Which string do you want ? Please tell in brief what you want to do and whats your requirment, i will definetly solve your problem.
Khushi Kapoor
Greenhorn

Joined: Apr 18, 2010
Posts: 11
Thanks, yet again :-)

The getString(); method was used in the given working code and it did not give any error when the MessageForm class was extending the TextBox class in the original given code as shown above. Only, when I made the class extend Form, it starting showing the error message of not being able to find the function.

What was happening in the original code was that it was collecting the input from the user as the "Message" string and submitted at the server.
ie.

Message(A Text Box for entering our details)
--so any input by the user in the text box, would be stored as "Message" string which was assigned to the message string in the Client MIDlet class (through the lines--




) ,

and different students used to enter their message through the above and that "Message" string was stored at the server.


Now, they want us to change the TextBox that used to appear for inputting any user input, into a form with different fields, so that the data recd. at the server end is in the format:

"
Name: Radha
Class: 11
Roll Number:12
"

instead of what come in the existing version

ie. "Message:my name is radha; ive been told to enter details in any format in the MessageTextBox that was shoen to me. Im in 11 std. and my roll is 12"


Hope the above conveys the requirements of the assignment. Please let me know if I need to give any other information.

As far as the codes are concerned, the MessageForm class is only being called by the ClientMidlet. It is not linked to any other class. After it takes in the user message, it gives this string to the client which further submits it at the server.
Both codes of the Client.java ie. the midlet and of MessageForm.java have been given in the previous thread.

Thanks again for all your time and help.
Ashish Bhandurge
Greenhorn

Joined: Apr 22, 2010
Posts: 17
hi,

you please try the following MessageForm class . And tell me if its working for you or not.I think this is your requirment.



import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;


public class MssageForm extends Form implements CommandListener
{
TextField name,rollNumber,age;
private Command submit,cancel;


public MssageForm(String title)
{
super(title);

name=new TextField("Name::"," ",50,TextField.ANY);
age=new TextField("Age::"," ",50,TextField.ANY);
rollNumber=new TextField("RollNumber::"," ",50,TextField.ANY);
submit=new Command("Submit",Command.SCREEN,1);
cancel=new Command("Cancel",Command.BACK,1);

this.append(name);
this.append(age);
this.append(rollNumber);
this.addCommand(submit);
this.addCommand(cancel);
this.setCommandListener(this);


}

public void commandAction(Command c, Displayable d)
{

if(c == submit)
{
String studentName=null ,studentRollNumber=null,studentAge=null;


studentName=name.getString(); /// like this you can get the text entered into the TextField
studentRollNumber=rollNumber.getString(); ///and you can send it to the server
studentAge=age.getString();

Client.startSubmit ();
}
else if(c == cancel)
{
Client.initSession();
}
}

}





Khushi Kapoor
Greenhorn

Joined: Apr 18, 2010
Posts: 11
Thanks a ton for quick and great help ...Yes, this was my requirement. I had incorporated your code and the jar file had compiled well,no errors etc, just when I was about to port it to my S40, my phone crashed ...Sorry, It'll take me atleast a day or two now, till I get my phone repaired, before I give you a good report

Thanks again!
Khushi Kapoor
Greenhorn

Joined: Apr 18, 2010
Posts: 11
Curiousity didnt let me rest ! I tried it on another S 40 phone. Its showed the form nicely and the contents were submitted properly after making the necessary changes at the server end !!!

Ill read up more about forms and will try to incoporate more types of inputs, checkbox selections etc. into this form after my exams . I am all enthusiastic now about learning J2ME properly, with experts like you to guide us on this forum !!!

Thanks a ton
Ashish Bhandurge
Greenhorn

Joined: Apr 22, 2010
Posts: 17
Its very nice that your prblem has solved , i am always ready to help you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to convert this into a form?