-1

enter image description here

in A class when i click a button and that button returns the true or false . if true returned then Next Tab of JTabbedPane is enabled ,which is written in another class. It may Sound stupid but I've tried a lot. and it is continously giving Null Pointer exception. Here's my 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 the Accessing Personal Details in a 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 you want to 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;
        }   
}   
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Napster
  • 1
  • 4

1 Answers1

1

You've got a lot of significant problems with that code including:

  • You're testing the value of cooat at GUI creation, before the user has had any chance to interact with the program and possibly change its state. And so cooat will == 0 when you test it (which is the value of JOptionPane.YES_OPTION).
  • You're assuming that a button's action performed method can return something -- but it can't since it's a void method.
  • A minor problem, but I see that you're using null layouts and setBounds(..). While null layouts and setBounds() might seem to Swing newbies like the easiest and best way to create complex GUI's, the more Swing GUI'S you create the more serious difficulties you will run into when using them. They won't resize your components when the GUI resizes, they are a royal witch to enhance or maintain, they fail completely when placed in scrollpanes, they look gawd-awful when viewed on all platforms or screen resolutions that are different from the original one.
  • You've got a NullPointerException being thrown somewhere and are asking for help on this, but are not giving us near enough information to allow us to help you. If you've done a little searching on solving a NullPointerException (NPE), then you'll know that the most important bit of information that we need is the exception's associated stacktrace and some identification of the exact line that causes it, something that the stacktrace will tell you. Please post this information so that we can help you.
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373