title: Why isn't my paintComponent working?
body: <p>What I want to do with my program is when I click the image, the rectangle will come out, together with the JOptionPane. However, the JOptionPane is the only thing popping up.</p>
  
  <p>I tried changing methods and adding more classes, nothing worked >.&lt; Can anyone shed some light to my problem? Here's a snippet of my code.</p>
  
  <p>Below is where I call the filechooser which allows me to select my photo. Also, a bunch of other stuff like labels are here.</p>
  
  <pre><code>public Help(){
  
          fc.setDialogTitle("Choose an image file to begin:");
          int returnval = fc.showOpenDialog(null);
          if (returnval == JFileChooser.APPROVE_OPTION){ //when user selects a file, value returned will be JFileChooser.APPROVE_OPTION
              File file = fc.getSelectedFile(); //the File value of the selection is returned from a call on getSelectedFile
              try{
                  image = ImageIO.read(file); //reads and loads File as image
              }
              catch (IOException e){}
                  System.out.println("You chose to open this file: " + file.getName());
          }else
              System.out.println("No file selected.");
  
          icon = new ImageIcon(image);
          label = new JLabel(icon);
          tagName = new JLabel(input);
  
          label.addMouseListener(new ImagePanel());
          label.addMouseMotionListener(new ImagePanel());
          panel.add(tagName);
      }
  </code></pre>
  
  <p>And finally, my ImagePanel class, which contains the troublesome paintComponent. Also, a couple of mouseListeners.</p>
  
  <pre><code>class ImagePanel extends JPanel implements MouseListener, MouseMotionListener{
  
          @Override
          public void mouseClicked(MouseEvent event) {
              // TODO Auto-generated method stub
  
                  x = event.getX();
                  y = event.getY();
  
                  input = JOptionPane.showInputDialog("Enter tag name");
                  tagName.setText("You have tagged: " + input);
                  System.out.println(input);
          }
  
          @Override
          public void mouseEntered(MouseEvent arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void mouseExited(MouseEvent arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void mousePressed(MouseEvent arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void mouseReleased(MouseEvent arg0) {
              // TODO Auto-generated method stub
  
          }
  
          public void paintComponent(Graphics g){
              super.paintComponent(g);
  
                  if(image != null &amp;&amp; isRectPresent){
                      g.setColor(Color.DARK_GRAY);
                      g.drawRect(x-50, y-50, 100, 100);
                  }
          }   
  
          @Override
          public void mouseDragged(MouseEvent e) {
              // TODO Auto-generated method stub
          }
  
          @Override
          public void mouseMoved(MouseEvent e) {
              // TODO Auto-generated method stub
          }
      }
  </code></pre>
  
  <p>You can compile the code and see for yourself. Give me a heads up if you know what to do :) Thank you so much!</p>