Package scotlandyard.client.widget

Source Code of scotlandyard.client.widget.NewLogin

package scotlandyard.client.widget;

import scotlandyard.client.network.rpc.GameService;
import scotlandyard.client.network.rpc.GameServiceAsync;
import scotlandyard.client.network.rpc.PreGameService;
import scotlandyard.client.network.rpc.PreGameServiceAsync;
import scotlandyard.client.util.WindowClosingHandlerImpl;
import scotlandyard.shared.ScotConstants;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.PasswordTextBox;

public class NewLogin extends Composite {
  public static boolean logged = false;
 
  //RemoteServices
  private PreGameServiceAsync preGame = GWT.create(PreGameService.class);
  private GameServiceAsync game = GWT.create(GameService.class);
 
  private TextBox textBox;
  private PasswordTextBox passwordTextBox ;
  public NewLogin() {
   
    AbsolutePanel absolutePanel = new AbsolutePanel();
    initWidget(absolutePanel);
    absolutePanel.setSize("200px", "168px");
   
    Label label = new Label("Nome do usu\u00E1rio");
    absolutePanel.add(label, 10, 10);
   
    textBox = new TextBox();
    absolutePanel.add(textBox, 10, 34);
   
    Label label_1 = new Label("Senha");
    absolutePanel.add(label_1, 10, 68);
   
    passwordTextBox = new PasswordTextBox();
    absolutePanel.add(passwordTextBox, 10, 92);
   
    Button button = new Button("New button");
    button.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        System.out.println("\nTentando logar...\n");
        final String usrName = textBox.getText();
        preGame.login(usrName, passwordTextBox.getText(), new AsyncCallback<Integer>(){

          @Override
          public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub
           
          }

          @Override
          public void onSuccess(Integer result) {
            //if result = true;
            switch(result){
            case ScotConstants.LOGIN_RECONNECTED:
              Window.addWindowClosingHandler(new WindowClosingHandlerImpl(usrName));
             
              preGame.notifyReconnection(new AsyncCallback<String>(){

                @Override
                public void onFailure(Throwable caught) {
                  System.out.println("Failed at notifying attempt to reconnect!");
                }

                @Override
                public void onSuccess(String result) {
                  System.out.println("Success at notifying attempt to reconnect!");
                 
                  RootLayoutPanel.get().clear();
                  RootLayoutPanel.get().add(new Game(result));
                }
               
              });
             

              break;
            case ScotConstants.LOGIN_CONNECTED:
              Window.addWindowClosingHandler(new WindowClosingHandlerImpl(usrName));
             
              GameList list = new GameList();
              RootLayoutPanel.get().clear();
              RootLayoutPanel.get().add(list);
              list.updateGameList();
              break;
            case ScotConstants.LOGIN_REJECTED:
              break;
             
            }
            //logged = true;
           
            /*if (logged){
              Window.addWindowClosingHandler(new WindowClosingHandlerImpl(usrName));
           
              GameList list = new GameList();
              RootLayoutPanel.get().clear();
              RootLayoutPanel.get().add(list);
              list.updateGameList();
            }*/
          }
        });
     
      }
    });
    button.setText("Entrar");
    absolutePanel.add(button, 10, 126);
   
    Button btnCadastro = new Button("Cadastro");
    btnCadastro.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        RootLayoutPanel.get().clear();
        RootLayoutPanel.get().add(new Register());
      }
    });
    absolutePanel.add(btnCadastro, 119, 126);
  }
}
TOP

Related Classes of scotlandyard.client.widget.NewLogin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.