430 likes | 453 Views
Learn about Java Foundation Classes (JFC) suite of libraries supporting enterprise apps. Explore Swing, Accessibility, Java 2D, Drag and Drop. Discover advantages of Swing over AWT, Model View Controller (MVC) architecture, and components hierarchy.
E N D
An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise applications. Extends the original Abstract Window Toolkit (AWT) by adding a comprehensive set of graphical user interface class libraries
The Five API’s of JFC • Abstract window toolkit (AWT) • Swing • Accessibility • Java 2D • Drag and Drop
AWT • Basic GUI toolkit • New event model • Downward compatibility for java versions less than 1.1
Swing • Built on top of the core 1.1 and 1.2 AWT libraries • Has twice the number of components as AWT • Cleaner design throughout • Depends on event handling mechanism of AWT 1.1
Accessibility • Assistance to users who have trouble with traditional user interfaces • Used in conjunction with devices such as audible text readers or braille keyboards
Java 2D • Classes for implementing various painting styles, complex shapes, fonts and colors • Based on APIs that were licensed from IBM’s Taligent division • Not a part of Swing
Drag and Drop • Moving objects in and out of window or frame with predictable results • Can be used to transfer information between Java applications and native applications • Not a part of Swing
The Five API’s of JFC Java 2D Drag&Drop AWT Accessibility Swing
Why Swing and Why Not AWT? AWT provided minimum functionality necessary to create a windowing application Swing is not a replacement for AWT but built on top of core AWT libraries
Disadvantages of AWT • Uses platform’s native components • Minimal number of components • Timing and sequence problems between platforms
Why Swing? • Pluggable look-and-feels • Lightweight components • Other features • Wide variety of components • Support for rendering custom Swing components • Support for replacing their insets with arbitrary concentric borders
Model View Controller (MVC) Architecture • Design Pattern introduced as a part of Smalltalk-80 version of Smalltalk programming language • Build systems that made use of multiple, synchronized presentation of same data
MVC may be used in • A graph package that contains different graphical view of same data • A CAD system, in which portions of design can be viewed at different magnifications, in different windows and at different scales
Controller View Controller Model View View Controller
Model • Represents state and low-level behavior of the component • Manages state and conducts transformations on that state • Has no specific knowledge of either its controllers or its views
View • Manages visual display of the state represented by model • A model can have more than one view • Swing set has one view associated with one model
Controller • Manages user interaction with the model • Has mechanism by which changes are made to the state of the model
Benefits of MVC • Clearly defined separation between components of a program • Problems in each domain can be solved independently • Binding between the model and the view is dynamic
The Model • The methods under model can be grouped as • Query internal state • Manipulate internal state • Add and remove event listeners • Fire events
The View and Controller • Responsible for creating visual representation and handling user input • Methods are • Paint • Return geometric information • Handle AWT events
JComponents and Subclasses • Abstract class extended by all Swing components • Contains properties such as, • Background/foreground • Enable/Disable • Visibility
JComponent’s Ancestry java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent
Top Level Components • JApplet • JDialog • JFrame • JWindow derived from their AWT version
Components Under JComponent JComboBox JLabel JList JMenuBar JPanel JPopupMenu JScrollPane JTable JTree JInternalFrame JOptionPane JProgressBar JRootPane JSeparator JSlider JSplitPane JTabbedPane JToolBar JToolTip JViewport JColorChooser JFileChooser JLayeredPane JTextComponent JTextArea JDesktopPane JEditorPane JTextField JTextPane JPasswordField
Components Under JComponent Contd.. Abstract Button JCheckBox JToggleButton JRadioButton JButton JMenuItem JMenu JRadioButtonMenuItem JCheckButtonMenuItem
What JComponent Provides • Invalidating and repainting • Position, size and alignment • Adding Borders • Tooltips • Double Buffering • Focus and Focus Cycle
JFrame • Standard window • Retains the look and feel of host OS • Acts as the main window to an application
JWindow Floats anywhere on the screen Has no frame around it Typically used for popup menus To display Splash screens
JDialog Floats anywhere on the screen Can be modal or non-modal Used to display messages The border and title bar are defined by the OS
JMenu Attached to a menu bar (JMenuBar) or another JMenu Items are added using JMenuItem Items can be a JMenuItem and/or JCheckBoxMenuItem and/or JRadioButtonMenuItem
JPanel A container to add components or to draw. A non-abstract version of JComponent Common use is to group components
JScrollPane Helps to scroll around panels Automatically adjusts itself
JSplitPane A container which can hold two components Can be split horizontally or vertically
JTabbedPane To display more components in one screen Components are grouped into categories Each tab holds a category of components
ImageIcon Load small Images Used when needed Used on Buttons, Check boxes, Radio buttons etc.
JToolBar A series of icon buttons Used as shortcuts to tasks A tool tip is associated with each button A tool bar can be in a separate window
JSlider and JProgressBar A JSlider has minimum, maximum and a current value Units on a JSlider can be displayed using tick marks and labels A JProgressBar is used to display the progress of a task
JTable Helps to create spreadsheet like controls that have rows and columns Editable cells Cell renderers can be used to add components like checkbox into a cell
JTree To display data in a hierarchical way One root node from which all nodes descend Nodes can be collapsed/expanded
Summary • JFC • Between Swing and AWT • MVC Architecture • JComponent and its sub classes