Java Reference
In-Depth Information
3. Within the actionPerformed() method, determine which button was
clicked. If the Send button is clicked, get the text from the text area
and display it using a call to System.out.println(), printing out the
recipient and the message. Then hide the dialog window referred to
by your JDialog field.
4. If the Cancel button is clicked, hide the dialog window.
5. Within the constructor of InstantMessageDialog, instantiate a new
SendMessage object, passing in the JTextArea of InstantMessageDia-
log, the recipient's name, and the this reference as the JDialog
argument.
6. Register your SendMessage object as an ActionListener of the Send
and Cancel buttons.
7.
Save, compile, and run the InstantMessageDemo program.
When you click the Send button, the message should appear at the
command prompt of the window, along with the recipient's name, and
the dialog window should disappear. Clicking the Cancel button should
simply hide the dialog window.
Lab 13.4 Displaying the InstantMessageDialog
In this lab, you will tie together the two classes InstantMessageFrame and
InstantMessageDialog.
1. Modify your DisplayMessageDialog event handler so that when the
user selects a friend from the list in InstantMessageFrame, the
InstantMessageDialog is displayed. Within the mouseClicked()
method, you will need to instantiate an InstantMessageDialog and
display it using the show() method.
2. Save and compile your DisplayMessageDialog class.
3. Run the InstantMessageFrame program.
The appearance of your InstantMessageFrame has not changed; how-
ever, clicking on a friend in the list should cause the InstantMessageDialog
window to appear. Entering a message and clicking the Send button
should display the message at the command prompt and also hide the dia-
log window. Clicking the Cancel button should hide the dialog window.
Search WWH ::




Custom Search