title: Swing change image with a button
body: <p>I have 2 class defined this way :</p>
  
  <pre><code>public class Cartes extends JPanel
  {
    private BufferedImage image;
    protected int tabC[] = new int[9];
    public int randomC ;
  
    public Cartes ()
    {
  
      ..........
  
      BufferedImage myPicture = null;
  
      try {
        myPicture = ImageIO.read(new File("images/"+randomC+".png"));
      } 
      catch (IOException e)
      {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
  
      JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
      add( picLabel );
    }
  
    public void paintComponent(Graphics g)
    {
      super.paintComponent(g);
      g.drawImage(image, 0, 0, null); //
    }
  }
  </code></pre>
  
  <p>Note : <code>randomC</code> is an integer generated in the constructor allowing me to choose at random an image .</p>
  
  <p>AND</p>
  
  <pre><code>public class VueGeo extends JFrame
  {
    public Cartes pan = new Cartes();
    private JButton bouton = new JButton("Change");
  
    public VueGeo()
    {
  
      ...
  
      container.add(pan, BorderLayout.CENTER);
  
      bouton.addActionListener(new BoutonListener ());
  
      ...
  
      this.setContentPane(container);
  
      this.setVisible(true);
  
    }
  
    class BoutonListener implements ActionListener
    {
      public void actionPerformed(ActionEvent arg0) {
        ????????
      }
    }
  } 
  </code></pre>
  
  <p>The problem is I don't know what to put in <code>actionPerformed</code> in order to allow me to change image whenever i click on Change . Does someone has an idea please ?</p>