GUI
GUI 3 - More Widgets
- JSpinner - Model
- JSlider
- StateChanged
Read D&D 12, 22
Classwork
Set up a JFrame using NetBeans' editor.
Add a JSpinner, a JSlider, and a JButton.
Set the JSpinner's Model type to Number with min 0 and max 100, and start at 50.
Set the JSlider's minimum and maximum also to 0 and 100. (These
are probably the defaults.)
Set the text on the button to
"Reset".
In the source for the GUI class, create an int instance variable currentVal which
starts at 50.
Add a JLabel showing currentVal's value.
When the JButton is clicked, set the value of the
Spinner and the slider and currentVal all back to 50, and update the
JLabel to match.
Whenever the spinner or slider changes value (StateChanged) update the
other widget's value, and currentVal, to match, and update the label.
OR -- Alternative
Set up a JFrame using NetBeans' editor.
In the Conditionals classwork you created a class Taxpayer. Add any group
member's Taxpayer class to your project (you can download the zipped
project from Blackboard). (You may write a new Taxpayer class if you
want to.)
Using appropriate widgets (you may use ones not covered in class, if
you wish), set up a GUI allowing
the user to set age, marital status, veteran status, and income for a
TaxPayer instance variable in the GUI class.
In JLabels, the user should see the amount of money they are paying tax
on (that is, after taking out exemptions), the amount of tax they pay,
and their remaining take-home income based on changes to the settings.
- all calculations and storage of data should be done by a
Taxpayer object, not replicated in the GUI
- you may make changes to Taxpayer to provide methods
that make your life easier, but Taxpayer should not know about the
GUI.
- use extra JLabels so that each
widget is clearly marked. Do not make me guess which widget
goes with which value.
- any change to any widget should cause immediate updates (e.g..
user should not have to click a button after changing income to see
the new tax value)