Basically, you can split your code into two function, one function will going to set up the user interface, and then two function will act as a callback that will return the use clicks the button.
I hope this will help.
Want to become a Java Expert? Join Java Certification now!!
Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Programming: