Remove all Jbuttons and passing the setText value to other variables : <p>I want to be able to remove all the JButton that is tied to b by just clicking on whichever of them and also to pass the value from the button that the user clicked to outside the loop. The code below only removes the button the user clicked on only.</p>

<pre><code>for (File file : listOfFiles) {
                int fileCount = 0;
                if (file.isFile()) {    
                    JButton b = new JButton(String.valueOf(fileCount));
                    fileCount++;
                    b.setText(file.getName());
                    b.setPreferredSize(new Dimension(300, 40));
                    Panel.add(b);
                    frame.add(b);
                    b.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                            b.setVisible(false);
                        }
                    });
                }
            }
</code></pre>
