gpt4 book ai didi

java - 访问 GWT 元素内的小部件

转载 作者:行者123 更新时间:2023-12-01 16:06:34 26 4
gpt4 key购买 nike

我想从 main 方法(我这样调用它)访问 GWT 中此文本框中的文本元素

DialogBox aBox =  newCandidatePop.buildNewElecPopup();
aBox.center();
aBox.getWidget();

MiscUiTools.newCandidateHandler(aBox.firstName, aBox.surName);

newCandidateHandler 中,我想将点击处理程序附加到两个文本框

但是,上面的方法不太有效 - 我无法访问 aBox.firstName 元素,因为它们是静态方法 - 我想知道什么是最佳实践,您将如何编写这样的代码?

static TextBox firstName = new TextBox();
static TextBox surName = new TextBox();
static DialogBox box;

// public newCandidatePop() {
// box = buildNewElecPopup();
// }

static public DialogBox buildNewElecPopup() {

DialogBox box = new DialogBox();
box.setAutoHideEnabled(true);

box.setText("Add a New Candidate");
box.setAnimationEnabled(true);
box.setGlassEnabled(true);

Grid dialogGrid = new Grid(2, 3);
dialogGrid.setPixelSize(250 , 125);
dialogGrid.setCellPadding(10);
dialogGrid.setWidget(0, 0, new HTML("<strong>First Name</strong>"));
dialogGrid.setWidget(0, 1, firstName);

dialogGrid.setWidget(1, 0, new HTML("<strong>Surname</strong>"));
dialogGrid.setWidget(1, 1, surName);

box.add(dialogGrid);

return box;
}

最佳答案

为什么文本框是静态的?

public class MyDialogBox extends DialogBox {
private final TextBox firstName;
private final TextBox surName;
public MyDialogBox() {
firstName = new TextBox();
surName = new TextBox();

DialogGrid dialogGrid = new Grid(2, 3);
// do all your stuff with the grid, add TextBoxes, etc.
add(dialogGrid);

setAutoHideEnabled(true);
// set all the properties of your DialogBox
}

public TextBox getFirstNameTextBox() {
return firstName;
}
// same with surName...
}

关于java - 访问 GWT 元素内的小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2465385/

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