Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Variable from other class not being changed correctly

$
0
0
In my class 'booleanArgs' I'm trying to make methods to set the resource = true so that a hex will display a resource picture based on a random number. Here is the method

 public void setHousePlaced(boolean placed) {
        placed = true;
        field.housePlaced = placed; 
    }



I also have a getHousePlaced method in the same class.

 public boolean getHousePlaced() {
        System.out.println("House placed: " + housePlaced);
        return housePlaced;
    }




This is inside my main class 'playingField'

 private void jLabel36MouseEntered(java.awt.event.MouseEvent evt) {                                      
        booleanArgs args = new booleanArgs();
        args.setResources(resource1Amount, resource2Amount, resource3Amount);
        
        if (args.getResources() == false) {
            jLabel36.setIcon(new ImageIcon("src/hexHouseRedFull.png"));
        }
        if (args.getResources() == true) {
            jLabel36.setIcon(new ImageIcon("src/hexHouseGreen.png"));
        }
        if(args.getHousePlaced() == true)
        {
            jLabel36.setIcon(new ImageIcon("src/hexHouseRedFull.png"));
        }
     }



Basically it won't recognize that I have set the variable to true.The SOP keeps reading as false;

Any help would be appreciated.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>