title: How would I make a GUI using Swing that picks two elements from a list and presents the user with two buttons so they could chose the winner?
body: <p>I am working with a list of elements that I want to rank. Ideally the program would randomly choose 2 elements to compare and present them, sort the list with the new ranking, then select 2 more so the user could pick the winner over and over again until the user wanted to stop. The parts I am having trouble with are:</p>
  <ol>
  <li>getting the button to interact with the object to change its rank and</li>
  <li>getting the JFrame to close and reopen with new elements to compare</li>
  </ol>
  <p>I created a class called action that is supposed to handle the clicks:</p>
  <pre><code>public class action extends JFrame implements ActionListener{
    private JButton b1;
    private JButton b2;
    private JButton b3;
    private JPanel jp;
  
  
    public action(Bond one, Bond two){
      //JFrame mf = new JFrame(&quot;My Frame&quot;);
      //JPanel jp = new JPanel();
      jp = new JPanel();
      setSize(500,500);
      setVisible(true);
      setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
      b1 = new JButton(one.name+&quot;\nRating: &quot;+one.rating);
      b1.addActionListener(this);
      b2 = new JButton(two.name);
      b2.addActionListener(this);
      b3 = new JButton(&quot;Tie&quot;);
      b3.addActionListener(this);
      jp.add(b1);
      jp.add(b2);
      jp.add(b3);
      add(jp);
    }
    public void actionPerformed(ActionEvent e){
      int clickCount = 0;
      if (clickCount &gt; 3) {
        System.exit(0);
      }
      JOptionPane jo = new JOptionPane();
      if(e.getSource() == b1){
        //  jo.showMessageDialog(null, &quot;button 1&quot;);
        clickCount++;
        //System.exit(0);
      }
      if(e.getSource() == b2){
        jo.showMessageDialog(null, &quot;button 2&quot;);
        clickCount++;
        //System.exit(0);
      }
      if(e.getSource() == b3){
        jo.showMessageDialog(null, &quot;button 3&quot;);
        clickCount++;
        //System.exit(0);
      }
    }
  }
  </code></pre>
  <p>And here is how I am calling the action class from my main:</p>
  <pre><code>    while(compCount &lt; 3){
        //these generate random numbers that correspond with the index of the elements to be compared
        //comp is the name of the list of objects
        int r1 = r.nextInt(comp.size());
        int r2 = r.nextInt(comp.size());
        int t;
        if(r1 == r2){
          continue;
        }
        else{
          action a = new action(comp.get(r1), comp.get(r2));
          compCount++;
        }
      }
  </code></pre>
  <p>Currently this just creates 3 popup windows that do nothing when I click the buttons.
  Any help or insight would be appreciated!</p>