package com.gwesm;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class AuthenticationUI {
public static void main(String[] args) {
Text userName;
Text userPassword;
GridData gridData = new GridData();
GridLayout gridLayout = new GridLayout();
Display display = new Display();
final Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN);
shell.setText("Guild Wars : ESM - Login");
shell.setSize(250, 190);
gridLayout.numColumns = 2;
shell.setLayout(gridLayout);
/*
* Enabling window close pressing escape
*/
shell.addListener(SWT.Traverse, new Listener() {
public void handleEvent(Event event) {
switch (event.detail) {
case SWT.TRAVERSE_ESCAPE:
shell.close();
event.detail = SWT.TRAVERSE_NONE;
event.doit = false;
break;
}
}
});
/*
* Defining widgets
*/
Group userInfo = new Group(shell, SWT.NONE);
userInfo.setText("User Info");
gridLayout = new GridLayout();
gridLayout.numColumns = 2;
userInfo.setLayout(gridLayout);
gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
gridData.horizontalSpan = 2;
userInfo.setLayoutData(gridData);
new Label(userInfo, SWT.NONE).setText("Name:");
userName = new Text(userInfo, SWT.SINGLE | SWT.BORDER);
userName.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
true, false));
new Label(userInfo, SWT.NONE).setText("Password:");
userPassword = new Text(userInfo, SWT.PASSWORD | SWT.SINGLE
| SWT.BORDER);
userPassword.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
true, false));
Button enterButton = new Button(shell, SWT.PUSH);
enterButton.setText("Enter");
gridData = new GridData();
gridData.widthHint = 110;
gridData.heightHint = 40;
gridData.horizontalAlignment = SWT.CENTER;
gridData.horizontalSpan = 2;
enterButton.setLayoutData(gridData);
Button closeButton = new Button(shell, SWT.PUSH);
closeButton.setText("close");
gridData = new GridData();
gridData.widthHint = 80;
gridData.heightHint = 25;
gridData.horizontalAlignment = SWT.CENTER;
gridData.horizontalSpan = 2;
closeButton.setLayoutData(gridData);
/*
* Defining close shell on pressing close button
*/
closeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
shell.close();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}