我想显示带有某些坐标的 map ,我可以在一个 GUI 元素上执行此操作,但是当我为其他 GUI 元素复制代码时, map 不会出现
这是一个 GUI 元素(页面或屏幕)的代码
@Override
protected void beforeMapaGPS(Form f) {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new FlowLayout());
f.addComponent(mapComponent);
f.show();
}
这是从第一个复制的另一个 GUI 元素(其他页面或屏幕)
@Override
protected void onCreateGUI1() {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new FlowLayout());
f.addComponent(mapComponent);
f.show();
}
当我运行模拟器时, map 出现在第一页或屏幕上,而不是其他页面或屏幕上
保存设计器时收到消息
最佳答案
首先,不要将 FlowLayout 用于任何对等组件或复杂组件,例如 map 、浏览器、列表、多列表...
其次,您将在第二种表单的 onCreate
方法中实现 map 代码。在 beforeShow()
或 postShow()
方法中执行此操作。
最后,您通过在 beforeShow()
方法内调用 f.show()
来请求已显示的表单再次显示。
将代码更改为:
@Override
protected void beforeMapaGPS(Form f) {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, mapComponent);
}
第二个:
@Override
protected void beforeGUI1(Form f) {
MapComponent mapComponent= new MapComponent();
double latitude=-41.169782;
double longitude =-71.444885;
Coord lastLocation = new Coord(latitude, longitude);
mapComponent.zoomTo(lastLocation, 15);
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, mapComponent);
}
关于java - 代号一张 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35168291/