Skip to content

Codes #236

@siddharthrgade21-a11y

Description

@siddharthrgade21-a11y

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;

public class ClipboardExample {
public static void main(String[] args) {
String textToCopy = "Hello from Advanced Java!";

    // Access the system clipboard
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    
    // Wrap the string in a Selection object
    StringSelection selection = new StringSelection(textToCopy);
    
    // Copy to clipboard
    clipboard.setContents(selection, selection);
    
    System.out.println("Text copied to clipboard: " + textToCopy);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions