1 /*
   2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation. Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package org.jemmy.swt;
  26 
  27 import org.eclipse.swt.SWT;
  28 import org.eclipse.swt.events.ModifyEvent;
  29 import org.eclipse.swt.events.ModifyListener;
  30 import org.eclipse.swt.events.SelectionEvent;
  31 import org.eclipse.swt.events.SelectionListener;
  32 import org.eclipse.swt.layout.RowLayout;
  33 import org.eclipse.swt.widgets.Button;
  34 import org.eclipse.swt.widgets.Combo;
  35 import org.eclipse.swt.widgets.Display;
  36 import org.eclipse.swt.widgets.List;
  37 import org.eclipse.swt.widgets.Shell;
  38 import org.eclipse.swt.widgets.Text;
  39 
  40 /**
  41  *
  42  * @author shura
  43  */
  44 public class Sample {
  45 
  46     public static void main(String[] args) {
  47         //Creates a new display object for the example to go into
  48         Display display = Display.getDefault();
  49         //Creates a new shell object
  50         final Shell shell = new Shell(display);
  51         //Sets the layout for the shell
  52         shell.setLayout(new RowLayout());
  53         final Text lbl = new Text(shell, SWT.DEFAULT);
  54         lbl.setText("click the button, please.");
  55         lbl.setBounds(0, 0, 100, 30);
  56         lbl.setEditable(true);
  57         Button btn = new Button(shell, SWT.DEFAULT);
  58         btn.setText("Click me!");
  59         btn.addSelectionListener(new SelectionListener() {
  60 
  61             public void widgetSelected(SelectionEvent arg0) {
  62                 lbl.setText("Now type some new text");
  63                 System.out.println(shell.getLocation());
  64             }
  65 
  66             public void widgetDefaultSelected(SelectionEvent arg0) {
  67                 //System.out.println(arg0);
  68             }
  69         });
  70         Combo combo = new Combo(shell, SWT.DEFAULT);
  71         combo.add("one");
  72         combo.add("two");
  73         combo.add("three");
  74         combo.add("four");
  75         combo.select(0);
  76         List list = new List(shell, SWT.DEFAULT);
  77         list.add("one");
  78         list.add("two");
  79         list.add("three");
  80         list.add("four");
  81         list.select(0);
  82         //Creates the control example - see import statement for location.
  83         shell.setText("Control Example");
  84         shell.setBounds(100, 100, 300, 200);
  85         shell.open();
  86         while (!shell.isDisposed()) {
  87             if (!display.readAndDispatch()) {
  88                 display.sleep();
  89             }
  90         }
  91     }
  92 }