• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two classes, setting variable of one from the other doesnt seem to be happening

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two classes, updateAll and addAll.

In the updateAll class I have a boolean variable called enabled as well as a method that only executes if enabled is set to true.



So in my addAll class I have a method that I call in various ways. If this method addAll method gets called, I want it to set the enabled variable from the updateAll class to true, so other event further down the line will see enabled as true and that method will execute.

So in the addAll class I figured this would do the trick:



However when everything is said and done, the enabled variable doesnt seem to be getting changed, or if it is, it doesnt stay that way, because every time I get the else output: enabled is false

This is all done at once by pressing a submit button. There are various method calls but this seems to be a basic java problem. Can someone tell me why this enabled variable isnt being evaluated as true?


edit - I also tried to put a method in my updateAll class that just set enabled to true:

public void changeEnabled(){
enabled=true;
}

and then instead of updateAll.setEnabled(true); I try updateAll.changeEnabled();
This of course doesnt work either.

of course I could just move the methods from my addAll class into my updateAll class, and it will work just fine, but these are two very big classes already and combining them does not seem very desirable
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eh I figured out a different way to handle this.

Id still like to know how to solve my problem though, I run ito it a lot and I know it is a basic java concept that I have forgotten or never learned.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're creating a completely new UpdateAll instance that will be enabled. The original UpdateAll instance is not modified. You'll need a reference to that instance to be able to update it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic