<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSWT_JFace_Eclipse%2FThread</id>
		<title>Java/SWT JFace Eclipse/Thread - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSWT_JFace_Eclipse%2FThread"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/SWT_JFace_Eclipse/Thread&amp;action=history"/>
		<updated>2026-04-21T21:41:27Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/SWT_JFace_Eclipse/Thread&amp;diff=5676&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/SWT_JFace_Eclipse/Thread&amp;diff=5676&amp;oldid=prev"/>
				<updated>2010-06-01T05:56:06Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:56, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/SWT_JFace_Eclipse/Thread&amp;diff=5675&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/SWT_JFace_Eclipse/Thread&amp;diff=5675&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Illustrates multithread UI programming issues ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
 * Copyright (c) 1998, 2004 Jackwind Li Guojie&lt;br /&gt;
 * All right reserved. &lt;br /&gt;
 * &lt;br /&gt;
 * Created on Oct 25, 2003 4:12:32 PM by JACK&lt;br /&gt;
 * $Id: PICalculator.java,v 1.1 2003/12/22 12:07:54 jackwind Exp $&lt;br /&gt;
 * &lt;br /&gt;
 * visit: http://www.asprise.ru/swt&lt;br /&gt;
 *****************************************************************************/&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.events.SelectionEvent;&lt;br /&gt;
import org.eclipse.swt.events.SelectionListener;&lt;br /&gt;
import org.eclipse.swt.graphics.Rectangle;&lt;br /&gt;
import org.eclipse.swt.widgets.Button;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
/**&lt;br /&gt;
 * Illustrates multithread UI programming issues.&lt;br /&gt;
 */&lt;br /&gt;
public class PICalculator {&lt;br /&gt;
  Display display = new Display();&lt;br /&gt;
  Shell shell = new Shell(display);&lt;br /&gt;
  Button buttonThread = new Button(shell, SWT.PUSH);&lt;br /&gt;
  Button buttonAsyncExec = new Button(shell, SWT.PUSH);&lt;br /&gt;
  public PICalculator(boolean asyncExecEnabled) {&lt;br /&gt;
    final boolean async = asyncExecEnabled;&lt;br /&gt;
    shell.setText(&amp;quot;PI Calculator&amp;quot;);&lt;br /&gt;
    shell.setSize(400, 80);&lt;br /&gt;
    Rectangle clientArea = shell.getClientArea();&lt;br /&gt;
    buttonThread.setText(&lt;br /&gt;
      &amp;quot;Click here to calculate PI  [Non-UI thread UI Update]&amp;quot;);&lt;br /&gt;
    buttonThread.setBounds(&lt;br /&gt;
      clientArea.x,&lt;br /&gt;
      clientArea.y,&lt;br /&gt;
      clientArea.width,&lt;br /&gt;
      clientArea.height / 2);&lt;br /&gt;
    buttonThread.addSelectionListener(new SelectionListener() {&lt;br /&gt;
      public void widgetDefaultSelected(SelectionEvent e) {&lt;br /&gt;
      }&lt;br /&gt;
      public void widgetSelected(SelectionEvent e) {&lt;br /&gt;
        buttonThread.setText(&amp;quot;Calculation in progress ...&amp;quot;);&lt;br /&gt;
        getTask(buttonThread).start();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    &lt;br /&gt;
    buttonAsyncExec.setText(&amp;quot;Click here to calculate PI  [asynExec method UI Update]&amp;quot;);&lt;br /&gt;
    buttonAsyncExec.setBounds(&lt;br /&gt;
      clientArea.x,&lt;br /&gt;
      clientArea.y + clientArea.height / 2,&lt;br /&gt;
      clientArea.width,&lt;br /&gt;
      clientArea.height / 2);&lt;br /&gt;
    buttonAsyncExec.addSelectionListener(new SelectionListener() {&lt;br /&gt;
      public void widgetDefaultSelected(SelectionEvent e) {&lt;br /&gt;
      }&lt;br /&gt;
      public void widgetSelected(SelectionEvent e) {&lt;br /&gt;
        buttonAsyncExec.setText(&amp;quot;Calculation in progress ...&amp;quot;);&lt;br /&gt;
        getTask2(buttonAsyncExec).start();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    shell.open();&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch()) {&lt;br /&gt;
        display.sleep();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    // new CalculatePI(false);&lt;br /&gt;
    new PICalculator(true);&lt;br /&gt;
  }&lt;br /&gt;
  public Thread getTask(Button button) {&lt;br /&gt;
    final Button theButton = button;&lt;br /&gt;
    return new Thread() {&lt;br /&gt;
      public void run() {&lt;br /&gt;
        double pi = calculatePI(9999999);&lt;br /&gt;
        theButton.setText(&amp;quot;PI = &amp;quot; + pi); // Update UI.&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
  }&lt;br /&gt;
  public Thread getTask2(Button button) {&lt;br /&gt;
    final Button theButton = button;&lt;br /&gt;
    return new Thread() {&lt;br /&gt;
      public void run() {&lt;br /&gt;
        final double pi = calculatePI(9999999);&lt;br /&gt;
        &lt;br /&gt;
        display.asyncExec(new Runnable() {&lt;br /&gt;
          public void run() {&lt;br /&gt;
            &lt;br /&gt;
            // Update UI.&lt;br /&gt;
            &lt;br /&gt;
            theButton.setText(&amp;quot;PI = &amp;quot; + pi); &lt;br /&gt;
            &lt;br /&gt;
          }&lt;br /&gt;
        });&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
  }  &lt;br /&gt;
  /**&lt;br /&gt;
   * Calculate value of PI using Vieta&amp;quot;s formula. For a complete discussion,&lt;br /&gt;
   * please visit:&lt;br /&gt;
   * http://documents.wolfram.ru/v4/GettingStarted/CalculatingPi.html&lt;br /&gt;
   * &lt;br /&gt;
   * @param nestedLevel -&lt;br /&gt;
   *            level of nested square roots in Vieta&amp;quot;s formula.&lt;br /&gt;
   * @return value of PI&lt;br /&gt;
   */&lt;br /&gt;
  public static double calculatePI(int nestedLevel) {&lt;br /&gt;
    double product = 1;&lt;br /&gt;
    double lastSqrtValue = 0;&lt;br /&gt;
    for (int i = 0; i &amp;lt; nestedLevel; i++) {&lt;br /&gt;
      double sqrt = getNextSqrtValue(lastSqrtValue);&lt;br /&gt;
      product *= 0.5 * sqrt;&lt;br /&gt;
      lastSqrtValue = sqrt;&lt;br /&gt;
    }&lt;br /&gt;
    return 2 / product;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Return the square root item value.&lt;br /&gt;
   * &lt;br /&gt;
   * @param lastValue -&lt;br /&gt;
   *            last square root item value.&lt;br /&gt;
   * @return&lt;br /&gt;
   */&lt;br /&gt;
  public static double getNextSqrtValue(double lastValue) {&lt;br /&gt;
    return Math.sqrt(2 + lastValue);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SWT and Thread ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
 * Copyright (c) 1998, 2004 Jackwind Li Guojie&lt;br /&gt;
 * All right reserved. &lt;br /&gt;
 * &lt;br /&gt;
 * Created on Oct 26, 2003 2:45:03 PM by JACK&lt;br /&gt;
 * $Id: SyncExecExample.java,v 1.1 2003/12/22 12:07:54 jackwind Exp $&lt;br /&gt;
 * &lt;br /&gt;
 * visit: http://www.asprise.ru/swt&lt;br /&gt;
 *****************************************************************************/&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.events.SelectionEvent;&lt;br /&gt;
import org.eclipse.swt.events.SelectionListener;&lt;br /&gt;
import org.eclipse.swt.widgets.Button;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
/**&lt;br /&gt;
 * syncExec Example. &lt;br /&gt;
 */&lt;br /&gt;
public class SyncExecExample {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    final Display display = new Display();&lt;br /&gt;
    Shell shell = new Shell(display);&lt;br /&gt;
    &lt;br /&gt;
    final Runnable print = new Runnable() {&lt;br /&gt;
      public void run() {&lt;br /&gt;
        System.out.println(&amp;quot;Print from thread: \t&amp;quot; + Thread.currentThread().getName());&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
    &lt;br /&gt;
    final Thread applicationThread = new Thread(&amp;quot;applicationThread&amp;quot;) {&lt;br /&gt;
      public void run() {&lt;br /&gt;
        System.out.println(&amp;quot;Hello from thread: \t&amp;quot; + Thread.currentThread().getName());&lt;br /&gt;
        display.syncExec(print);&lt;br /&gt;
        System.out.println(&amp;quot;Bye from thread: \t&amp;quot; + Thread.currentThread().getName());&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
    &lt;br /&gt;
    shell.setText(&amp;quot;syncExec Example&amp;quot;);&lt;br /&gt;
    shell.setSize(300, 100);&lt;br /&gt;
    &lt;br /&gt;
    Button button = new Button(shell, SWT.CENTER);&lt;br /&gt;
    button.setText(&amp;quot;Click to start&amp;quot;);&lt;br /&gt;
    button.setBounds(shell.getClientArea());&lt;br /&gt;
    button.addSelectionListener(new SelectionListener() {&lt;br /&gt;
      public void widgetDefaultSelected(SelectionEvent e) {&lt;br /&gt;
      }&lt;br /&gt;
      public void widgetSelected(SelectionEvent e) {&lt;br /&gt;
        applicationThread.start();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    &lt;br /&gt;
    shell.open();    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    while(! shell.isDisposed()) {&lt;br /&gt;
      if(! display.readAndDispatch()) {// If no more entries in event queue&lt;br /&gt;
        display.sleep();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    display.dispose();&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>