We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
I just found this:
"Applet is gone — Java's java.awt.Applet is no longer the base class used by PApplet, so any sketches that make use of Applet-specific methods (or assume that a PApplet is a Java AWT Component object) will need to be rewritten."
getToolkit() is a Component method.
https://forum.Processing.org/two/discussion/17270/why-this-getx-method-is-missing-in-processing-3-1-1