PDA

View Full Version : get Screen size to center Windows Login



TheMrCego
18 Oct 2011, 4:23 PM
hi!

i'm developing a chat for Software Engineering homework. we're learning GWT and we're using GXT to develop.

first part of homework is "develop a chat login". I'm using "Windows form" and I almost finished the login windows. but I want to get screen size to situate this windows on center of any screen size. I know I should get browser screen, but I dont know how, least situate the windows on center.

here my code source:


package com.mycompany.project.client;

import com.extjs.gxt.ui.client.widget.MessageBox;


public class LoginWindows extends Window {
private LabelField lblfldUsername;
private LabelField lblfldPassword;

public LoginWindows() {


setResizable(false);
setHeading("Ventana de Login");
CenterLayout centerLayout = new CenterLayout();
centerLayout.setExtraStyle("centered.DialogLogin");
setLayout(centerLayout);

FlexTable flexTable = new FlexTable();
add(flexTable);
flexTable.setSize("321px", "110px");

final TextField cajaUse = new TextField();
cajaUse.setMinLength(4);
cajaUse.getMessages().setMinLengthText("Debe Ser Mayor de 3 Caracter");

lblfldUsername = new LabelField("Nombre de Usuario:");
flexTable.setWidget(0, 0, lblfldUsername);
lblfldUsername.setSize("150", "22");
cajaUse.setEmptyText("Usuario");
flexTable.setWidget(0, 2, cajaUse);

final TextField cajaPas = new TextField();
cajaPas.setMinLength(5);
cajaPas.getMessages().setMinLengthText("Debe Ser Mayor de 5 Caracteres");

lblfldPassword = new LabelField("Contrase\u00F1a:");
flexTable.setWidget(1, 0, lblfldPassword);
cajaPas.setPassword(true);
flexTable.setWidget(1, 2, cajaPas);

CheckBox checkBox = new CheckBox();
flexTable.setWidget(2, 1, checkBox);
checkBox.setSize("17px", "16px");
checkBox.setBoxLabel("");
checkBox.setHideLabel(true);

Text txtRecordarEnEste = new Text("Recordar En Este PC");
flexTable.setWidget(2, 2, txtRecordarEnEste);
flexTable.getCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getRowFormatter().setVerticalAlign(2, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable.getCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setVerticalAlignment(0, 2, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable.getCellFormatter().setHorizontalAlignment(3, 2, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setVerticalAlignment(3, 2, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setVerticalAlignment(1, 2, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable.getCellFormatter().setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
flexTable.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);

final Button btnReset = new Button("Reset");
btnReset.addListener(Events.Select, new Listener<ButtonEvent>() {
public void handleEvent(ButtonEvent e) {
cajaUse.clear();
cajaPas.clear();
}
});
flexTable.setWidget(3, 0, btnReset);
btnReset.setSize("93px", "null");

Button btnIngresa = new Button("Ingresa");
btnIngresa.setWidth("93px");
btnIngresa.addListener(Events.Select, new Listener<ButtonEvent>() {
public void handleEvent(ButtonEvent e) {
cajaUse.selectAll();
cajaPas.selectAll();

if((cajaUse.getSelectionLength()==0) && (cajaPas.getSelectionLength()==0)) {
MessageBox.alert("Error", "Inserte Username & Password!", null);
}
else if (cajaUse.getSelectionLength()==0) {
MessageBox.alert("Error", "Inserte Username", null);
}
else if (cajaPas.getSelectionLength()==0){
MessageBox.alert("Error", "Inserte Password!", null);
}
else if (!(cajaUse.getSelectionLength()>=1 && cajaUse.getSelectionLength()<4)
&& !(cajaPas.getSelectionLength()>=1 && cajaPas.getSelectionLength()<5)){
final MessageBox menAct = MessageBox.progress("Espere...", "Estamos Comprobando Acceso, Espere Un Momento...", "Cargando...");
final ProgressBar barraAct = menAct.getProgressBar();
barraAct.setStyleName("ProgressBar");
Timer t = new Timer() {
float i;
@Override
public void run() {
barraAct.updateProgress(i / 100, (int) i + "% Completado");
i += 5;
if (i > 100) {
cancel();
menAct.close();
MessageBox.info("Bienvenido!", "Ingreso Correcto!", null);
}

}
};
t.scheduleRepeating(300);
}

}
});
flexTable.setWidget(3, 2, btnIngresa);
btnIngresa.setWidth("93px");
btnIngresa.setWidth("93px");
}



}



any help is welcome! regards!

(sorry for my english :D)

catalin.ciobanu
18 Oct 2011, 10:19 PM
http://sencha.com/examples/#centerlayout