get the Clip Board contents, it initializes the ClipBoard object. - Java Native OS

Java examples for Native OS:Clipboard

Description

get the Clip Board contents, it initializes the ClipBoard object.

Demo Code


//package com.java2s;
import java.awt.Toolkit;

import java.awt.datatransfer.Clipboard;

public class Main {
    public static void main(String[] argv) throws Exception {
        getClipboard();//from w w  w  .j av  a 2  s  .  c  o m
    }

    private static Clipboard clipboard = null;

    /**
     * Method to get the Clip Board contents, it initializes the
     * ClipBoard object. It starts a sub thread to copy the contents.
     * created : Nov 20, 2006 8:55:21 PM
     */
    private static void getClipboard() {
        // this is our simple thread that grabs the clipboard
        Thread clipThread = new Thread() {
            public void run() {
                clipboard = Toolkit.getDefaultToolkit()
                        .getSystemClipboard();
            }
        };

        // start the thread as a daemon thread and wait for it to die
        if (clipboard == null) {
            try {
                clipThread.setDaemon(true);
                clipThread.start();
                clipThread.join();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

Related Tutorials