Solved

Putting boolean value in permanent state.

Posted on 2011-02-17
4
285 Views
Last Modified: 2012-05-11
I have JToggleButton which change value of boolean flag0s and set it for another class DecisionCenter (DC).
In the same time this class get value of another boolean bl0 from the third class BusinessLogic (BL) and when this variable come to DC flag0s start to be false again.
Please advice how to protect value of flag0s from any changes apart of command from ToggleButton.
Thank you.
private void jToggleButton1_mouseClicked(MouseEvent e) throws Exception {

        AbstractButton abstractButton = (AbstractButton) e.getSource();
        boolean flag0s = abstractButton.getModel().isSelected();
        dc_EURUSD_S = new DecisionCenter_EURUSD_S(flag0s).getInstance(flag0s);

        System.out.println("Action - flaf0s = " + flag0s + "\n");
        
        if (flag0s == true) {
            jToggleButton1.setBackground(Color.green);

        } else {            
            jToggleButton1.setBackground(Color.red);
        }
    }

Open in new window

public class DecisionCenter_EURUSD_S {

    private static DecisionCenter_EURUSD_S dc_EURUSD_S;
    ISide side;
    boolean flag0s;

    public DecisionCenter_EURUSD_S(boolean flag0s) {

    }

    public static DecisionCenter_EURUSD_S getInstance(boolean flag0s) {
        
        if (flag0s == true)
        {
            System.out.println("$$$$$$$$  flag0s   " + flag0s);
            dc_EURUSD_S = new DecisionCenter_EURUSD_S(flag0s);
        }
        return dc_EURUSD_S;
    }

    public void decisionCenter_EURUSD_S(boolean bl0) throws Exception {

        System.out.println("  bl0   " + bl0);
        System.out.println(" &&&&&&&  flag0s   " + flag0s);

        try {

            if (bl0 == false && flag0s == true
                side = SideFactory.SELL;
            System.out.println("    side  " + side);
            AlgoTradeMarket_EURUSD.getInstance(null).algoTradeMarket(side);
        } catch (Exception ex) {
            Logger.getLogger(BusinessLogic_EURUSD.class.getName()).log(Level.SEVERE,
                                                                       null,
                                                                       ex);
        }
    }
}

Open in new window

public class BusinessLogic_EURUSD {

    boolean bl0;
    boolean flag0s;
    boolean flag0b;


    public BusinessLogic_EURUSD() throws Exception {
    }

    public void businessLogic_EURUSD(double[] outY0) throws Exception {

        if (outY0 != null) {
            try {
               if (outY0[0] < 0 && outY0[1] < 0 && outY0[2] < 0 &&
                    outY0[3] < 0 && outY0[4] < 0 && outY0[5] < 0) {

                    bl0 = false;

                    System.out.println("   bl0 = " + bl0 + "\n");

                    DecisionCenter_EURUSD_S.getInstance(flag0s).decisionCenter_EURUSD_S(bl0);

Open in new window

// Initial output after pressing button

$$$$$$$$  flag0s   true  // from DecisionCenter
Action - flaf0s = true   // from BusinessLogicControl

// Output after sending value bl0 = false to DecisionCenter

 bl0 = false //from BusinessLogic

  bl0   false            // from DecisionCenter
 &&&&&&&  flag0s   false //
    side  null           //

Open in new window

0
Comment
Question by:gbcbr
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 34917127
>>Please advice how to protect value of flag0s from any changes apart of command from ToggleButton.

Unless that listener method is being used for something other than just that toggle button, that's impossible (the boolean variable is local to the method)
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34917161
You just create anothe bololean myFlag and assign:

boolean myFlag = flag0;

No matter waht happens with flag0 afterward myFlag will always keep its value (and thus original value of flag0)
until you change myFlag yourself
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34917289
>>You just create anothe bololean myFlag and assign: ....


Where would you do that (which line number)?
0
 

Author Comment

by:gbcbr
ID: 34917417
It works! Thank you
public static DecisionCenter_EURUSD_S getInstance(boolean flag0s) {
        
        if (flag0s == true)
        {
            System.out.println("$$$$$$$$  flag0s   " + flag0s);
            dc_EURUSD_S = new DecisionCenter_EURUSD_S(flag0s);
            mflag0s = flag0s;
        }
        return dc_EURUSD_S;
    }

    public void decisionCenter_EURUSD_S(boolean bl0) throws Exception {

        System.out.println("  bl0   " + bl0);
        System.out.println(" &&&&&&&  flag0s   " + flag0s);
        System.out.println(" ^^^^^^^  mflag0s   " + mflag0s);

        try {

            if (bl0 == false && mflag0s == true)

                side = SideFactory.SELL;
            System.out.println("    side  " + side);

Open in new window

bl0 = false

  bl0   false
 &&&&&&&  flag0s   false
 ^^^^^^^  mflag0s   true
    side  SideFactory:Sell (2)

    EUR/USD  
    Margin use = 0.4857042663291346%
 Thu Feb 17 18:07:40 EET 2011

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now