title: Paint Image in JPanel using drawImage
body: <p>may I ask your help? I'm having some trouble painting an image inside a JPanel. I used to create a class that extended JPanel and did this</p>
  
  <pre><code>public class Example extends JPanel {
  
      BufferedImage background;
  
      public Example () {
  
          background = loadImage();   
      }           
  
      private BufferedImage loadImage(){
          URL imagePath = getClass().getResource("Immagini/Board.png");
          BufferedImage result = null;
          try {
              result = ImageIO.read(imagePath);
          } catch (IOException e) {
              System.err.println("Errore, immagine non trovata");
          }
  
          return result;
      }
  
       @Override
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          Dimension size = getSize();
          g.drawImage(background, 0, 0,size.width, size.height,0, 0, background.getWidth(), background.getHeight(), null);
  
      }
  }
  </code></pre>
  
  <p>And it was perfect, now i can't do that because my newExample class extends genericExample so can't extend JPanel too. I have <code>JPanel panel = new JPanel()</code> inside the newExample in which i'd like to paint like I did in the code above, how can I adapt it to use in this different situation? </p>