2
Contributors
16
Replies
17
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

well ,

I declared below in coursebookie package ..

public class GlobalVariables {
 public static enum BetfairStatus{NOT_CONNECTED, CONNECTED};
}

and i want to access in

import coursebookie.presentation.BookiesFrame;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import coursebookie.GlobalVariables.BetfairStatus;
import coursebookie.GlobalVariables;

import coursebookie.*;



/**
 *
 * @author Dale
 */
public class BetfairLogoutAction extends AbstractAction{

    public BetfairLogoutAction(String text, String desc) {
        super(text);
        putValue(SHORT_DESCRIPTION, desc);
    }

    public BetfairLogoutAction(String text, String desc, Integer mnemonic) {
        super(text);
        putValue(SHORT_DESCRIPTION, desc);
        putValue(MNEMONIC_KEY, mnemonic);
    }



    public void actionPerformed(ActionEvent e)
    {



        if (GlobalVariables.BetfairStatus = CONNECTED)
        {


}

if (GlobalVariables.BetfairStatus = NOT_CONNECTED) {
   JOptionPane.showMessageDialog(null,"logged out of betfair" );

}

    }
}

but it says error at

GlobalVariables.BetfairStatus  that BetfairStatus is not delcared 

please help me out..
i think i declared public and all...

Edited by Nick Evan: Fixed formatting

0

You are trying to use the enum as if it is a variable. Your code should look more like this...


BetfairStatus status = ...
if (status == BetfairStatus.CONNECTED) ...

0

BetfairStatus status = ...
if (status == BetfairStatus.CONNECTED) ...


should i make object of BetfairStatus enum ...but it cannot be instatiated...error comes what to use after
BetfairStatus status = what i can write here

0

I really don't approve of global variables. IMHO you should always make variables private and use get/set methods. But if that's the way you want to do it...
In your globals you need the enum to define the possible values, plus another global variable that holds the current value:

public static enum BetfairStatus{NOT_CONNECTED, CONNECTED};
public static BetfairStatus status;

then, in the other modules:

GlobalVariables.status = BetfairStatus.CONNECTED;
or
if (GlobalVariables.status == BetfairStatus.CONNECTED) ...
0
//logoutActions
       logout.addActionListener(new ActionListener()
     {
public void actionPerformed(ActionEvent e)
    {
       if (GlobalVariables.status == BetfairStatus.CONNECTED)
       {
           //try{
             // GlobalAPI.logout(null);}
           //catch(Exception k)
           //{}
              GlobalVariables.status = BetfairStatus.NOT_CONNECTED;
       }


       else if(GlobalVariables.status == BetfairStatus.NOT_CONNECTED)
       {
           JOptionPane.showMessageDialog(null, "You are not logged in to betfair");
       }
}
     });

I am applying this to logout Jmenuitem ..nothing Action is happening ..

why..

Edited by Nick Evan: Fixed formatting

0

it is not going in any if statement...I am not getting any error in any of if statements ..but when i print outside if statement it prints...

0
public void actionPerformed(ActionEvent e)
    {

System.out.println(GlobalVariables.BetfairStatus.CONNECTED);

        if(GlobalVariables.status == BetfairStatus.NOT_CONNECTED)
       {
System.out.println("hi to all");
  JOptionPane.showMessageDialog(null, "You are not logged in to betfair");
    }
    }

i did above and it is printing connected..

Edited by Nick Evan: Fixed formatting

0

did i need to intialise..

public static enum BetfairStatus{NOT_CONNECTED, CONNECTED};
this ..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.