[英]accessing widgets inside a GWT element
I want to access the text elements inside this textbox in GWT from the main method (where I call it like this) 我想从main方法(我这样称呼它)中访问GWT中此文本框内的文本元素。
DialogBox aBox = newCandidatePop.buildNewElecPopup();
aBox.center();
aBox.getWidget();
MiscUiTools.newCandidateHandler(aBox.firstName, aBox.surName);
in newCandidateHandler
i want to attach a click handler to the two text boxes 在
newCandidateHandler
我想将点击处理程序附加到两个文本框中
However, the above doesnt quite work - I cant get access to the aBox.firstName elements because they are static methods -- I am wondering what is best practice, how would you code something like this up? 但是,上述方法并不十分有效-我无法访问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;
}
Why are the TextBoxes static at all? 为什么TextBoxes完全是静态的?
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...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.