Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Putting boolean value in permanent state.

Posted on 2011-02-17
4
Medium Priority
?
315 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:
Suggested Courses

636 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