/**
   * Create the GUI and show it. For thread safety, this method should be invoked from the
   * event-dispatching thread.
   */
  private static void createAndShowGUI() {
    // Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    // Create and set up the window.
    JFrame frame = new JFrame("SelectionDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set up the content pane.
    SelectionDemo controller = new SelectionDemo();
    controller.buildUI(frame.getContentPane(), createImageIcon(starFile));

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
    protected void paintComponent(Graphics g) {
      super.paintComponent(g); // paints the background and image

      // If currentRect exists, paint a box on top.
      if (currentRect != null) {
        // Draw a rectangle on top of the image.
        g.setXORMode(Color.white); // Color of line varies
        // depending on image colors
        g.drawRect(rectToDraw.x, rectToDraw.y, rectToDraw.width - 1, rectToDraw.height - 1);

        controller.updateLabel(rectToDraw);
      }
    }