本文整理匯總了Java中java.awt.datatransfer.Clipboard.getData方法的典型用法代碼示例。如果您正苦於以下問題:Java Clipboard.getData方法的具體用法?Java Clipboard.getData怎麽用?Java Clipboard.getData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.datatransfer.Clipboard
的用法示例。
在下文中一共展示了Clipboard.getData方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runTest
import java.awt.datatransfer.Clipboard; //導入方法依賴的package包/類
private static void runTest() throws Exception {
String testString = "my string";
JTextField tf = new JTextField(testString);
tf.selectAll();
Clipboard clipboard = new Clipboard("clip");
tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY);
DataFlavor[] dfs = clipboard.getAvailableDataFlavors();
for (DataFlavor df: dfs) {
String charset = df.getParameter("charset");
if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) &&
charset != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(
(InputStream) clipboard.getData(df), charset));
String s = br.readLine();
System.out.println("Content: '" + s + "'");
passed &= s.contains(testString);
}
}
}
示例2: getLicenseKeyFromClipboard
import java.awt.datatransfer.Clipboard; //導入方法依賴的package包/類
private String getLicenseKeyFromClipboard() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
try {
String licenseFromClipboard = (String)clipboard.getData(DataFlavor.stringFlavor);
if(ProductConstraintManager.INSTANCE.isLicenseValid(licenseFromClipboard)) {
return licenseFromClipboard;
}
} catch (Exception var3) {
;
}
return null;
}
示例3: getClipboardImage
import java.awt.datatransfer.Clipboard; //導入方法依賴的package包/類
/**
* Gets an image from Clipboard.
*
* @return image
*/
public static Image getClipboardImage() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
try {
return (Image) clipboard.getData(DataFlavor.imageFlavor);
} catch (Exception e) {
return null;
}
}
示例4: getScreenfromClipB
import java.awt.datatransfer.Clipboard; //導入方法依賴的package包/類
Image getScreenfromClipB() {
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
if (clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor)) {
try {
return (Image) clipboard.getData(DataFlavor.imageFlavor);
} catch (UnsupportedFlavorException | IOException ex) {
Logger.getLogger(CropUIController.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
示例5: main
import java.awt.datatransfer.Clipboard; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Clipboard clipboard =
Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor dataFlavor = new DataFlavor(DataFlavor.javaRemoteObjectMimeType +
";class=Hello" );
Object data = clipboard.getData(dataFlavor);
System.err.print(((Hello) data).sayHello());
}