5-jan-16 r ramesh swing. 5-jan-16 r ramesh an introduction to java foundation classes (jfc) a suite...

43
Jun 27, 20 22 R Ramesh Swin g

Upload: hubert-benson

Post on 19-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Swing

Page 2: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

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

Page 3: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

The Five API’s of JFC

Abstract window toolkit (AWT)SwingAccessibilityJava 2DDrag and Drop

Page 4: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

AWT

Basic GUI toolkitNew event modelDownward compatibility for java versions less than 1.1

Page 5: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Swing

Built on top of the core 1.1 and 1.2 AWT librariesHas twice the number of components as AWTCleaner design throughoutDepends on event handling mechanism of AWT 1.1

Page 6: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Accessibility

Assistance to users who have trouble with traditional user interfacesUsed in conjunction with devices such as audible text readers or braille keyboards

Page 7: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Java 2D

Classes for implementing various painting styles, complex shapes, fonts and colorsBased on APIs that were licensed from IBM’s Taligent divisionNot a part of Swing

Page 8: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Drag and Drop

Moving objects in and out of window or frame with predictable resultsCan be used to transfer information between Java applications and native applicationsNot a part of Swing

Page 9: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

The Five API’s of JFC

Page 10: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Why Swing and Why Not AWT?

AWT provided minimum functionality necessary to create a windowing applicationSwing is not a replacement for AWT but built on top of core AWT libraries

Page 11: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Disadvantages of AWT

Uses platform’s native componentsMinimal number of componentsTiming and sequence problems between platforms

Page 12: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Why Swing?

Pluggable look-and-feelsLightweight componentsOther features Wide variety of components Support for rendering custom Swing

components Support for replacing their insets with

arbitrary concentric borders

Page 13: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Model View Controller (MVC) Architecture

Design Pattern introduced as a part of Smalltalk-80 version of Smalltalk programming languageBuild systems that made use of multiple, synchronized presentation of same data

Page 14: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

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

Page 15: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Page 16: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Page 17: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Model

Represents state and low-level behavior of the componentManages state and conducts transformations on that stateHas no specific knowledge of either its controllers or its views

Page 18: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

View

Manages visual display of the state represented by modelA model can have more than one viewSwing set has one view associated with one model

Page 19: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Controller

Manages user interaction with the modelHas mechanism by which changes are made to the state of the model

Page 20: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Benefits of MVC

Clearly defined separation between components of a programProblems in each domain can be solved independentlyBinding between the model and the view is dynamic

Page 21: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

MVC in Swing Components

Page 22: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

The Model

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

Page 23: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

The View and Controller

Responsible for creating visual representation and handling user inputMethods are Paint Return geometric information Handle AWT events

Page 24: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JComponents and Subclasses

Abstract class extended by all Swing componentsContains properties such as, Background/foreground Enable/Disable Visibility

Page 25: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

java.lang.Object

java.awt.Component

java.awt.Container

javax.swing.JComponent

JComponent’s Ancestry

Page 26: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Top Level Components

JAppletJDialogJFrameJWindow

derived from their AWT version

Page 27: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Components Under JComponentJComboBox JLabel JList JMenuBar JPanel JPopupMenu

JScrollPane JTable JTree JInternalFrame JOptionPane

JProgressBar JRootPane JSeparator JSlider JSplitPane

JTabbedPane JToolBar JToolTip JViewport JColorChooser

JFileChooser JLayeredPane JTextComponent

JTextAreaJTextField

JPasswordField

JEditorPane

JTextPane

JDesktopPane

Page 28: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Components Under JComponent Contd..

JRadioButton

JToggleButton

JButton

JMenuItem

JCheckBox

Abstract Button

JMenu JRadioButtonMenuItemJCheckButtonMenuItem

Page 29: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

What JComponent Provides

Invalidating and repaintingPosition, size and alignmentAdding BordersTooltipsDouble BufferingFocus and Focus Cycle

Page 30: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JFrame

Standard windowRetains the look and feel of host OSActs as the main window to an application

Page 31: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JWindow

Floats anywhere on the screenHas no frame around itTypically used for popup menusTo display Splash screens

Page 32: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JDialog

Floats anywhere on the screenCan be modal or non-modalUsed to display messagesThe border and title bar are defined by the OS

Page 33: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JMenu

Attached to a menu bar (JMenuBar) or another JMenuItems are added using JMenuItemItems can be a JMenuItem and/or JCheckBoxMenuItem and/or JRadioButtonMenuItem

Page 34: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JPanel

A container to add components or to draw.A non-abstract version of JComponentCommon use is to group components

Page 35: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JScrollPane

Helps to scroll around panelsAutomatically adjusts itself

Page 36: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JSplitPane

A container which can hold two componentsCan be split horizontally or vertically

Page 37: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JTabbedPane

To display more components in one screenComponents are grouped into categoriesEach tab holds a category of components

Page 38: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

ImageIcon

Load small ImagesUsed when neededUsed on Buttons, Check boxes, Radio buttons etc.

Page 39: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JToolBar

A series of icon buttonsUsed as shortcuts to tasksA tool tip is associated with each buttonA tool bar can be in a separate window

Page 40: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JSlider and JProgressBar

A JSlider has minimum, maximum and a current valueUnits on a JSlider can be displayed using tick marks and labelsA JProgressBar is used to display the progress of a task

Page 41: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JTable

Helps to create spreadsheet like controls that have rows and columnsEditable cellsCell renderers can be used to add components like checkbox into a cell

Page 42: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

JTree

To display data in a hierarchical wayOne root node from which all nodes descendNodes can be collapsed/expanded

Page 43: 5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise

Apr 21, 2023R Ramesh

Summary

JFCBetween Swing and AWTMVC ArchitectureJComponent and its sub classes