java - Nesting actionPerformed() -


i'm designing program allows users reserve airplane flight. when program first runs, jframe opens 2 buttons. depending on button clicked, actionperformed opens new jpanels, etc.

i'm trying create tab inside jtabbedpane display 2 buttons. clicking either button lead different image, section of code in actionperformed method. how can find out button clicked?

this method used:

protected jcomponent makeimagepanel(string path1, string path2)  {     try{         jpanel panel= new jpanel(false);         jbutton international= new jbutton("international flights");         jbutton domestic= new jbutton("domestic flights");         international.setactioncommand("login");         domestic.setactioncommand("domestic");         international.setenabled(true);         international.addactionlistener(new actionlistener() {                 @override                 public void actionperformed(actionevent e) {                     bufferedimage mypicture = imageio.read(new file(path1));                     jlabel piclabel = new jlabel(new imageicon( mypicture ));                 }             });         domestic.addactionlistener(new actionlistener() {                 @override                 public void actionperformed(actionevent e) {                     bufferedimage mypicture = imageio.read(new file(path2));                     jlabel piclabel = new jlabel(new imageicon( mypicture ));                 }             }); 

and tried implement it:

jcomponent reservation= makeimagepanel("international_1.gif", "domestic_seating.gif");             overview.addtab ("reserve flight", reservation);             overview.setmnemonicat(1, keyevent.vk_2); 

thanks in advance help!

actionevent has method getsource() give object on event fired. or can set global variable find out button clicked. there many ways it.

regards, ravi


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -