Extending a java swing button? -
i want each jbutton have number or id associated it. why decided extend jbutton class make class superjbutton.
how include value of id/number in action event generated when button clicked class responds action can access id ?
another alternative doesn't require sub-classing, use jcomponent.putclientproperty(object key, object value)
store id associated button.
it can retrieved using getclientproperty(object key)
.
public void actionperformed(actionevent e) { jcomponent comp = (jcomponent)e.getsource(); keyobject kobj = (keyobject)comp.getclientproperty("button.id"); }
that might bit more flexible can attach id every button without need use application specific code e.g. when using gui builder it's bit complicated change creation code button, or when need use existing components.
Comments
Post a Comment