Search code examples
javaformsjava-me

Store the values from a textField


How can I store the values which inputted on the textfield of a form and show these entered values to another form? I'm using java-me. I'm trying to use dbhelper but I cant understand it. A piece of code will be helpful. What should I do? Any help or positive comments will be appreciated.

Here is my code :

public class Song extends Form implements CommandListener {
    private Display display;
    private List list;
    private final Command logout;
    private Command back;
    private final TextField songname;
    private TextField band;
    private final MIDlet midlet;
    private Command add;
    private Form form;
    private DbHelper dbhelper1;

    public Song(MIDlet midlet) {
        super("My Playlist");

        songname = new TextField("Song name: ", null, 20, TextField.ANY);
        band = new TextField("Singer/Band Name: ", null, 20, TextField.ANY);
        form = new Form("New form");
        logout = new Command("Logout", Command.OK, 0);
        add = new Command("Add", Command.OK, 0);
        back = new Command("Back", Command.BACK, 0);
        this.append(songname);
        this.append(band);
        this.addCommand(logout);
        this.addCommand(add);
        this.addCommand(back);
        this.setCommandListener(this);
        this.midlet = midlet;
    }

    public void startApp() {
        this.append("This is MainForm");
        display.setCurrent(this);
    }

    public void showInput() {
        String w = "by";
        String n = songname.getString();
        String c = band.getString();
        Form form = new Form("Input Value");
        this.append(n);
        this.append(w);
        this.append(c);
        System.out.print("\n");
        display.setCurrent(form);
    }

    public void commandAction(Command c, Displayable d) {

        if (c == logout) {
            Display.getDisplay(midlet).setCurrent(new LoginForm(midlet));
        }
        if (c == add) {
            showInput();
        }
        if (c == back) {
            Display.getDisplay(midlet).setCurrent(new Playlist(midlet));
        }
    }
}

Solution

  • You have to do function that gets TextField form and change it to your new form. I don't know what is your form but you can easly change it to string. Somthing like this:

    public Form ChangeForm(TextField s) {
    
        String str = s.getText() // get string from textfield
        // Setting new form..
        // return form
    }