Download GUI - Introduction to Programming in Java - Lecture Slides and more Slides Network security in PDF only on Docsity!
Objectives
- describe some of the GUI controls and their listeners; more appear in part 13 12. GUI Examples I
Contents
1. Three Step GUI
2. Swing GUI Overview
3. Swing Hierarchy
4. Listener Interfaces
5. Button Example
6. TextField Example
7. Check Boxes Example
8. Radio Buttons Example
9. Combo Box Example
2. Swing GUI Overview
- The Swing GUI has six categories:
- basic components
- uneditable displays
- interactive displays of highly formatted info
- general-purpose containers
- top-level containers
- special-purpose containers
We will look at code examples using the GUI components listed in bold.
2.1. Basic Components
- Component Swing Class Name
- button JButton , JCheckBox , JRadioButton
- combo box JComboBox
- list JList
- menu JMenu, JMenuBar, JMenuItem
- slider JSlider
- text field JTextField , JPasswordField
2.2. Uneditable Displays
- Display Swing Class Name
- label JLabel
- Tooltip JToolTip
- Progress bar JProgressBar
2. 3. Interactive Displays
- Display Swing Class Name
- table JTable
- text JTextPane, JTextArea, JEditorPane
- tree JColorChooser
- file chooser JFileChooser
- General Purpose Containers
- Container Swing Class Name
- panel JPanel
- scroll pane JScrollPane , JScrollBar
- split pane JSplitPane
- tabbed pane JTabbedPane
- toolbar JToolbar
2. 6. Special-Purpose Containers
- Container Swing Class Name
- internal frame JInternalFrame
- layered pane JLayeredPane
- root pane JRootPane
indirectly used by top-level containers to gain access to the content pane and other 'layers' of a container
3. Swing Hierarchy (partial)
java.lang.Object
java.awt.Component (abstract)
java.awt.Container
javax.swing.JComponent (abstract)
continued
extends
Swing uses a AWT component to draw the blank window area.
The GUI in the window is drawn by Swing.
AbstractButton (abstract)
JMenuItem JMenu
JToggleButton JRadioButton
JButton^ JCheckBox
JTextComponent (abstract)
JEditorPane
JTextField
JTextArea
JLabel
JPanel
JScrollPane
GUI controls inherit many methods.
JToolTip
Not the whole hierarchy
extends
4. Listener Interfaces
- I'll look at 4 listener interfaces that can
handle events from different GUI
components
- ActionListener
- ItemListener
- MouseListener
- MouseMotionListener
- There are several other listener interfaces.
I'll use these two in this part
in part 13
4.1. ActionListener
- ActionListener can deal with events from:
- JButton (most common)
- JMenu, JMenuItem, JRadioButton, JCheckBox
- JTextField
- The interface has one method:
public void actionPerformed(ActionEvent e)