title: Paint an image on a JPanel when button is clicked
body: <p>I'm trying to paint an image on a <code>JPanel</code> when I click a button, but I'm confused with the <code>paintComponent</code> and the <code>mouselistener</code>.</p>
  
  <p>This is the code I've done so far.</p>
  
  <pre><code>public class Efi {
  
      public JFrame frame;
      public JButton button;
      private JPanel panel;
      private JPanel panel1 = new JPanel(new FlowLayout());
      private JPanel panel2 = new JPanel(new FlowLayout());
      private Image sex = new ImageIcon("img.jpg").getImage();
  
      public Efi() {
          frame = new JFrame("EFI'S APPLICATION");
          frame.setLayout(null);
          button = new JButton("IMAGE");
          button.setLocation(0, 0);
          button.setSize(500, 50);
          frame.add(button);
          button.addMouseListener(ML);
  
          panel = new JPanel(null);
          panel.setSize(400, 400);
          panel.setLocation(50, 50);
          panel.setVisible(true);
          panel.setLayout(null);
          panel.setBorder(BorderFactory.createLineBorder(Color.black, 2));
          frame.add(panel);
     }
     // super.paintComponent(g);
     MouseListener ML = new MouseListener() {
  
          @Override
          public void mouseClicked(MouseEvent e) {
  
          }
  
          @Override
          public void mousePressed(MouseEvent e) {
          }
  
          @Override
          public void mouseReleased(MouseEvent e) {
          }
  
          @Override
          public void mouseEntered(MouseEvent e) {
          }
  
          @Override
          public void mouseExited(MouseEvent e) {
          }
      };
    }
  </code></pre>