Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

AhmadLang / Java, How To Program, 2004

.pdf
Скачиваний:
630
Добавлен:
31.05.2015
Размер:
51.82 Mб
Скачать

When the user clicks an item in a JList, a ListSelectionEvent occurs. JList method addListSelectionListener registers a ListSelectionListener for a JList's selection events. A ListSelectionListener (package javax.swing.event) must implement method valueChanged.

JList method setVisibleRowCount specifies the number of items that are visible in the list.

JList method setSelectionMode specifies a list's selection mode.

A JList does not provide a scrollbar if there are more items in the list than the number of visible rows. In this case, a JScrollPane object can be used to provide the scrolling capability.

JFrame method getContentPane returns a reference to the JFrame's content pane where GUI components are displayed.

JList method getSelectedIndex returns the selected item's index.

A multiple-selection list enables the user to select many items from a JList.

JList method setFixedCellWidth sets a JList's width. Method setFixedCellHeight sets the height of each item in a JList.

There are no events to indicate that a user has made multiple selections in a multiple-selection

list. Normally, an external event generated by another GUI component specifies when the multiple selections in a JList should be processed.

JList method setListData sets the items displayed in a JList. JList method getSelectedValues returns an array of Objects representing the selected items in a JList.

The MouseListener and MouseMotionListener event-listener interfaces are used to handle mouse events. Mouse events can be trapped for any GUI component that extends Component.

Interface MouseInputListener (package javax.swing.event) extends interfaces MouseListener and MouseMotionListener to create a single interface containing all their methods.

Each of the mouse event-handling methods takes a MouseEvent object as its argument. A

MouseEvent object contains information about the mouse event that occurred, including the x- and y-coordinates of the location where the event occurred. These coordinates are measured from the upper-left corner of the GUI component on which the event occurred.

