title: Using JRadioButton to display images
body: <p>I need help with a small little problem. I'm not sure how to display an image properly after clicking a JRadioButton. Nothing shows up after I click any button and idk where to begin. Any help is appreciated.</p>
  
  <pre><code>public class DisplayImage extends JFrame{
  private JRadioButton pic1Button, pic2Button;
  private ImageIcon pic1Image,pic2Image;
  private JLabel pic1Label,pic2Label;
  
  
  public DisplayImage(){
      super("JRadioButton Image");
      setLayout(new FlowLayout());
  
      pic1Button = new JRadioButton("pic1");
      pic1Button.addActionListener(new displayListener());
  
      pic2Button = new JRadioButton("pic2");
      pic2Button.addActionListener(new displayListener());
      ButtonGroup bg = new ButtonGroup();
      bg.add(pic1Button);
      bg.add(pic2Button);
      JPanel panel = new JPanel();
      panel.add(pic1Button);
      panel.add(pic2Button);
      add(panel);
  }
  private class displayListener implements ActionListener{
      public void actionPerformed(ActionEvent e){
          if(e.getSource()==pic1Button){
              pic1Image = new ImageIcon(getClass().getResource("car.jpg"));
              pic1Label = new JLabel(pic1Image);
              add(pic1Label);
          }
          if(e.getSource()==pic2Button){
              pic2Image = new ImageIcon(getClass().getResource("plane.jpg"));
              pic2Label = new JLabel(pic2Image);
              add(pic2Label);
          }
  
      }
  
  }
  public static void main(String[]args){
      DisplayImage gui = new DisplayImage();
      gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      gui.setSize(300,300);
      gui.setVisible(true);
  }
  </code></pre>