Download Java Core Technologies What is Swing?

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Extreme Java
G22.3033-007
Session 3 - Sub-Topic 1
Swing
Dr. Jean-Claude Franchitti
New York University
Computer Science Department
Courant Institute of Mathematical Sciences
Java Core Technologies
• JFC Swing
What is Swing?
• A GUI toolkit that simplifies and
streamlines the development of windowing
components (e.g., menus, toolbars, etc.)
• Pluggable look-and-feel design (PL&F)
– Platform specific look and feel with platform
independent software
– Swing components never rely on peer code
• Lightweight components
1
Swing and AWT
• Swing extends - but does not replace - the
Abstract Windowing Toolkit (AWT)
• AWT is a set of OO GUI classes
• Swing extends the Lightweight UI
Framework that became part of the Java
AWT with the introduction of JDK 1.1
Swing is 100% Pure Java and
Swing Beans
• Components are 100% pure Java versions
of AWT components (e.g., Button,
Scrollbar, List, etc.)
• Swing also include new higher-level
components written in pure Java (e.g., treeview, list-box, tabbed-pane components)
• Swing is compatible with the JavaBeans
specification
Swing and the JFC Library
• The JCF Library includes the Swing
component set
• JFC also contains three major APIs:
– Java 2D
• advanced 2D graphics and imaging
– Drag and Drop
• data transfer across Java and native applications, and
within a single Java application
– Accessibility API
• e.g., screen magnifiers, and audible text readers
2
Swing Architecture
Differences between
AWT and Swing
• Swing does not use any platform-specific
implementations (such as AWT’s “peers”)
• Swing creates its components using
pluggable look-and-feel (PL&F or plaf)
• Swing automatically plugs in the L&F
module that matches its platform
• Other L&F modules can also run in a given
GUI
Differences between
AWT and Swing (continued)
• L&F can be changed dynamically at
runtime
• The 3 other JFC APIs can be used in Swing
programs in a 1.2/1.3 environment (real
integration is planned for a future release)
3
The Three Parts of Swing
• New set of components inheriting from
JComponent
– Jcomponent is a descendent form AWT’s
Container class
– Jcomponent is the root class of almost all
Swing Component classes
– Hierarchy allows Swing components to contain
other components (component nesting)
The Three Parts of Swing
(continued)
• Group of Swing-related support classes
– Vital services to the Swing API
– Not used to create visible Swing components
• New set of Swing-related interfaces
implemented by Swing component classes
and support classes
Swing & IFC
• Best features of AWT and Netscape’s IFC
(Internet Foundation Class) library are
being integrated
• Some similarity in the default look and feel
of Swing and IFC widgets
• Similarities are disappearing since L&Fs
give Swing components different looks and
feels in different implementations
4
Swing Component Gallery
JApplet - Border Interface - Jbutton - JCheckBox - JCheckBoxMenuItem
JColorChooser - JComboBox - ImageIcon - Jdialog - JFileChooser
JInternalFrame - Jlabel - JList - JMenu - JMenuBar - JOptionPane
Swing Component Gallery (cont.)
JPopupMenu - JProgressBar - JRadioButton - JRadioMenuItem - JScrollBar
JScrollPane - Jslider - JSplitPane - JTabbedPane - JTable
JTextArea - JTextField - JToggleButton - JToolBar - JToolTip - JTree
Swing’s Inheritance Hierarchy
5
Swing Component Hierarchy
• More than 250 classes
• More than 75 interfaces for creating
lightweight, 100% pure Java GUI
components
• More than twice as many components as
AWT
UI classes and non-UI classes
• All UI-Swing component classes start with
“J” and descend from JComponent
• UI classes create visible components (e.g.,
buttons, menus, etc.)
• Examples of non-UI classes
– events classes, and model classes
Differences Between AWT & Swing
6
Differences Between AWT & Swing
• In AWT: CheckBox served as a check-box
class and a radio-button class
• In Swing all buttons have three states
(pressed, enabled, and selected)
• It is easier to synchronize and coordinate
menu events and button events in Swing (a
single mouse click can activate or
desactivate both a menu item and its toolbar
button)
JComponent Class
Roots in MVC
7
Related documents