Creating classes that can reference GUI items

Post Reply
User avatar
AndyMac
Posts: 149
Joined: Wed Sep 05, 2018 6:16 pm
Location: Wirral UK
Contact:

Creating classes that can reference GUI items

Post by AndyMac »

Maybe my lack of detailed understanding of Java coding, or the lack of detailed development documentation, but now I have a way to calculate the BPM from a gate reasonably accurately/reliably (although far from perfect), I was thinking about making it into a class that I can generalise and use across my modules.

In doing so, I have tried to work out how to reference the input jack that I want to be able the class to reference, which will then be called in initialisation (setting the jack to be monitoring), on a named timer (which looks at the signal on the jack), when the jack is connected or disconnected and when the value that is a running calculation is needed. I have tried a couple of things by looking through the code, but can't seem to setup a variable that I can use to reference the jack, check it is an AudioInput jack and use the GetValue and IsConnected methods on.

Any help/pointers on this would be really useful.
User avatar
Captain
Posts: 103
Joined: Sat Aug 25, 2018 11:12 am

Re: Creating classes that can reference GUI items

Post by Captain »

Hmm, I have a feeling I might be able to help you, but I'm not quite 100% sure if I get what you are asking. :) To refer to any GUI object, just use its variable name (that you enter in the properties pane):

jackVariableNameInGUI.GetValue();

Or if you want to create a new reference, it would be something like:

VoltageAudioJack jack = jackVariableNameInGUI;
jack.GetValue();

Or you could even generate a completely new jack from scratch, like the auto-generated GUI code does, but usually this is not necessary.

Dunno if this helps at all, but feel free to elaborate a little more, and I'll do my best to help! Assuming I can do it with my limited skills... :D

EDIT: One more thing occurred to me, helpful or not, but anyways: If you create additional classes and place them in an external .class file, they can't see the GUI objects directly. You'll either have to pass the necessary objects as parameters to the new class, or use inner classes inside the main module (they can access all the same things as the main module).
User avatar
AndyMac
Posts: 149
Joined: Wed Sep 05, 2018 6:16 pm
Location: Wirral UK
Contact:

Re: Creating classes that can reference GUI items

Post by AndyMac »

Thanks - I think I know what I was doing wrong (at least to a point) and will try the...

VoltageAudioJack jack = jackVariableNameInGUI;
jack.GetValue();

Not sure whether this will allow me to pass the name of the jack to a new class, but will have a go next week!
Post Reply

Return to “Module Designer”