The methods and constants of class InputEvent (MouseEvent's superclass) enable an application to determine which mouse button the user clicked.

Interface MouseWheelListener enables applications to respond to the rotation of a mouse wheel.

GUI components inherit methods addMouseListener and addMouseMotionListener from class

Component.

Many event-listener interfaces contain multiple methods. For many of these interfaces, packages

java.awt.event and javax.swing.event provide event-listener adapter classes. An adapter class implements an interface and provides a default implementation of each method in the interface. You can extend an adapter class to inherit the default implementation of every method and subsequently override only the method(s) you need for event handling.

MouseEvent method getClickCount returns the number of mouse button clicks. Methods isMetaDown and isAltDown determine which mouse button the user clicked.

Lightweight Swing components that extend class JComponent contain method paintComponent,

which is called when a lightweight Swing component is displayed. By overriding this method, you can specify how to draw shapes using Java's graphics capabilities.

When customizing a JPanel for use as a dedicated drawing area, the subclass should override method paintComponent and call the superclass version of paintComponent as the first

statement in the body of the overridden method.

[Page 586]

Subclasses of JComponent support transparency. When a component is opaque, paintComponent clears the component's background before the component is displayed.

The transparency of a Swing lightweight component can be set with method setOpaque (a false argument indicates that the component is transparent).

Class Point (package java.awt) represents an x-y coordinate.

Class Graphics is used to draw.

MouseEvent method getPoint obtains the Point where a mouse event occurred.

Method repaint (inherited indirectly from class Component) indicates that a component should be refreshed on the screen as soon as possible.

Method paintComponent receives a Graphics parameter and is called automatically any time a lightweight component needs to be displayed on the screen.

Graphics method fillOval draws a solid oval. The method's four parameters represent the

bounding box in which the oval is displayed. The first two parameters are the upper-left x- coordinate and the upper-left y-coordinate of the rectangular area. The last two coordinates represent the rectangular area's width and height.

Interface KeyListener is used to handle key events that are generated when keys on the

keyboard are pressed and released. Method addKeyListener of class Component registers a KeyListener for a component.

KeyEvent method getKeyCode gets the virtual key code of the key that was pressed. Class

KeyEvent maintains a set of virtual key-code constants that represent every key on the keyboard.

KeyEvent method getKeyText returns a string containing the name of the key that was pressed.

KeyEvent method getKeyChar gets the Unicode value of the character typed.

KeyEvent method isActionKey determines whether the key in an event was an action key.

InputEvent method getModifiers determines whether any modifier keys (such as Shift, Alt and Ctrl) were pressed when the key event occurred.

KeyEvent method getKeyModifiersText produces a string containing the names of the pressed modifier keys.

Layout managers arrange GUI components in a container for presentation purposes.

All layout managers implement the interface LayoutManager (package java.awt).

Container method setLayout specifies the layout of a container.

FlowLayout is the simplest layout manager. GUI components are placed on a container from left

to right in the order in which they are added to the container. When the edge of the container is reached, components continue to display on the next line. Class FlowLayout allows GUI components to be left aligned, centered (the default) and right aligned.

FlowLayout method setAlignment changes the alignment for a FlowLayout.

The BorderLayout layout manager (the default for a JFrame) arranges components into five

regions: NORTH, SOUTH, EAST, WEST and CENTER. NORTH corresponds to the top of the container.

A BorderLayout limits a Container to containing at most five componentsone in each region.

The GridLayout layout manager divides the container into a grid so that components can be placed in rows and columns.

Container method validate recomputes a container's layout based on the current layout manager for the Container and the current set of displayed GUI components.

A JTextArea provides an area for manipulating multiple lines of text. JTextArea is a subclass of

JTextComponent, which declares common methods for JTextFields, JTextAreas and several other text-based GUI components.

[Page 587]

Class Box is a subclass of Container that uses a BoxLayout layout manager to arrange the GUI components either horizontally or vertically.

Box static method createHorizontalBox creates a Box that arranges components from left to right in the order that they are attached.

Method getSelectedText (inherited into JTextArea from JTextComponent) returns the selected text from a JTextArea.

You can set the horizontal and vertical scrollbar policies of a JScrollPane when it is constructed.

JScrollPane methods setHorizontalScrollBarPolicy and setVerticalScrollBarPolicy can be used change the scrollbar policies at any time.

[Page 587 (continued)]

Terminology

AbstractButton class

ActionEvent class

ActionListener interface

actionPerformed method of ActionListener adapter class

add method of class ButtonGroup add method of Container

addActionListener method of class JTextField addItemListener method of class AbstractButton addKeyListener method of class Component addListSelectionListener method of class JList addMouseListener method of class Component addMouseMotionListener method of class Component addWindowListener method of class JFrame anonymous inner class

AWTEvent class

book-title capitalization

BorderLayout class

Box class

BoxLayout class

ButtonGroup class

Class class

Component class

Container class

content pane

createHorizontalBox method of class Box

dedicated drawing area

default constructor of an anonymous inner class delegation event model

dialog box dispatch an event event

event driven event handler event handling event listener

event-listener adapter class event-listener interface event object

event registration event source

EventListenerList class

fillOval method of class Graphics

FlowLayout class

focus

Font class

getActionCommand method of ActionEvent

getClass method of Object

getClickCount method of MouseEvent

getContentPane method of JFrame

getIcon method of JLabel

getKeyChar method of KeyEvent

getKeyCode method of KeyEvent

getKeyModifiersText method of KeyEvent

getKeyText method of KeyEvent

getModifiers method of InputEvent getPassword method of JPasswordField getPoint method of MouseEvent getresource method of Class getSelected Index method of JList getSelectedIndex method of JComboBox

getSelectedText method of JTextComponent getSelectedValues method of JList getSource method of EventObject getStateChange method of ItemEvent getText method of JLabel

getX method of MouseEvent getY method of MouseEvent graphical user interface (GUI)

Graphics class

GridLayout class

GUI component

heavyweight GUI component

[Page 588]

Icon interface

ImageIcon class

inner class

input dialog

InputEvent class

isActionKey method of KeyEvent isAltDown method of InputEvent isAltDown method of MouseEvent isControlDown method of InputEvent isMetaDown method of InputEvent

isMetaDown method of MouseEvent

isSelected method of JCheckBox

isShiftDown method of InputEvent

ItemEvent class

ItemListener interface

itemStateChanged method of ItemListener

java.awt package

java.awt.event package

javax.swing package

javax.swing.event package

JButton class

JCheckBox class

JComboBox class

JComponent class

JFrame class

JLabel class

JList class

JOptionPane class

JPanel class

JPasswordField class

JRadioButton class

JScrollPane class

JSlider class

JTextArea class

JTextComponent class

JTextField class

JToggleButton class

KeyAdapter class

KeyEvent class

KeyListener interface

keyPressed method of KeyListener

keyReleased method of KeyListener

keyTyped method of KeyListener

layout manager

layoutContainer method of LayoutManager

LayoutManager interface

LayoutManager2 interface

lightweight GUI component

listenerList field of JComponent

ListSelectionEvent class

ListSelectionListener interface

ListSelectionModel class look-and-feel

message dialog

MouseAdapter class

mouseClicked method of MouseListener mouseDragged method of MouseMotionListener mouseEntered method of MouseListener MouseEvent class

mouseExited method of MouseListener MouseInputListener interface

MouseListener interface

MouseMotionAdapter class

MouseMotionListener interface

mouseMoved method of MouseMotionListener

mousePressed method of MouseListener

mouseReleased method of MouseListener

MouseWheelEvent class

MouseWheelListener interface

mouseWheelMoved method of MouseWheelListener

nested class

paintComponent method of JComponent Point class

registering an event handler repaint method of Component

rollover Icon

setAlignment method of FlowLayout setBackground method of Component

setDefaultCloseOperation method of JFrame

setEditable method of JTextComponent

setFixedCellHeight method of JList

setFixedCellWidth method of JList

setFont method of Component

setHorizontalAlignment method of JLabel

setHorizontalScrollBarPolicy method of JScrollPane

setHorizontalTextPosition method of JLabel

setIcon method of JLabel

setLayout method of Container

setLineWrap method of JTextArea

setListData method of JList

setMaximumRowCount method of JComboBox

setOpaque method of JComponent

setRolloverIcon method of AbstractButton

setSelectionMode method of JList

setSize method of JFrame

setText method of JLabel

setText method of JTextComponent

setToolTipText method of JComponent

[Page 589]

setVerticalAlignment method of JLabel

setVerticalScrollBarPolicy method of JSlider

setVerticalTextPosition method of JLabel

setVisible method of Component

setVisible method of JFrame

setVisibleRowCount method of JList

showInputDialog method of JOptionPane

showMessageDialog method of JOptionPane

static nested class Swing GUI components

SwingConstants interface tool tip

top-level class

transparency of a JComponent typing in a text field

validate method of Container

valueChanged method of ListSelectionListener WindowAdapter class

windowClosing method of WindowListener WindowListener interface