getSystemClipboard() method of the
java.awt.Toolkit class.StringSelection,
which implements the transferable interface and contains the data
you want to copy.setContents() method of the Clipboard class.For example,
public void copy(TextField tf) {
StringSelection data = new StringSelection(tf.getText());
Clipboard clipboard = Toolkit().getDefaultToolkit().getSystemClipboard();
clipboard.setContents(data, data);
}
getSystemClipboard() method of the
java.awt.Toolkit class.getContents() method of the Clipboard class.getTransferData().For example,
public void paste(TextField tf) {
Clipboard clipboard = Toolkit().getDefaultToolkit().getSystemClipboard();
Transferable data = clipboard.getContents(this);
String s;
try {
s = (String) (data.getTransferData(DataFlavor.stringFlavor));
}
catch (Exception ex) {
s = data.toString();
}
tf.setText(s);
}