What is java.awt.Component.getName() used for? It always seems to be null
in the applications I build with NetBeans. I\'m thinking of storing some help text p
I have searched many answers for getting name and i think this is the only easy solution
public static void main(String[] args) {
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
String name = actionEvent.getSource().toString();
UserReaction(ObjectName.getComponentVariableName(name), "null");
}
};
Button calculate_btn = new Button("Calculate");
calculate_btn.setName("Calculate");
calculate_btn.addActionListener(actionListener);
}
private static void UserReaction(String objectName) {
if (objectName.equals("Calculate")) {
//do something;
}
}static public String getComponentVariableName(String name) {
String res = (name.substring(name.indexOf("[") + 1));
res = res.split(",")[0];
return res;
}