java - Switch the tab of a tJabbedpane on a click of button in different class? -


enter image description here

in class when click button , button returns true or false . if true returned next tab of jtabbedpane enabled ,which written in class. may sound stupid i've tried lot. , continously giving null pointer exception. here's code..

public class stepsforapply extends jpanel {      public jtabbedpane tab = new jtabbedpane();     personaldetails pd = new personaldetails();     int ch =1;     int a[]={0,1,2,3,4,5};     public stepsforapply()     {         setlayout(null);         setbounds(100, 100, 660, 300);         tab.add("sourcing",new  jpanel());         tab.add("personal details",pd);         tab.add("income details",new jpanel());         tab.add("education details", new jpanel());         tab.add("liability details",new jpanel());         tab.add("experence details", new jpanel());         tab.setbounds(0,0,700,300);         add(tab);         //disableall(1);         for(int i=2;i<=a.length-1;i++)         {         tab.setenabledat(i, false);         }           if(pd.check()==true)         {             tab.setenabledat(2,true);         }         setvisible(true);      } } 

here 's accessing personal details in tab

public class personaldetails extends jpanel {      int response,response1;     int cooat;     private jtextfield votertxt;     public boolean checkstatus = false;     public personaldetails()     {         setlayout(null);         jbutton btnsave = new jbutton("save");         btnsave.setbounds(29, 173, 89, 23);         add(btnsave);          votertxt = new jtextfield();         votertxt.setbounds(137, 67, 86, 20);         add(votertxt);         votertxt.setcolumns(10);          jlabel lblvoteridno = new jlabel("voterid no.");         lblvoteridno.setbounds(29, 70, 94, 14);         add(lblvoteridno);         btnsave.addactionlistener(new actionlistener() {              @override             public void actionperformed(actionevent e) {             cooat = joptionpane.showconfirmdialog(null, "do want continue?", "confirm",                          joptionpane.yes_no_option, joptionpane.question_message);                        personaldetails.this.check();              }         });       }         '         public boolean check()         {             if (cooat == joptionpane.no_option) {                  votertxt.requestfocus();                 }             else                  if(cooat==joptionpane.yes_option)                 {                      checkstatus = true;                     return checkstatus;                 }            return checkstatus;         }    }    

you've got lot of significant problems code including:

  • you're testing value of cooat @ gui creation, before user has had chance interact program , possibly change state. , cooat == 0 when test (which value of joptionpane.yes_option).
  • you're assuming button's action performed method can return -- can't since it's void method.
  • a minor problem, see you're using null layouts , setbounds(..). while null layouts , setbounds() might seem swing newbies easiest , best way create complex gui's, more swing gui's create more serious difficulties run when using them. won't resize components when gui resizes, royal witch enhance or maintain, fail when placed in scrollpanes, gawd-awful when viewed on platforms or screen resolutions different original one.
  • you've got nullpointerexception being thrown somewhere , asking on this, not giving near enough information allow you. if you've done little searching on solving nullpointerexception (npe), you'll know important bit of information need exception's associated stacktrace , identification of exact line causes it, stacktrace tell you. please post information can you.

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -