Java getToolkit() question

edited October 2016 in Questions about Code

I'm trying to update a program I wrote in Processing 2.2.1 to Processing 3.2.1.

The following code runs fine in Processing 2. In processing 3 it throws an error that "getToolkit() does not exist." I have to use "Toolkit.getDefaulToolkit().getSystemClipboard()." Why does this break in Processing 3?

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;


Object GetFromClipboard(DataFlavor flavor)
{
  Clipboard clipboard = getToolkit().getSystemClipboard();
  Transferable contents = clipboard.getContents(null);
  Object obj = null;
  if (contents != null && contents.isDataFlavorSupported(flavor))
  {
    try
    {
     obj = contents.getTransferData(flavor);
    }
    catch (UnsupportedFlavorException exu) // Unlikely but we must catch it
    {
     println("Unsupported flavor: " + exu);
//~      exu.printStackTrace();
    }
    catch (java.io.IOException exi)
    {
     println("Unavailable data: " + exi);
//~      exi.printStackTrace();
    }
  }
  return obj;
} 

Answers

Sign In or Register to comment.