java - Register JPanel in radioButtonActionPerfomed -
can catch panel name actionlistener
?
here code:
void models (int panenum, int tabnum, string equery, string str, string title) throws sqlexception { intomodels[panenum] = new jpanel(); intomodels[panenum].setbackground(c); intomodels[panenum].setlayout(new gridlayout(6, 2)); resultset rs = database.setconnection().executequery(equery); buttongroup modelradiogroup = new buttongroup(); while (rs.next()) { jradiobutton radio = new jradiobutton(rs.getstring(str)); radio.addactionlistener(new radiobuttonactionperformed()); modelradiogroup.add(radio); intomodels[panenum].add(radio); } intomodels[panenum].setborder(borderfactory.createtitledborder(borderfactory.createetchedborder(), title)); panelstab[tabnum].add(intomodels[panenum]); }
and listener code:
public class radiobuttonactionperformed implements actionlistener { public void actionperformed(actionevent e){ system.out.println("selected radio: " + e.getactioncommand()); selectedmodel = e.getactioncommand(); } }
the interface:
i can selected radio, can't register panel. need register panel , save selected array on indexes 0 , 1 first , second panel.
have tried component.getparent()
method parent.
public void actionperformed(actionevent e) { object src=e.getsource(); if(src instanceof jradiobutton){ container parent=((jradiobutton)src).getparent(); if(parent instanceof jpanel){ system.out.println(parent.getname()); } } }
Comments
Post a Comment