我创建了登录类:
public class LoginPage extends VerticalPanel implements ClickHandler {
ApplicationMethods appMthd;
private RootPanel rootPanel;
TextBox txtUserEmail;
PasswordTextBox txtPassword;
Button btnLogin;
String strEmail, strPass;
public LoginPage(ApplicationMethods appMthd) {
this.appMthd = appMthd;
rootPanel = RootPanel.get();
rootPanel.setSize("320", "480");
btnLogin = new Button("Login");
btnLogin.setText("Login");
rootPanel.add(btnLogin, 224, 256);
btnLogin.setSize("79px", "35px");
btnLogin.addClickHandler(this);
txtUserEmail = new TextBox();
rootPanel.add(txtUserEmail, 36, 161);
txtUserEmail.setSize("240px", "20px");
txtPassword = new PasswordTextBox();
rootPanel.add(txtPassword, 36, 207);
txtPassword.setSize("240px", "20px");
}
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
if(event.getSource() == btnLogin)
{
strEmail = txtUserEmail.getText().toString();
strPass = txtPassword.getText().toString();
appMthd.onLogin(strEmail, strPass);
}
else
{
Window.alert("Coming Soon..!!");
}
}
}
但我无法访问任何文本框或单击按钮。因为 Parent 类是 RootPanel。
如果我使用:
add(txtUserEmail);
add(txtPassword);
add(btnReg);
add(btnLogin);
btnLogin.addClickHandler(this);
然后,它是可访问的。在此,父类是 VerticalPanel。
那么,如何为 RootPanel 解决这个问题。?
请帮助我。
提前致谢。