How to find JLabel that was clicked and show ImageIcon from it?
问题 Here is my code. I want to know which l was clicked and then in a new frame, display that ImageIcon. The e.getSource() is not working... final JFrame shirts = new JFrame("T-shirts"); JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); for (int i = 1; i < 13; i++) { l = new JLabel(new ImageIcon("T-shirts/"+i+".jpg"), JLabel.CENTER); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); l.setFont(l.getFont().deriveFont(20f)); panel.add(l); }//end of for loop panel