2016-09-21 5 views
-2

私はスニペットクラスを持っています。どのようにマウスのクリックイベントで次のループを壊す?マウスクリックイベントでループを解除する方法

public class Sample { 

    private static Label label; 

    public static void main(String[] args) {   
     Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setLayout(new FillLayout()); 
     shell.setBounds(100, 100, 200, 70); 
     Button button = new Button(shell, SWT.NONE); 
     button.setText("Go"); 
     button.addListener(SWT.Selection, new Listener(){ 
      @Override 
      public void handleEvent(Event arg0) { 
       while (true) { 
        int x = MouseInfo.getPointerInfo().getLocation().x; 
        int y = MouseInfo.getPointerInfo().getLocation().y; 
        label.setText(x + ":" + y); 
       } 
      }}); 
     label = new Label(shell, SWT.NONE); 
     shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) display.sleep(); 
     } 
     display.dispose(); 
    } 
} 
+1

最初に達成しようとしていることは何ですか? – Baz

+0

外部アプリケーションにある指定されたテキストボックスをクリックして、ループの音を鳴らしたいです。私はクリックしたテキストボックスの位置(x、y)を思い出したい。 – ks099

+0

外部アプリケーションのテキストボックスがクリックされたことをどのように知っていますか? – Baz

答えて

0

私は自分が望むものを持っています。 Bazにご協力いただきありがとうございます。

public class Sample { 

private static Label label; 

public static void main(String[] args) {   
    Display display = new Display(); 
    Shell shell = new Shell(display); 
    shell.setLayout(new FillLayout()); 
    shell.setBounds(100, 100, 200, 70); 
    Button button = new Button(shell, SWT.NONE); 
    button.setText("Go"); 
    button.addListener(SWT.Selection, new Listener(){ 
     @Override 
     public void handleEvent(Event arg0) { 
      Shell screenShell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); 
      screenShell.setMaximized(true); 
      screenShell.setBackground(display.getSystemColor(SWT.COLOR_GRAY)); 
      screenShell.setAlpha(120); 
      screenShell.addListener(SWT.MouseDown, new Listener() { 
       @Override 
       public void handleEvent(Event event) { 
        screenShell.close();       
       }}); 
      screenShell.open(); 
      Display.getCurrent().timerExec(10, new Runnable(){ 
       @Override 
       public void run() { 
        if (!screenShell.isDisposed()) { 
         int x = MouseInfo.getPointerInfo().getLocation().x; 
         int y = MouseInfo.getPointerInfo().getLocation().y; 
         label.setText(x + ":" + y); 
         Display.getCurrent().timerExec(10, this); 
        } 
       }});  
     }}); 

    label = new Label(shell, SWT.NONE); 
    shell.open(); 

    while (!shell.isDisposed()) { 
     if (!display.readAndDispatch()) display.sleep(); 
    } 
    display.dispose(); 
} 
関連する問題