Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package com.ssn.ssijs.lgh_test15;
  2.  
  3. import org.eclipse.swt.SWT;
  4. import org.eclipse.swt.layout.GridData;
  5. import org.eclipse.swt.layout.GridLayout;
  6. import org.eclipse.swt.widgets.Button;
  7. import org.eclipse.swt.widgets.Display;
  8. import org.eclipse.swt.widgets.Event;
  9. import org.eclipse.swt.widgets.Label;
  10. import org.eclipse.swt.widgets.Listener;
  11. import org.eclipse.swt.widgets.MessageBox;
  12. import org.eclipse.swt.widgets.Shell;
  13. import org.eclipse.swt.widgets.Text;
  14.  
  15. public class User {
  16. private Display display = new Display();
  17. private Shell shell = new Shell(display);
  18. private Label label1;
  19. private Text userName;
  20.  
  21. Text text;
  22.  
  23. public User() {
  24.  
  25. }
  26.  
  27. public void showUserDialog() {
  28. shell.setLayout(new GridLayout(2, false));
  29. shell.setText("Start Game");
  30. label1 = new Label(shell, SWT.NULL);
  31. label1.setText("User Name: ");
  32.  
  33. userName = new Text(shell, SWT.SINGLE | SWT.BORDER);
  34. userName.setText("");
  35. userName.setTextLimit(30);
  36.  
  37. Button button = new Button(shell, SWT.PUSH);
  38. button.setText("Submit");
  39. button.addListener(SWT.Selection, new Listener() {
  40. @Override
  41. public void handleEvent(Event event) {
  42. String selected = userName.getText();
  43.  
  44. if (selected == "") {
  45. MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING | SWT.CANCEL);
  46. messageBox.setMessage("Enter the User Name");
  47. messageBox.open();
  48.  
  49. } else {
  50. shell.dispose();
  51. }
  52. }
  53.  
  54. });
  55. userName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  56.  
  57. shell.pack();
  58. shell.open();
  59.  
  60. while (!shell.isDisposed()) {
  61. if (!display.readAndDispatch()) {
  62. display.sleep();
  63. }
  64. }
  65. display.dispose();
  66. }
  67.  
  68. public Display getDisplay() {
  69. return display;
  70. }
  71.  
  72. public Shell getShell() {
  73. return shell;
  74. }
  75.  
  76. public Label getLabel1() {
  77. return label1;
  78. }
  79.  
  80. public Text getUserName() {
  81. return userName;
  82. }
  83.  
  84. public Text getText() {
  85. return text;
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement