Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: How to copy from Java ?

Author: Manfred Rosenboom

Date: 12:40:04 09/05/00

Go up one level in this thread


On September 04, 2000 at 19:15:46, Pierre Bourget wrote:

>Any tricks to copy the moves list from a java interface ?

This must be programmend in the Java component, with the help of the
java.awt.datatransfer package. Here a code snippet from my Java chessboard
component:

import java.awt.datatransfer.*;

...

  /**
  *  get an EPD string from the system clipboard.
  */
  public void getBoardFromClipboard()
  {
    if (fApplet != null)
      return;

    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    if (clipboard == null)
     {
      return;
     }

    Transferable data = clipboard.getContents(this);
    String s;
    try {
      s = (String) (data.getTransferData(DataFlavor.stringFlavor));
    }
    catch (Exception e) {
      s = data.toString();
    }

    try {
      this.setBoard(s);
    }
    catch (Exception e) {
    }
  }


  /**
  *  put the actual board data to the system clipboard as an EPD string.
  */
  public void putBoardToClipboard()
  {
    if (fApplet != null)
      return;

    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    if (clipboard == null)
     {
      return;
     }

    String s = this.getBoard();
    if (s == null)
      return;

    StringSelection data = new StringSelection(s);
    clipboard.setContents(data, data);
  }




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.