CSci 2101 Data Structures: Lab 15
The material of this lab is optional. You may work on your problem
set instead. Note that, unless your problem set is already submitted,
you MUST attend the lab.
For this lab use the SecondSwing example that we
used in class, as well as the following APIs:
Problem 1 (and only)
- Write a Swing program that creates a window with one label and
one button. When the button is pressed, the program displays a
randomly selected string (out of a pre-defined array of strings).
- Set a different color background color of the
label (hint: see the
JComponent API above).
- Modify the program so that when the user clicks the button, not
only the string gets changed, but the color of the label
changes as well.
- Add a JTextField
to the application so that the user can enter a word, press "enter",
and the word gets displayed on the label. Note that you would need to
create another Listener class to handle the "enter" event for the text
area (if you add the listener to the JTextField object, the listener
will automatically call the
actionPerformed
method when
the user presses "enter"). See Text
Fields Tutorial for some guidance. If (or, more precisely, when)
you get confused, ask!
This is a lab from CSci 2101 course.