Error Importing Boolean Variables

advertisements

I have two classes , one called AdminMenu class where variable VoteCycle is a boolean variable that enables a voter to vote provided that the VoteCycle is enabled and another class called LogInMenu where I would like to utilize it.

I'm doing this for my school project.

The problem I have is that even if I select enable which is meant to change the boolean value to true , I'm still getting the false output.. If you don't understand what I mean, my code below should explain it.

Its very basic programming.

The Class

 public class AdminMenu extends javax.swing.JFrame {
    public boolean VoteCycle;

The method

private void VoteComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
if(vCycle.getSelectedItem().toString().equalsIgnoreCase("True"))
{
VoteCycle=true;
}
else if(vCycle.getSelectedItem().toString().equalsIgnoreCase("False"))
{
VoteCycle=false;
}
}

This is the class where I would like to use the variable to allow users to log in. The class is called LogInMenu(). At the start of the class I created an object of the class where the variable was defined in using

AdminMenu AdminMenu=new AdminMenu();
DataValidation validate=new DataValidation();
ConnectDB db=new ConnectDB();

I will just post the relevant code for this class:

private void EnterBtnActionPerformed(java.awt.event.ActionEvent evt) {
if(AdminMenu.VoteCycle)
{
     String Voter=voter.getText();

     boolean detail = false;

    if (validate.Verify(Voter))// Validates Data
    {
        try
        {
            detail = db.VoterLogIn(Voter);
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
        if (detail)
        {
            new VoterMenu().setVisible(true);
            this.dispose();
        }
        else
        {
            JOptionPane.showMessageDialog(null, "The Username or Password entered is incorrect");// error message
        }
    }
}
else
{
JOptionPane.showMessageDialog(null, "Voting is currently disabled", "Error",     JOptionPane.ERROR_MESSAGE);
}

Even after selecting the combo box option to enabled, I return to the LogInMenu class and if i attempt to login I receive the "Voting is currently disabled" error.

I would really appreciate any help offered , Thank you!

P.S : I'm unsure how to use a toggle button and allow its state to be kept when logging into the administrators menu or just how to use the toggle button at all.

So instead i'm using a combox box to set my variables values.


The problem I have is that even if I select enable which is meant to change the boolean value to true , I'm still getting the false output..

Because, the elements of your JComboBox vCycle are { "Disabled", "Enabled", " " } whereas, you are checking the selectedItem for true and false. You should compare the selected value of vCycle for Diabled or Enabled instead of true and false.

if(vCycle.getSelectedItem().toString().equalsIgnoreCase("Disabled"))
{
VoteCycle=true;
}
else if(vCycle.getSelectedItem().toString().equalsIgnoreCase("Enabled"))
{
VoteCycle=false;
}
}