7
1 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

Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

1

Extreme Java G22.3033-007

Session 3 - Sub-Topic 1Swing

Dr. Jean-Claude Franchitti

New York UniversityComputer 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

Page 2: Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

2

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., tree-view, 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

Page 3: Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

3

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 betweenAWT 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)

Page 4: Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

4

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

Page 5: Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

5

JColorChooser - JComboBox - ImageIcon - Jdialog - JFileChooser

Swing Component GalleryJApplet - Border Interface - Jbutton - JCheckBox - JCheckBoxMenuItem

JInternalFrame - Jlabel - JList - JMenu - JMenuBar - JOptionPane

JScrollPane - Jslider - JSplitPane - JTabbedPane - JTable

Swing Component Gallery (cont.)JPopupMenu - JProgressBar - JRadioButton - JRadioMenuItem - JScrollBar

JTextArea - JTextField - JToggleButton - JToolBar - JToolTip - JTree

Swing’s Inheritance Hierarchy

Page 6: Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

6

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

Page 7: Dr. Jean -Claude Franchitti€¦ · – Drag and Drop • data transfer across Java and native applications, and within a single Java application – Accessibility API • e.g., screen

7

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