netbeans - "Simply" determining Java Radio Button id -
i'm hoping java not in-elegant efforts lead me believe.
i working jradiobuttons, , want programmatically determine "id" associated them. this, trying read "name" listed in netbeans properties.
in ide, when right-click component, given option of "change variable name..." use set values such rb1, rb2, etc.
but in properties panel, there "name" entry can set different value. use set "id"-s such 1, 2, etc.
working radio buttons, know can have series of if-statements that, in handler, ask
object src = evt.getsource(); int val=-1; if (src == rb1) { val=1; } else if (src == rb2) { val=2; } else if (src == rb3) { val=3; } else { val=4; }
but, besides requiring me hard code id value control name myself, i'm prone make transcription error, want believe there simpler single-statement means achieve this, like:
string name = rbgroup.getselection().getname(); .gettext(); .getlabel();
but, seem stuck less elegant , verbose use of multiple if-else statements.
how can query control give me properties listed in netbeans ide in simplest means possible?
one way use action command of button:
rb1.setactioncommand("1");
then in event handler can juse use:
string command = evt.getactioncommand();
the action command defaults text of button if don't set explicitly.
Comments
Post a Comment