JavaFX Pass information to EventHandler

Halasham

n00b
Joined
Jul 21, 2019
Messages
19
Hello, I'm writing a digital character sheet program for the Cogent TTRPG system as my friends and I are going to try playing a campaign with it.
I have the program just about working using Java and JavaFX I'm just missing one thing to bring it all together: any means by which to send a variable to an EventHandler method.

I am configuring the system so that attribute and skill ranks are incremented and decremented via JavaFX Button to try and make the system as simple and user-friendly for my friends as possible.
While explaining the problem to one of my, non-programmer, friends they wrote this this and it is a fair description of what I'm trying to accomplish https://docs.google.com/document/d/1ftLZ6r_cLtY3Z2ptZW4rg-bD3_cQN5ww8Fn1dIWH7rs/edit?usp=drivesdk

For a more technical description in the underlying class I have arranged the variables that make up the Attributes and Skills into separate arrays and would like to be able to associate an int with each location the increment and decrement buttons show up so that I can tell it to perform the increment or decrement operations on the xth position of the array.

I tried scrounging through StackOverflow for answers and got the vague direction of using .setTag(var) and getTag with insufficient context for how either work and poor luck in looking up those methods else-ware.

Forgot to mention: Any other means of getting around writing separate incriminater and decrementor buttons for every Attribute and Skill while providing that kind of functionality would work.
I just want a program simple enough I can send it to my friends and they'll probably be able to use it with little to no instruction.
 
Last edited:
Structurally I can see why you would opt for an array and then imply array index maps to some UI object, but that's a bit more tightly bound than I would normally go for. Sure it's a PITA to have 12 individually named variables holding their values, but that removes the ambiguity in the implied relationship between array index to UI.

It may do well to refactor and specify those out directly. Lord knows I've been bit on the bottom a few times over for forgetting about implied structures like that.

.. but doubting that advice will be taken, here's an overflow example of creating FXML event handlers that call a single function with a given numeric input that would do what you are asking.

https://stackoverflow.com/questions/37902660/javafx-button-sending-arguments-to-actionevent-function
 
any means by which to send a variable to an EventHandler method.
Maybe your event will have a source, maybe it look similar to this:

https://stackoverflow.com/questions/35676519/actionevent-get-source-of-button-javafx

I.e, all the incriminater and decrementor buttons for every Attribute and Skill point to the same event function and _myNewEven.getSource() will be used to determine which attribute-skill just got changed.

has long has each buttons have an id variable you tracked to recognize which one it was.
 
Maybe your event will have a source, maybe it look similar to this:

https://stackoverflow.com/questions/35676519/actionevent-get-source-of-button-javafx

I.e, all the incriminater and decrementor buttons for every Attribute and Skill point to the same event function and _myNewEven.getSource() will be used to determine which attribute-skill just got changed.

has long has each buttons have an id variable you tracked to recognize which one it was.
Thank you. I can't get .getId() working no matter what I do but with .setId() .getSource() provides a useful String I can structure by button methods to use.
 
Back
Top