Java Reference
In-Depth Information
4. Save and compile your IMHandler class.
5. Within your InstantMessageFrame constructor, instantiate a new
IMHandler, passing in the JList and JTextField of the InstantMes-
sageFrame.
6. Register your IMHandler object with the text field and the Send
button.
7. Write a class named DisplayMessageDialog that extends the Mouse-
Adapter class. This class does not need any fields or constructors.
8. Add the mouseClicked() method to DisplayMessageDialog. Use the
getClickCount() method of MouseEvent to determine if the user
double-clicked the mouse. If yes, print out the item double-clicked,
which will be the name of the person that the instant message is
intended for.
9. Within your InstantMessageFrame constructor, instantiate a new
DisplayMessageDialog object, and register it as a listener to the
JList.
10. Add a collection of Strings to the JList. These will represent the
screen names of your friends who are currently online and awaiting
an instant message.
11.
Save, compile, and run your InstantMessageFrame program.
When you type something in the text field and click the Send button,
the message should appear at the command prompt of the window along
with the names of each friend. If you click on a friend in the list, the name
of the friend should be displayed at the command prompt.
Lab 13.3: The InstantMessageDialog Events
This lab is a continuation of Lab 12.4. You will add some event handling
to your InstantMessageDialog.
1. Write a class named SendMessage that implements ActionListener.
This class will handle the events from the Send and Cancel buttons
of your InstantMessageDialog.
2. Add a field of type JTextArea which will contain the message to
send, a String to represent the recipient of the message, and JDialog
to represent dialog window. Add a constructor that initializes these
three fields.
Search WWH ::




Custom Search