$29
CS2050 Programming Assignment #2 - Playing with GUIs
The Assignment
Implement a Graphical User Interface (GUI) in Java that does the following:
1.
Put a JTextField in the north of the JFrame along with a
JLabel that says: Year
2.
Put a JSlider, vertically in the east side of the JFrame
1. Have the JSlider range from 1990 to 2019
2. Have the JSlider labeled Choose Year
3. Add a *ChangeListener* to the JSlider
4. Have the JSlider's value displayed in the TextField
Hints
1. to get the JSlider to be vertical, make the JSlider's
orientation JSlider.VERTICAL.
2. label the JSlider
1. tell the JSlider to set the tick
spacing:setMajorTickSpacing(4), and setMinorTickSpacing(2)
2. tell the JSlider to make the tick marks show up:
setPaintTicks(true)
3. tell the JSlider to make the labels show up use
setPaintLabels(true)
3. for the changeListener to work, the class has to implement the
*ChangeListener* interface. If the class implements more than
one interface, they should be noted in a comma seperated list.
4. the changeListener has to have a *stateChanged* method which
takes a *ChangeEvent* object as an argument.
5. The int returned by the slider can be converted to a string by
concatenating it with the empty String as in: "" + value
3.
Have typing in the TextField change the JSlider.
Hints
1. The value from the TextField is obtained as a String. To get an
int use Integer.parseInt()
4.
Add JRadioButtons with labels that are color names
1. Group the JRadioButtons into a ButtonGroup
2. Hook your JRadioButtons to your program (use
addActionListener()) so that the JFrame's background color is
changed to the color chosen with the JRadioButton
Hints
1. The ButtonGroup just coordinates the buttons so, when one is
pressed, the others turn off.
2. Use setBackground() to set the JFrame's color. If setting the
JFrame's color doesn't work for you, try setting the background
color of each of the JPanels you have.
Due Date
Turn in your program to me by the start of class on Wednesday,
2019.09.11. Don't miss class to work on your program.