public UserSelect() { loginInfo = new Label(""); loginInfo.addStyleName("error-font"); loginInfo.addStyleName("margin15"); loginInfo.addStyleName("margin-top40"); loginInfo.setVisible(false); selected = null; loginField = new PasswordField(""); loginField.setWidth("200px"); loginField.addStyleName("margin15"); loginField.addStyleName("margin-bot40"); loginBut = new Button("login"); loginBut.addStyleName("margin15"); loginBut.addClickListener( e -> { if (loginField.getValue().equals(selected.getPassword())) { hidePass(); Globals.user = selected; Globals.root.changeScreen(Globals.user); } else { loginInfo.setVisible(true); loginInfo.setValue("Wrong password"); loginField.setValue(""); } }); loginBox = new HorizontalLayout(); loginBox.addStyleName("popup-box"); loginBox.addComponents(loginField, loginBut, loginInfo); loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_LEFT); loginBox.setComponentAlignment(loginBut, Alignment.MIDDLE_CENTER); loginBox.setComponentAlignment(loginField, Alignment.MIDDLE_RIGHT); loginBox.setVisible(false); userIcon = new ThemeResource("icons/user.png"); users = Globals.control.usersData(); vbox = new VerticalLayout(); // vbox.setSizeUndefined(); vbox.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); Panel p = new Panel(); p.setSizeFull(); p.setContent(vbox); // vbox.addStyleName("border-l-r"); this.addComponent(p, "left: 25%; right: 25%; top: 15px"); this.addComponent(loginBox, "left: 25%; right: 25%; top: 40%"); this.addLayoutClickListener( e -> { if (!loginBox.isVisible()) return; System.out.println(e.getClickedComponent()); if (e.getClickedComponent() == null || e.getClickedComponent().equals(vbox)) hidePass(); }); }
public LoginModule() { setMargin(true); setSpacing(true); grid.setSizeFull(); grid.setSpacing(true); final TextField username = new TextField(); username.setValue("username"); username.setWidth("120px"); username.setStyleName("small"); grid.addComponent(username, 0, 0); final PasswordField password = new PasswordField(); password.setValue("password"); password.setWidth("120px"); password.setStyleName("small"); grid.addComponent(password, 0, 1); Button button = new Button("Login"); button.setWidth("120px"); button.setStyleName("small"); button.addListener( new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { login.setUsername(username.getValue().toString()); login.setPassword(password.getValue().toString()); String user = login.getUsername(); String pass = login.getPassword(); // login.setResult(authLog.login(user, pass)); boolean result = authLog.login(user, pass); if (result == true) { label.setCaption("Successfully Login"); } else { label.setCaption("SQL Error"); } } }); grid.addComponent(button, 0, 2); panel.addComponent(grid); addComponent(panel); addComponent(label); }