[ Pobierz całość w formacie PDF ]

Factor double weigthy allocated for the component will
not grow beyond the preferred
size.
Anchoring int anchor Where a component should be placed within GridBagConstraints.CENTER
its display area.
Constants defined in GridBagConstraints:
CENTER, NORTH, NORTHEAST, EAST,
SOUTHEAST, SOUTH, SOUTHWEST,
WEST, NORTHWEST
Filling int fill How the component is to stretch and fill its GridBagConstraints.NONE
display area.
Constants defined in GridBagConstraints:
NONE, BOTH, HORIZONTAL, VERTICAL
Padding int ipadx Internal padding added to each side of the 0 pixels in either direction
int ipady component. Dimension of the component will
grow to (width + 2 * ipadx) and (height + 2 *
ipady)
Insets Insets insets External padding (border) around the (0,0,0,0) (top, left, bottom, right)
component.
48
Layout Description Constructors Constants Default For
Manager
FlowLayout Lays out the components FlowLayout() - center aligned, 5 pixels gap LEFT Panel and its
in row-major order. Rows both horizontally and vertically CENTER subclasses
growing from left to right, FlowLayout(int alignment) RIGHT (Applet)
top to bottom. FlowLayout(int alignment, int hgap, int vgap)
GridLayout Lays out the components GridLayout()  equivalent to GridLayout(1,0) N/A None
in a specified rectangular GridLayout(int rows, int columns)
grid, from left to right in
each row and filling rows
from top to bottom.
BorderLayout Up to 5 components can BorderLayout() NORTH Window and
be placed in particular BorderLayout(int hgap, int vgap) SOUTH its subclasses
locations: north, south, EAST (Dialog and
east, west and center. WEST Frame)
CENTER
CardLayout Components are handled CardLayout() N/A None
as a stack of indexed CardLayout(int hgap, int vgap)
cards. Shows only one at
a time.
GridbagLayout Customizable and flexible GridbagLayout() Defined in None
layout manager that lays GridBag
out the components in a Constraints
rectangular grid. class. See
the above
table
49
Chapter 12 Events
" Java 1.0 s original outward rippling event model had shortcomings.
- An event could only be handled by the component that originated the event or one of its
containers.
- No way to disable processing of irrelevant events.
" Java 1.1 introduced new  event delegation model .
- A component may be told which objects should be notified when the component generates a
particular kind of event.
- If a component is not interested in an event type, those events won t be propagated.
" Both models are supported in Java 2, but the old model will eventually disappear. Both models should
not be mixed in a single program. If we do that, the program is most likely to fail.
" Event delegation model s main concepts: Event classes, Event listeners, Explicit event enabling and
Event adapter classes.
Event Classes
" Events are Java objects. All the pertinent information is encapsulated in that object. The super class of
all events is java.util.EventObject.
" This java.util.EventObject class defines a method that returns the object that generated the event:
Object getSource()
" All events related to AWT are in java.awt.event package. AWTEvent is the abstract super class of all
AWT events. This class defines a method that returns the ID of the event. All events define constants
to represent the type of event.
int getID()  returns an int in the form of an integer value that identifies the type of event.
" It is useful to divide the event classes into Semantic events and Low-level events.
" Semantic Events 
These classes are used for high-level semantic events, to represent user interaction with GUI.
ActionEvent, AdjustmentEvent, ItemEvent, TextEvent
Event Class Source Event Types
Button  when clicked ACTION_PERFORMED
List  when doubleclicked
ActionEvent
MenuItem  when clicked
TextField  when Enter key is pressed
AdjustmentEvent Scrollbar  when adjustments are made ADJUSTMENT_VALUE_CHANGED
ITEM_STATE_CHANGED
CheckBox  when selected or deselected
CheckboxMenuItem  same as checkbox
ItemEvent
Choice  when an item is selected or deselected
List - when an item is selected or deselected
TEXT_VALUE_CHANGED
TextField
TextEvent
TextArea
Methods defined in the events to get the information about them.
Event Class Method Description
String getActionCommand Returns the command name associated with this action
int getModifiers Returns the sum of modifier constants corresponding to the keyboard
ActionEvent
modifiers held down during this action.
SHIFT_MASK, ALT_MASK, CTRL_MASK, META_MASK
AdjustmentEvent int getvalue Returns the current value designated by the adjustable component
Object getItem Returns the object that was selected or deselected
Label of the checkbox
ItemEvent
int getStateChange Returned value indicates whether it was a selection or a de-selection
SELECTED that took place, given by the two constants in ItemEvent.
DESELECTED
50
" Low-level Events 
These classes are used to represent low-level input or window operations. Several low-level events can
constitute a single semantic event.
ComponentEvent, ContainerEvent, FocusEvent, KeyEvent, MouseEvent, PaintEvent,
WindowEvent
Event Class Source Event Types
COMPONENT_SHOWN, COMPONENT_HIDDEN,
COMPONENT_MOVED, COMPONENT_RESIZED
ComponentEvent All components
AWT handles this event automatically. Programs should not handle this event.
COMPONENT_ADDED, COMPONENT_REMOVED
ContainerEvent All containers
AWT handles this event automatically. Programs should not handle this event.
FOCUS_GAINED, FOCUS_LOST
FocusEvent All components
Receiving focus means the component will receive all the keystrokes.
This is an abstract class. Parent of KeyEvent and MouseEvent. Constants for
InputEvent All components
key and mouse masks are defined in this class.
KEYPRESSED, KEYRELEASED, KEYTYPED (when a character is typed)
KeyEvent All components
MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_CLICKED,
MouseEvent All components MOUSE_DRAGGED, MOUSE_MOVED, MOUSE_ENTERED,
MOUSE_EXITED
This event occurs when a component should have its paint()/update() methods
invoked. AWT handles this event automatically. Programs should not handle
PaintEvent All components
this event. This event is not supposed to be handled by the event listener model.
Components should override paint/update methods to get rendered.
This event is generated when an important operation is performed on a window.
WINDOW_OPENED, WINDOW_CLOSING, WINDOW_CLOSED,
WindowEvent All windows
WINDOW_ICONIFIED, WINDOW_DEICONIFIED,
WINDOW_ACTIVATED, WINDOW_DEACTIVATED
Methods defined in the events to get the information about them.
Event Class Method Description [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • alwayshope.keep.pl
  •