Codenameone 在打开表单后请求连接,如在statemachine中的postForm中一样

Codenameone 在打开表单后请求连接,如在statemachine中的postForm中一样,codenameone,Codenameone,我已经从statemachine转换到了赤裸裸的代码。这里我在构造函数中有一个代码(connectionRequest),因此在打开新表单之前调用连接。我需要的是:打开新表单后,应该调用连接。在statemachine中,如果我在postForm中请求连接,表单将打开,然后调用connectionRequest。我在这里怎么做 Home.java public class Home extends Form { public Home() { Button test =

我已经从statemachine转换到了赤裸裸的代码。这里我在构造函数中有一个代码(connectionRequest),因此在打开新表单之前调用连接。我需要的是:打开新表单后,应该调用连接。在statemachine中,如果我在postForm中请求连接,表单将打开,然后调用connectionRequest。我在这里怎么做

Home.java

public class Home extends Form {
    public Home() {
        Button test = new Button("Test");
        add(test);

        test.addActionListener(e->{
            new Test().show();
        });
    }
}
Test.java

public class Test extends Form{
    public Test(){
        Label nameLabel = new Label("");
        add(nameLabel);

        ConnectionRequest cr = new ConnectionRequest() {

            @Override
            protected void readResponse(InputStream input) throws IOException {
                JSONParser jp = new JSONParser();
                Map parser = jp.parseJSON(new InputStreamReader(input));
                String name = (String) parser.get("name");
                nameLabel.setText(name);
            }
        };
        cr.setUrl("test.com");
        NetworkManager.getInstance().addToQueueAndWait(cr);
    }  
}

您可以使用
addShowListener
在那里调用连接请求。

您可以使用
addShowListener
在那里调用连接请求