gpt4 book ai didi

java - 将小部件添加到 map 会破坏 GWT 中的其他小部件

转载 作者:行者123 更新时间:2023-12-01 14:23:09 24 4
gpt4 key购买 nike

我基本上有两对小部件,一对有两个日期选择器和一个提交按钮,用于将日期提交到服务器上的 RPC,另一对是显示这些日期之间信息的 map 。它们每个都单独工作,但是当显示 map 时,我无法对日期选择器或提交按钮执行任何操作。

这是重要的代码

public void onModuleLoad() {
final DockLayoutPanel dock = new DockLayoutPanel(Unit.PCT);
/*
* Asynchronously loads the Maps API.
*
* The first parameter should be a valid Maps API Key to deploy this
* application on a public server, but a blank key will work for an
* application served from localhost.
*/
Maps.loadMapsApi("", "2", false, new Runnable() {
public void run() {

final FormPanel form = new FormPanel();
form.setMethod(form.METHOD_POST);


DatePicker datePicker = new DatePicker();
final Label text = new Label();
text.setText("Start Date");

// Set the value in the text box when the user selects a date
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
public void onValueChange(ValueChangeEvent<Date> event) {
Date date = event.getValue();
String dateString = DateTimeFormat.getMediumDateFormat().format(date);
text.setText("Start Date - " + dateString);
}
});

// Set the default value
datePicker.setValue(new Date(), true);

// Add the widgets to the page
RootPanel.get().add(text);
RootPanel.get().add(datePicker);

DatePicker datePicker2 = new DatePicker();
final Label text2 = new Label();
text2.setText("End Date");

// Set the value in the text box when the user selects a date
datePicker2.addValueChangeHandler(new ValueChangeHandler<Date>() {
public void onValueChange(ValueChangeEvent<Date> event) {
Date date = event.getValue();
String dateString = DateTimeFormat.getMediumDateFormat().format(date);
text2.setText("End Date - " + dateString);
}
});

// Set the default value
datePicker2.setValue(new Date(), true);

// Add the widgets to the page

RootPanel.get().add(text2);
RootPanel.get().add(datePicker2);
RootPanel.get().add(new Button("Submit", new ClickListener()
{
public void onClick(Widget sender)
{
form.submit();
}
}));

form.addSubmitHandler(new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
getAwards(text.getText(),text2.getText());
}
});

}
});
}

这是创建日期选择器的代码。

这是显示 map 的代码。

private void buildUi() {
ArrayList<Icon> icons = createIconList();
content = new ArrayList<String>();
LatLng sanDiego = LatLng.newInstance(32.83049, -117.122717);
final MapWidget map = new MapWidget(sanDiego, 9);
map.clearOverlays();
map.setSize("100%", "100%");
// Add some controls for the zoom level
map.addControl(new LargeMapControl());

java.util.Random rand = new java.util.Random();
for(ContractAward ca : sanDiegoAwards)
{
double off1 = (rand.nextDouble()-.5)/100;
double off2 = (rand.nextDouble()-.5)/100;
index++;
// Open a map centered on San Diego
LatLng contract = LatLng.newInstance(ca.getLat() + off1,ca.getLon()+off2);

MarkerOptions mo = MarkerOptions.newInstance();
mo.setTitle(""+index);
mo.setIcon(icons.get(whichIcon(ca.getAmount())));
final Marker mark = new Marker(contract,mo);
map.addOverlay(mark);

String caContent = "<P>Company: " + ca.getCompany() + "<br>";
caContent+= "Date: " + ca.getDate().toGMTString() + "<br>";
caContent+= "Amount: " + ca.getAmount() + "<br>";
caContent+= "ContractID: " + ca.getContractID() + "</P>";

content.add(caContent);
mark.addMarkerClickHandler(new MarkerClickHandler() {
public void onClick(MarkerClickEvent event) {

InfoWindow info = map.getInfoWindow();
info.open(mark, new InfoWindowContent(content.get(Integer.parseInt(mark.getTitle())-1)));
}
});

}
final DockLayoutPanel dock = new DockLayoutPanel(Unit.PCT);
dock.addEast(map, 80);


// Add the map to the HTML host page
RootLayoutPanel.get().add(dock);
}

我尝试将 RootLayoutPanel.get().add(dock) 更改为 RootPanel.get().add(dock) 但 map 本身不显示。我还尝试更改所有要通过 rootlayoutpanel 停靠和插入的顶部部分,但出现了与当前问题相同的问题。

最佳答案

我第一眼看到的几种可能性。

1) 您要将日期选择器内容添加到 RootPanel,但将 map 内容添加到 RootLayoutPanel。我建议两者都坚持使用 RootLayoutPanel,如果它有效的话,标准模式通常在 GWT 中有更有用、最新的东西。

2) 为什么你要在代码的第一段中使用 Runnable 来完成这一切?难道所有这些东西都不在 onModuleLoad 中吗?

关于java - 将小部件添加到 map 会破坏 GWT 中的其他小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17375029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com