Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ssn.ssijs.lgh_test15;
- import org.eclipse.swt.SWT;
- 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.Label;
- import org.eclipse.swt.widgets.Listener;
- import org.eclipse.swt.widgets.MessageBox;
- import org.eclipse.swt.widgets.Shell;
- import org.eclipse.swt.widgets.Text;
- public class User {
- private Display display = new Display();
- private Shell shell = new Shell(display);
- private Label label1;
- private Text userName;
- Text text;
- public User() {
- }
- public void showUserDialog() {
- shell.setLayout(new GridLayout(2, false));
- shell.setText("Start Game");
- label1 = new Label(shell, SWT.NULL);
- label1.setText("User Name: ");
- userName = new Text(shell, SWT.SINGLE | SWT.BORDER);
- userName.setText("");
- userName.setTextLimit(30);
- Button button = new Button(shell, SWT.PUSH);
- button.setText("Submit");
- button.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- String selected = userName.getText();
- if (selected == "") {
- MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING | SWT.CANCEL);
- messageBox.setMessage("Enter the User Name");
- messageBox.open();
- } else {
- shell.dispose();
- }
- }
- });
- userName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- shell.pack();
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- display.dispose();
- }
- public Display getDisplay() {
- return display;
- }
- public Shell getShell() {
- return shell;
- }
- public Label getLabel1() {
- return label1;
- }
- public Text getUserName() {
- return userName;
- }
- public Text getText() {
- return text;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement