title: How to set a image icon to JButton?
body: <p>I want to set a image icon to JButton, here the code that i tried:</p>
  
  <pre><code>public class Calculator {
  
      public static JFrame f;
  
      Calculator() throws IOException{
  
          JButton b;
  
          f = new JFrame();
          Image play = ImageIO.read(getClass().getResource("images/play.png"));
          b = new JButton(new ImageIcon(play));
  
          b.setBounds(250,250,75,20);
  
          f.add(b);
          f.setSize(500,500);
          f.setLayout(null);
          f.setVisible(true);
      }
  
      public static void main(String[] args) throws IOException {
  
          new Calculator();
      }
  }
  </code></pre>
  
  <p>The program runs normally without errors, but the image didn't appear.</p>
  
  <p>I think the image url is wrong.</p>
  
  <p>I am using netbeans, so I created a folder named images in the source packages directory.</p>