title: Adding a Image Within a switch - PaintComponent Override
body: <p>Im trying to add a small burger.jpg img to a game I am making. The burger should be added whenever 'f'(food) is passed in Switch. Im having issues implementing this in my code. </p>
  
  <p>I was originally just filling an orange rectangle <code>g2.fillRect()</code>, but I would like to replace this with an actual image instead. I've tried scaling the image and adding it but it doesn't show up. If I replace the<code>g2.fillRect</code> at the end of the for loop, it makes every square a burger, instead of just the 'f'</p>
  
  <p>How would I do this?</p>
  
  <pre><code>private class Game extends JPanel {
  
      BufferedImage img = null;
  
      @Override
      public void paintComponent(Graphics g2) {
  
          super.paintComponent(g2);
  
          try {
  
              img = ImageIO.read(new File("src/burger.jpg"));
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          BufferedImage otherImage = new BufferedImage(50, 50,
                  BufferedImage.TYPE_INT_RGB);
          Graphics g = otherImage.createGraphics();
  
          int width = getWidth() / game.getBoardWidth();
          int height = getHeight() / game.getBoardHeight();
  
          char[] symbols = game.toString().toCharArray();
  
          int x = 0;
          int y = 0;
  
          for (char c : symbols) {
  
              switch (c) {
              case 'Q':
                  g2.setColor(Color.BLACK);
                  break;
              case 'H':
                  g2.setColor(Color.GREEN);
                  break;
              case 'f':
                  //g2.setColor(Color.ORANGE);
                  g2.drawImage(img, x, y, width, height, null);
                  break;
              case '-':
                  g2.setColor(Color.WHITE);
                  break;
              case '\n':
                  y += height;
                  x = 0; 
              }
  
             //g2.drawImage(img, x, y, width, height, null);
             g2.fillRect(x, y, width, height);
              x += width;
          }
      }
  
  }
  </code></pre>