By looping, I created tags. I need to, when I click on them with the mouse, they disappear. She clicked on one, she disappeared, on the other and so on. But when I launch, the labels do not disappear. What needs to be done to make everything work as it should?
lol = new JPanel(); lol.setBounds(10, 47, 974, 693); contentPane.add(lol); lol.setLayout(null); for (int k = 0; k < 50; k++){ label_2 = new JLabel(""); label_2.setIcon(new ImageIcon(P.class.getResource("/images/00.png"))); int w = randomRange(10, 974); int r = randomRange(10, 693); label_2.setBounds(w, r, 200, 200); label_2.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { lol.remove(label_2); } }); lol.add(label_2); }
MouseEventshould be a link to the clicked control. Here it should be removed. - Igor