I have a Processing class, called Button, which has the following function onClick:
class Button() {
// Extra code
void onClick() {
// Run function here
}
}
which is supposed to trigger a function call when the button is clicked, and the function is taken in from an argument, like so:
Button test = new Button(..., callFunction())
Where callFunction() is guaranteed to be a void function. How do I call the function callFunction() once test is clicked on? I can check if the button is clicked, but I have no idea how to wire that to a function call provided by an argument.
Use Runnable.
Button test = new Button(..., new Runnable(){
public void run() {
// your stuff.
callFunction();
}
});
Then:
class Button() {
private Runnable runnable;
public Button (... Runnable runnable ){
this.runnable = runnable;
}
// Extra code
void onClick() {
runnable.start();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With