java - JRadiobutton ActionListener not responding -


i'm registering events 2 jradiobuttons, nothing happens! no errors thrown, i'm not being able trace problem.. when selecting first radio button, should print out text. when selecting second button, should print out different text....

import java.awt.flowlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener;  import javax.swing.*;   public class num2 extends jframe  {     private static jlabel type;     private static jlabel days;     private static jlabel amt;     private static jradiobutton checkstandard;     private static jradiobutton checkexecutive;     private static jtextfield txtdays;     private static jtextfield txtamount;     private static jbutton btncalculate;     private static buttongroup group = new buttongroup();      public num2(){         super("testing events");         jpanel p = new jpanel();         jlabel type = new jlabel("room type : ");         jlabel days = new jlabel("number of days : ");         jlabel amt = new jlabel("total amount : ");          jradiobutton checkstandard = new jradiobutton("standard");         jradiobutton checkexecutive = new jradiobutton("executive");             p.setlayout(new flowlayout());           group.add(checkstandard);         group.add(checkexecutive);         p.add(checkstandard);         p.add(checkexecutive);         thehandler handler = new thehandler();         checkstandard.addactionlistener(handler);         checkexecutive.addactionlistener(handler);         add(p);          setdefaultcloseoperation(jframe.exit_on_close);         setsize(100, 100);         setvisible(true);      }      public static void main(string[] args) {         num2 app = new num2();       }   private class thehandler implements actionlistener{     public void actionperformed(actionevent evt) {         object source = evt.getsource();         if (source == checkstandard) {             system.out.println("done");          }         else if(source == checkexecutive){             system.out.println("nope");         }  } }    } 

you're shadowing both jradiobutton variables

jradiobutton checkstandard = new jradiobutton("standard"); jradiobutton checkexecutive = new jradiobutton("executive"); 

should be

checkstandard = new jradiobutton("standard"); checkexecutive = new jradiobutton("executive"); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -