Handling user events in Droplets is just like handling them in Java. The first step is importing the Droplets Event package - called com.droplets.api.event.* - into your application logic.
There are four things that your application will need in order to handle button clicks and similar user-initiated events.
This is the object that will listen for button clicks and respond appropriately.
class clicker implements ClickListener{
...
}
This method will define the action that is taken whenever a particular button is clicked.
public void handleClick(ClickEvent e) {
...
}
This is automatically created by the Droplets Platform whenever a button is clicked, so we simply have to include it as an argument to the handleClick() method.
handleClick(ClickEvent e)
Within the class in which you add your components to the GUI window, create an instance of your ClickListener, and then make a call to the button's addClickListener() method with this ClickListener as the parameter.
clicker click = new clicker(getApplication());
button.addClickListener(click);
|