We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have been thinking to write my own custom event listener like mousePressed or keyPressed in java. I have seen similar events in androids too where when an acitivity loads it goes through a cycle such as onCreate, onCreateView, onStart, onPause, onResume, onStop etc. these are the methods are independent of main and act when these events fire.
In processing, mousePressed, keyPressed etc. are independent of main method [draw & setup] and fires only when any key is pressed or mouse is pressed or moved. My question is can I write something my own methods which will be independent of main function but it will trigger when event gets fired.
For example - I would like to write a serial port listener method or headphone attached method for processing so that programmer don't need to write them in setup and they just need to call once like mousePressed and it will do the work. Ofcouse these are just example and it can be done for something else for example if my Arraylist is exceeding over some size it would automatically start emptying itself without any method which can trigger to some other event such as add new objects in the arraylist. Please take these as example. Of couse I might not need custom event listener to do this but I would still like to know how and where to start.
I have been doing my research and stumble upon observer pattern in java but I couldn't get my head around it. I feel I need something simple which is understandable by beginners too.