如何将控件从GUI创建的表单传递给codenameONe中的代码创建的表单 [英] How to pass control from GUI created form to code created form in codenameONe
问题描述
我已经使用GUI构建器创建了一个表单,并通过加载Google地图的代码创建了另一个表单。表单中有一个使用GUI Builder创建的按钮,我需要在单击该按钮的同时转到地图。怎么做 ?
I have created a form using GUI builder and another form via code which loads the google map. There is a button in the form which was created by using GUI builder, I need to go to the map while clicking the button. How to do it ? please help.
推荐答案
在按钮上添加一个ActionListener并在StateMachine中生成的方法中调用新表单。
Add an actionListener to your button and call the new form in the method generated in StateMachine.
您的表单应在StateMachine中创建。
Your form should be created in StateMachine.
例如:
protected void onPage2_ButtonAction(Component c, ActionEvent event) {
Form hi = new GmapForm("Native Maps Test");
hi.show();
}
Gmap表单类:
public class GmapForm extends Form {
public GmapForm(String title) {
t.setTitle(title);
setLayout(new BorderLayout());
final MapContainer cnt = new MapContainer();
addComponent(BorderLayout.CENTER, cnt);
addCommand(new Command("Move Camera") {
public void actionPerformed(ActionEvent ev) {
cnt.setCameraPosition(new Coord(-33.867, 151.206));
}
});
addCommand(new Command("Add Marker") {
public void actionPerformed(ActionEvent ev) {
System.out.println("Marker");
try {
cnt.setCameraPosition(new Coord(41.889, -87.622));
cnt.addMarker(EncodedImage.create("/maps-pin.png"), new Coord(41.889, -87.622), "Hi marker", "Optional long description", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Dialog.show("Marker Clicked!", "You clicked the marker", "OK", null);
}
});
} catch(IOException err) {
// since the image is iin the jar this is unlikely
err.printStackTrace();
}
}
});
addCommand(new Command("Add Path") {
public void actionPerformed(ActionEvent ev) {
cnt.setCameraPosition(new Coord(-18.142, 178.431));
cnt.addPath(new Coord(-33.866, 151.195), // Sydney
new Coord(-18.142, 178.431), // Fiji
new Coord(21.291, -157.821), // Hawaii
new Coord(37.423, -122.091) // Mountain View
);
}
});
addCommand(new Command("Clear All") {
public void actionPerformed(ActionEvent ev) {
cnt.clearMapLayers();
}
});
revalidate();
}
从Gmap类中删除上述代码,然后取消注释 // new StateMachine( / theme);
Remove the above code from your Gmap class and Uncomment // new StateMachine("/theme");
这篇关于如何将控件从GUI创建的表单传递给codenameONe中的代码创建的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!