
JLabels are the simplest Swing components.
See the code.
See the code.
JTextField is a short, one-line piece of
editable text.
See the code.
JScrollPane is a container that is able to
scroll the component it contains.
See the code.
JViewport)
onto its contained component.
|
|
Scrollable interface.
|
|
|
The model implements the changes interface.
The view implements the state interface.
The controller implements the events interface.
|
|
|


JRadioButton provides one-of-several
selections.
See the code.
ButtonGroup enforces the one-of-many rule.
JComboBox also provides one-of-several
selections.
See the code.

JSlider.getModel(): return a slider's minimum, maximum, and current value.
ButtonGroup.getSelected(): return a radio-button group's selected button.
JTextField.getText(): return a text field's displayed text.
When should an application call a component's query method?
ActionListener interface defines
notification-receiving behavior.
ActionListener.
TextAction, for example
void actionPerformed(ActionEvent e)
call-back method.
ActionEvent argument provides
information about the event:
String getActionCommand() int getModifiers() long getWhen() String paramString()
See the code.
See the code.
slider.addChangeListener(
new ChangeListener() {
public void
stateChanged(ChangeEvent e) {
JSlider slider =
(JSlider) e.getSource();
stateLabel.setText(
stateNames[slider.getValue()]);
}
});