GWT interface的使用例子
Posted wuzg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GWT interface的使用例子相关的知识,希望对你有一定的参考价值。
一、定义一个接口类
public interface TicketViewModuleListener {
void fieldsChanged();
void positionReceived(double latitude, double longitude);
}
二、定义widget类并实现TicketViewModuleListener接口
public class TicketViewWidget extends VOverlay implements OfflineMode,
TicketViewModuleListener {
private InformationLayout informationLayout;
@Override
public void fieldsChanged() {
if (validateFields) {
validateFields();
}
if (listener != null && isApplicationOnline()) {
listener.updateState(getTicket());
}
fieldsChanged = true;
CacheManifestStatusIndicator.setConfirmationRequired(true);
saveTicketButton.setEnabled(true);
}
private boolean isApplicationOnline() {
return OfflineModeEntrypoint.get().getNetworkStatus().isAppOnline();
}
private boolean validateFields() {
resetValidations();
boolean valid = true;
if (!informationLayout.validateFields()) {
valid = false;
}
return valid;
}
private Widget buildSectionWrapper(final Widget content,
final String captionString, final String styleName) {
VCssLayout layout = new VCssLayout();
layout.addStyleName(styleName);
Label caption = new Label(captionString);
caption.addStyleName("sectioncaption");
layout.add(caption);
layout.add(content);
return layout;
}
@Override
public void positionReceived(final double latitude, final double longitude) {
if (listener != null) {
listener.positionReceived(latitude, longitude);
}
}
}
三、定义组件类并调用接口
public class InformationLayout extends VerticalComponentGroupWidget {
private final TicketViewModuleListener listener;
private void requestUserPosition() {
Geolocation geolocation = Geolocation.getIfSupported();
if (geolocation == null) {
useCurrentLocationSwitch.setValue(false);
} else {
geolocation
.getCurrentPosition(new Callback<com.google.gwt.geolocation.client.Position, PositionError>() {
@Override
public void onSuccess(
final com.google.gwt.geolocation.client.Position result) {
currentPosition = result;
if (listener != null) {
listener.positionReceived(result
.getCoordinates().getLatitude(), result
.getCoordinates().getLongitude());
}
}
@Override
public void onFailure(final PositionError reason) {
useCurrentLocationSwitch.setValue(false, true);
remove(useCurrentLocationSwitch);
}
});
}
}
}
四、应用情况
widget类实现listener接口,并调用组件类,组件类产生事件后调用widget类,达到参数传递的目的。
以上是关于GWT interface的使用例子的主要内容,如果未能解决你的问题,请参考以下文章
华为-vlan间路由之SVI(switch virtual interface)
Go 接口实现原理高阶篇: type _interface struct
为啥在 Weka 中使用 libsvm 时会出现“NoClassDefFoundError:libsvm/svm_print_interface”错误?