title: Getting RGB value from under mouse cursor
body: <p>I am trying to build a program that detects the color that is under the mouse cursor and then displays the color and RGB values in a window on the screen. I am VERY new to Java so do not know much of anything. I have two codes I have worked on, with help from a friend, The first one gets the RGB values of a specific coordinate of a buffered image, and the other takes user defined RGB values and shows a pane with the color in it. My question is "how do I get the program to detect the color under the mouse cursor no matter what it is scrolling over?</p>
  
  <pre><code>public class Buffered_Image 
  {
  public static void main(String[] args) throws IOException 
  {
      BufferedImage bi = ImageIO.read(new File("C:/Users/user/Pictures/Hornet.jpg"));
      Color c = new Color(bi.getRGB(50,40));
      int red=c.getRed();
      int green=c.getGreen();
      int blue=c.getBlue();
  
      System.out.print("Red " + red + " Green " + green+ " Blue" + blue + "\n" );
  }
  }
  
  
  
  
  public class RGB_Pane 
  {
  
  public static void main(String[] args) 
  {
      JFrame F = new JFrame("RGB");
      Panel Pan = new Panel();
      F.getContentPane().add(Pan);
      F.pack();
      F.setVisible(true);
      F.setSize(300, 300);
  }
  }
  
  class Panel extends JPanel
  {
  public Panel()
  { 
      setPreferredSize(new Dimension(200,200));
      int Red = Integer.parseInt(JOptionPane.showInputDialog("Enter value for RED"));
      int Green = Integer.parseInt(JOptionPane.showInputDialog("Enter value for Green"));
      int Blue = Integer.parseInt(JOptionPane.showInputDialog("Enter value for BLUE"));
      Color Defined_Color = new Color(Red,Green,Blue);
      setBackground(Defined_Color);
  }
  }
  </code></pre>