[Solved] Renaming button name [closed]


Your question is not very clear, but the String name is a java.awt.Component property.

In case you mean this name,
you can change a component’s name with .setName() and get the name with .getName().

A component’s name by default is null, until you set it. It makes usually sense to .getName() in listeners.

Here is an example. If you have many panels, you can set each name:

        JPanel p = new JPanel();
        p.addMouseListener((MouseListener) this);
        p.setName("Panel" + i + "_" + j);

and then check in order to find where your mouse was clicked at:

@Override
public void mouseClicked(MouseEvent e) {            
        JPanel p = (JPanel) e.getSource();
        String s = p.getName();
        String[] numbers = s.replaceAll("^\\D+", "").split("\\D+");
        int y = Integer.valueOf(numbers[0]);
        int x = Integer.valueOf(numbers[1]);
        ...

1

solved Renaming button name [closed]