3
votes

I am using the typical code to navigate between forms in the same package. For instance, the form tutorial.java

 Form Tutorials = new Tutorials();           
    Tutorials.getToolbar().setBackCommand(back);
    Tutorials.setBackCommand(back);
    Tutorials.show();

However, if i create another package with other java forms, how do i navigate to them? Let's say folder1/form1.java

Form folder1/form1 = new folder1/form1();           
        folder1/form1.getToolbar().setBackCommand(back);
        folder1/form1.setBackCommand(back);
        folder1/form1.show();

Not working.

1

1 Answers

3
votes

The package name can be specified in an import. Following your example, suppose to have this class that extends the Form class:

package net.informaticalibera.tests.folder1;

import com.codename1.ui.Form;
import com.codename1.ui.layouts.Layout;

public class Form1 extends Form{

    public Form1() {
    }

    public Form1(Layout contentPaneLayout) {
        super(contentPaneLayout);
    }

    public Form1(String title) {
        super(title);
    }

    public Form1(String title, Layout contentPaneLayout) {
        super(title, contentPaneLayout);
    }

}

If you want to use that class in another package, you have to use an import. For example:

import net.informaticalibera.tests.folder1.Form1;

public class YourClass {

    [your other code]
    Form form1 = new Form1("Hi World", BoxLayout.y());
    form1.add(new Label("Hi World"));
    form1.show();

}

Usually the IDEs allow to insert the imports automatically.

Alternatively, if you have any reason to don't use the import (for example when a class name conflict occurs), you can use fully qualified name to avoid the import statement:

Form form1 = new net.informaticalibera.tests.folder1.Form1("Hi World", BoxLayout.y());
form1.add(new Label("Hi World"));
form1.show();

For a detailed explanation: https://beginnersbook.com/2013/03/packages-in-java/