Component |
Description |
Constructors |
Events |
Button |
A button with a textual label. |
new Button("Apply") |
Action event. |
Canvas |
- No default appearance.
- Can be sub-classed to create custom drawing
areas.
|
|
Mouse, MouseMotion, Key events. |
Checkbox |
- Toggling check box.
- Default initial state is false.
- getState(), setState(boolean state) - methods
- Can be grouped with a CheckboxGroup to provide
radio behavior.
- Checkboxgroup is not a subclass of Component.
- Checkboxgroup provides these methods: getSelectedCheckbox
and setSelectedCheckbox(Checkbox new)
|
Checkbox(String label) Checkbox(String label,
boolean initialstate) Checkbox(String label, CheckBoxGroup
group) |
Item event |
Choice |
- A pull-down list
- Can be populated by repeatedly calling addItem(String
item) method.
- Only the current choice is visible.
|
|
Item event |
FileDialog |
- Subclass of Dialog
- Open or Save file dialog, modal
- Dialog automatically removed, after user
selects the file or hits cancel.
- getFile(), getDirectory() methods can be
used to get information about the selected file.
|
FileDialog(Frame parent, String title, int mode)
Mode can be FileDialog.LOAD or FileDialog.SAVE |
|
Label |
- Displays a single line of read-only non-selectable
text
- Alignment can be Label.LEFT, Label.RIGHT
or Label.CENTER
|
Label() Label(String label) Label(String label,
int align) |
None |
List |
- Scrollable vertical list of text items.
- No of visible rows can be specified, if
not specified layout manager determines this.
- Acquires a vertical scrollbar if needed.
- List class methods:
- addItem(String), addItem(String, int index)
- getItem(int index), getItemCount()
- getRows() - no of visible rows
- int getSelectedIndex()
- int[] getSelectedIndexes()
- String getSelectedItem()
- String[] getSelectedItems()
|
List() List(int nVisibleRows) List(int nVisibleRows,
boolean multiSelectOK) |
Item event - selecting or deselecting Action
event - double clicking |
Scrollbar |
With the last form of constructor, calculate
the spread as maxvalue - minvalue. Then the slider
width is slidersize / spread times of scrollbar
width. |
Scrollbar() - a vertical scrollbar. Scrollbar(int
orientation) Scrollbar(int orientation, int initialvalue,
int slidersize, int minvalue, int maxvalue) Orientation
can be Scrollbar.HORIZONTAL Scrollbar.VERTICAL |
Adjustment event |
TextField |
- Extends TextComponent
- Single line of edit / display of text.
- Scrolled using arrow keys.
- Depending on the font, number of displayable
characters can vary.
- But, never changes size once created.
- Methods from TextComponent:
- String getSelectedText()
- String getText()
- void setEditable(boolean editable)
- void setText(String text)
|
TextField() - empty field TextField(int ncols)
- size TextField(String text) - initial text TextField(String
text, int ncols) - initial text and size |
Text event Action event - Enter key is pressed. |
TextArea |
- Extends TextComponent
- Multiple lines of edit/display of text.
- Scrolled using arrow keys.
- Can use the TextComponent methods specified
above.
- Scroll parameter in last constructor form
could be
- TextArea.SCROLLBARS_BOTH,
- TextArea.SCROLLBARS_NONE,
- TextArea.SCROLLBARS_HORIZONTAL_ONLY
- TextArea.SCROLLBARS_VERTICAL_ONLY
|
TextArea() - empty area TextArea(int nrows,
int ncols) - size TextArea(String text) - initial
text TextArea(String text, int nrows, int ncols)
- initial text and size TextArea(String text, int
nrows, int ncols, int scroll) |
Text event |