Do it! Button

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

With some programming effort, it would work. The listener would have to check that both text fields had valid data before doing anything. This might be awkward.

Do it! Button

Fat Calculator GUI

 

Both values are needed before the application code can be started. You could write the event listener to check that there is data in both fields before it calls the application method. However, let us take a different approach. The user enters data into the text fields and then clicks to perform the calculation.

Action events from the text fields are ignored. The listener receives only events from the button.

QUESTION 12:

Which of the components needs to register a listener?