How to code Auto mouse color function in Java

I'm thinking of a Java program that would recognize the text on the screen as the cursor hovers. By that, the background color would automatically change based on the text. For example, as the mouse points to text "black", the background would be black. How could I do this auto mouse color function?
