1 / 43

Swing

Swing. 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.

roryparsons
Download Presentation

Swing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Swing

  2. 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

  3. The Five API’s of JFC • Abstract window toolkit (AWT) • Swing • Accessibility • Java 2D • Drag and Drop

  4. AWT • Basic GUI toolkit • New event model • Downward compatibility for java versions less than 1.1

  5. 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

  6. Accessibility • Assistance to users who have trouble with traditional user interfaces • Used in conjunction with devices such as audible text readers or braille keyboards

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

  8. 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

  9. The Five API’s of JFC Java 2D Drag&Drop AWT Accessibility Swing

  10. 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

  11. Disadvantages of AWT • Uses platform’s native components • Minimal number of components • Timing and sequence problems between platforms

  12. 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

  13. 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

  14. 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

  15. Controller View Controller Model View View Controller

  16. 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

  17. 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

  18. Controller • Manages user interaction with the model • Has mechanism by which changes are made to the state of the model

  19. 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

  20. MVC in Swing Components

  21. The Model • The methods under model can be grouped as • Query internal state • Manipulate internal state • Add and remove event listeners • Fire events

  22. The View and Controller • Responsible for creating visual representation and handling user input • Methods are • Paint • Return geometric information • Handle AWT events

  23. JComponents and Subclasses • Abstract class extended by all Swing components • Contains properties such as, • Background/foreground • Enable/Disable • Visibility

  24. JComponent’s Ancestry java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent

  25. Top Level Components • JApplet • JDialog • JFrame • JWindow derived from their AWT version

  26. 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

  27. Components Under JComponent Contd.. Abstract Button JCheckBox JToggleButton JRadioButton JButton JMenuItem JMenu JRadioButtonMenuItem JCheckButtonMenuItem

  28. What JComponent Provides • Invalidating and repainting • Position, size and alignment • Adding Borders • Tooltips • Double Buffering • Focus and Focus Cycle

  29. JFrame • Standard window • Retains the look and feel of host OS • Acts as the main window to an application

  30. JWindow Floats anywhere on the screen Has no frame around it Typically used for popup menus To display Splash screens

  31. 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

  32. 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

  33. JPanel A container to add components or to draw. A non-abstract version of JComponent Common use is to group components

  34. JScrollPane Helps to scroll around panels Automatically adjusts itself

  35. JSplitPane A container which can hold two components Can be split horizontally or vertically

  36. JTabbedPane To display more components in one screen Components are grouped into categories Each tab holds a category of components

  37. ImageIcon Load small Images Used when needed Used on Buttons, Check boxes, Radio buttons etc.

  38. 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

  39. 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

  40. 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

  41. JTree To display data in a hierarchical way One root node from which all nodes descend Nodes can be collapsed/expanded

  42. Summary • JFC • Between Swing and AWT • MVC Architecture • JComponent and its sub classes

More Related