Site MapHelpFeedbackChapter Summary
Chapter Summary
(See related pages)

• The type of user interface covered in this chapter is called a graphical user interface (GUI).
• GUI objects in the javax.swing package are collectively called Swing classes.
• To program the customized user interface effectively, we must learn a new style of programming control called event-driven programming.
• The GUI and related classes and interfaces introduced in this chapter are:
ActionEvent    JButton
ActionListener    JCheckBox
BorderFactory    JComboBox
BorderLayout    JFrame
ButtonGroup    JLabel
ChangeEvent    JList
ChangeListener    JMenu
Container    JMenuBar
FlowLayout    JMenuItem
GridLayout    JPanel
ImageIcon    JRadioButton
ItemEvent    JScrollPane
ItemListener    JSlider
JTextArea    MouseListener
JTextField    MouseMotionListener
MouseEvent
• GUI objects such as buttons and text fields are placed on the content pane of a frame window.
• The layout manager determines the placement of the GUI objects.
• The FlowLayout manager places components in left-to-right, top-to-bottom order.
• The BorderLayout manager places components in one of the five regions: north, south, east, west, and center.
• The GridLayout manager places components in one of the equal-size N X M grids.
• GUI objects can be placed on the content pane without using any layout manager. Such placement is called absolute positioning.
• Effective layout of GUI components is achieved by nesting panels and applying different layout managers to the panels.
• JPanel is a container for GUI components. JPanel itself is a GUI component, and therefore, we can nest JPanel objects.
• Event handling is divided into event sources and event listeners. Event sources generate events, and event listeners include a method that gets executed in response to the generated events.
• The most common event type is called an action event.
• ActionListener handles the action events.
• We use an instance of JButton to represent a pushbutton on a frame. JButton objects generate action events.
• GUI objects dealing with text are JLabel, JTextfield, and JTextArea. The JTextField objects generate action events.
• AJLabel object can include an image of type ImageIcon.
• The JCheckBox class is used for check-box buttons. An instance of the class generates action and item events.
• ItemEvent is generated when the state (selected/deselected) of an item changes.
• ItemEvent is handled by an instance of a class that implements the ItemListener interface.
• The JRadioButton class is used for radio buttons. An instance of the class generates action and item events.
• The JComboBox class is used for combo boxes, also known as drop-down lists. An instance of the class generates action and item events.
• The JList class is used for displaying a list of items. (Note: A JList object generates action and list events. To keep the examples brief and at the introductory level, we did not give any sample code that deals with events generated by a JList object.)
• The JSlider class is used for sliders. An instance of the class generates change events.
• ChangeEvent is handled by an instance of a class that implements the ChangeListener interface.
• We can find out the class to which an object belongs by using the instanceof operator.
• Aframe has one JMenuBar object. A single JMenuBar can have many JMenu objects with many JMenuItem objects associated to a single JMenu object.
• JMenuItem objects generate action events.
• User actions such as moving or dragging the mouse and clicking the mouse buttons will result in the generation of mouse events.
• MouseListener handles the button actions, and MouseMotionListener handles the mouse movements.







WuOnline Learning Center

Home > Chapter 14 > Chapter Summary