Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

button clicked event question

 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 124 in the code is this code buttonExit.setOnAction(e -> ButtonClicked(e)); and then starting at line 183 is the code it should run. It runs the code as the println prints but I can not get the If to work. The editor says it can not find the symbol variable buttonExit. I suspect some type of public or private?

Any help would be appreciated.

Thanks Roger

 
Maneesh Godbole
Saloon Keeper
Posts: 11308
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short answer: Scope of the variable.

Long answer-
Look at your code below:


You defined buttonExit inside addHBox(). Thus the visibility is limited to only inside addHBox(); That's what the editor is trying to tell you.

Solution: Declare buttonExit as a class variable


Recommended reading: https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html
 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it was a scope thing but I still don't understand even after reading the reference.

Can you show me how to do the class variable using the code I have or do I have to rewrite the whole thing?

Rogefr
 
Roger Wells
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Got it working mostly

Thanks
 
Maneesh Godbole
Saloon Keeper
Posts: 11308
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done! 

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic