HI, I am beginner in j2me. Trying to store the data[array] into next form. It will be helpful if you provide edit and delete the
records from the form2. Can you suggest easier way to store the values in j2me

import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class InputArray extends MIDlet implements CommandListener {
  private Form form1, form2;
  private Command exit,next;
  private DateField df;
  private TextField tf;
//  private char data[][] = {'a', 'b', 'c'}};
  private String str[] = {"111"};
  

public InputArray() {
  	 form1 = new Form("Main Menu");
  	 df = new DateField("Choose a Date", DateField.DATE_TIME);
  	 df.setDate(new java.util.Date());
  	 tf = new TextField("Post a Note", "", 32, TextField.ANY);
  	 
	// First Form 
  	 form1.append(df);
     form1.append(tf);
   
    
    // Second form 
  	 exit = new Command("Exit", Command.EXIT, 0);
  	 next = new Command("ADD", Command.SCREEN, 1);
  	 form1.addCommand(next);
  	 form1.addCommand(exit);
  	 form2 = new Form("Second Form");
  	 form2.addCommand(exit);
  }
 
  public void startApp() {
  	form1.setCommandListener(this);
     form2.setCommandListener(this);
    Display.getDisplay(this).setCurrent(form1);
    
  }

 public void pauseApp() {}
  
 public void destroyApp(boolean unconditional) {}
  
 public void commandAction(Command c, Displayable s) {

    	if(c == exit) notifyDestroyed();
    	else if (c == next)
    	{

		StringItem tmp = new StringItem(null, ("bla" + (str(buffer) )));
    	
    	StringItem tmp = new StringItem(null, "bla " + (str(buffer)));
    	
    		form2.append(tmp);
    	//	form2.append(new StringItem("", tmp));
    	    
    	//	form2.append(new StringItem(null, "Store the values Date and Text"));
    		Display.getDisplay(this).setCurrent(form2);
    	}
   	
   	}
}

Welcome nukabolhi,
Use code tags. Source code must be surrounded with code tags.

This way you can add items into form:

StringItem data[] = new StringItem[] { new StringItem("Name, ", "Mr.X"),
        new StringItem("Age", "12") };

form1 = new Form("Items are", messages);

You may read string data and write by using the RecordStore class. javax.microedition.rms.

HI, I am beginner in j2me. Trying to store the data[array] into next form. It will be helpful if you provide edit and delete the
records from the form2. Can you suggest easier way to store the values in j2me

import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class InputArray extends MIDlet implements CommandListener {
  private Form form1, form2;
  private Command exit,next;
  private DateField df;
  private TextField tf;
//  private char data[][] = {'a', 'b', 'c'}};
  private String str[] = {"111"};
  

public InputArray() {
  	 form1 = new Form("Main Menu");
  	 df = new DateField("Choose a Date", DateField.DATE_TIME);
  	 df.setDate(new java.util.Date());
  	 tf = new TextField("Post a Note", "", 32, TextField.ANY);
  	 
	// First Form 
  	 form1.append(df);
     form1.append(tf);
   
    
    // Second form 
  	 exit = new Command("Exit", Command.EXIT, 0);
  	 next = new Command("ADD", Command.SCREEN, 1);
  	 form1.addCommand(next);
  	 form1.addCommand(exit);
  	 form2 = new Form("Second Form");
  	 form2.addCommand(exit);
  }
 
  public void startApp() {
  	form1.setCommandListener(this);
     form2.setCommandListener(this);
    Display.getDisplay(this).setCurrent(form1);
    
  }

 public void pauseApp() {}
  
 public void destroyApp(boolean unconditional) {}
  
 public void commandAction(Command c, Displayable s) {

    	if(c == exit) notifyDestroyed();
    	else if (c == next)
    	{

		StringItem tmp = new StringItem(null, ("bla" + (str(buffer) )));
    	
    	StringItem tmp = new StringItem(null, "bla " + (str(buffer)));
    	
    		form2.append(tmp);
    	//	form2.append(new StringItem("", tmp));
    	    
    	//	form2.append(new StringItem(null, "Store the values Date and Text"));
    		Display.getDisplay(this).setCurrent(form2);
    	}
   	
   	}
}

I have tried lot of ways. But get so many errors. Can you provide example for this code.

OK, before I start doing anything, would you care to explain what this application is supposed to do?
From what I seen so far I guess you trying to create some sort of memo holder or diary where you will keep a note associated with date and time.
Can you confirm or correct me please?

Exactly, its a memory holder. like task management.

Here are few suggestions:

1) Your code is growing and becoming more difficult to manage. It is good practice to put each screen in its own class and either pass instance of Display from screen to screen or do something like this article
2) Instead of using arrays create a simple Memo object that can hold "long" type for date&time and string for memo comment. Something like

public class Memo{
    private long dateTime;
    private String comment;

    public Memo(){}

    public Memo(long dateTime, String comment){
        setDateTime(dateTime);
        setComment(comment);
    }

    public void setDateTime(long dateTime){
       this.dateTime = dateTime;
    }

    public long getDateTime(){
       return dateTime;
    }

    public void setComment(String comment){
        this.comment = comment;
    }

    public String returnComment(){
        return comment;
    }
}

this become more organized and more efficient then limited size arrays, especially if you decide to store Memo object in vector and pass along for various reasons (reading multiple records from RMS, putting them in Memo objects, storing in vector and passing for further processing)

3)I believe this is school assignment so I will not push you for advanced GUI like CustomItem or Canvas. However I would recommend re-do your application flow. On application start I would show option to "Add Memo" and "View Memos" in form of List. Once add memo selected I would proceed to your current screen with calendar and text area where you will collect data from user and store them.
On other hand view memos should receive either collection of data or query RMS for data and display them in form of list. Here you can implement options for edit and delete, which is nothing more as either removing currently selected list item from collection (from vector if you deploy vector) and refreshing view plus passing data to create memo form for editing.

If you willing to and will implement changes to screen handling, add the memo object I will assist you with it and also help you with RMS

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.