?
Solved

Putting boolean value in permanent state.

Posted on 2011-02-17
4
Medium Priority
?
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
A solution for Fortify Path Manipulation.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

800 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