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
Solved

Putting boolean value in permanent state.

Posted on 2011-02-17
4
290 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 120
Java: anonymous class 4 29
Selenium docs api java index 3 48
hashmap order 17 37
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

837 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