Reminder Application. Stage 2/4

Add some listeners

Report a typo

Description

Now that you have the application window, it is an excellent time to learn how to provide the functionality to those buttons. The buttons in our application cannot do anything when they are clicked.

To make the button come alive, add an action listener to it. An action listener can be added using the addActionListener() method for each button declared in our application. You can use action listeners to handle events, such as what must happen when the end user clicks a button in the application window.

ActionListener is an interface, and addActionListener() allows you to bind the interface to each button.

Once you handle the button click event, you must define what happens when a particular button is clicked. To explain that, you need to implement the logic for the actionPerformed() method, which comes in the ActionListener interface. In this stage, after clicking the button, a new screen must appear on your window with available functionality to set reminders.

If you have a reminder to have a cup of water every four minutes, then your new screen should have a text field to add text It's time to drink some water.

This screen should have two buttons: OK and Cancel. OK confirms and sets a new reminder. Cancel aborts setting the reminder. The buttons in this stage take users back to the original application screen. Do not worry about the reminder timer logic in this stage; just implement the logic of both buttons.

Add two JComboBoxes to the screen to select the timer delay and the period in the following stages.

It is now time to add listeners to your menu options and buttons to make your reminder app do some real work. We recommend writing your project using the MVC pattern starting from this stage.

Objectives

Add addActionListener() to the ADD button with the name Add Reminder . It creates a new screen with the name Set Reminder. The title of this window should be Set Reminder . ADD button should be disabled after pressed.

The window should contain the following components:

  • JTextField with the Field name;

  • JLabel Reminder Text with the Reminder Text Label name. This label should be located over the Field JTextField ;

  • JButton OK with the OK name;

  • JButton Cancel with the Cancel name;

  • JComboBox with the set Period name;

  • JLabel with the Period label name. This label should be located beneath the set Period JComboBox ;

  • JLabel Set Period with the Set Repeat Period Label name. This label should be located over the set Period JComboBox ;

  • JComboBox with the set Delay name;

  • JLabel Set Delay with the Set Delay Label name. This label should be located over set Delay JComboBox ;

  • JLabel with the Delays Label name. This label should be located beneath the set Delay JComboBox .

Figures in the Set Delay comboBox and period Delay comboBox should follow this order:

For set delay – 30, 25, 15, 5;
For set Period – 0, 5, 10, 20;

This order will be used for testing purposes of your application.

Examples

Application Interface (two windows are visible)

Clicking on the OK or Cancel buttons close the Set Reminder window; only the Reminder application window is visible:

Application interface (only one window is visible)

Application Interface  (Set Reminder window)

Application Interface

Write a program
IDE integration
Checking the IDE status
___

Create a free account to access the full topic