0% found this document useful (0 votes)
9 views49 pages

CST205 - M5 -Ktunotes.in

Uploaded by

RM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views49 pages

CST205 - M5 -Ktunotes.in

Uploaded by

RM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Module V-

Graphical User Interface


and Database support of
Java
Swing
SWING FUNDAMENTALS 3

» Java Swing is a GUI Framework that contains a set


of classes to provide more powerful and
flexible GUI components than AWT.
» Swing provides the look and feel of modern Java
GUI.
» Swing library is an official Java GUI tool kit
released by Sun Microsystems.
» It is used to create graphical user interface with
Java.
4

» Swing classes are defined in javax.swing


package and its subpackages.
» Java Swing provides platform-independent and
lightweight components.
» Java Swing is a part of Java Foundation Classes
(JFC) that is used to create window-based
applications.
» It is built on the top of AWT (Abstract Windowing
Toolkit) API and entirely written in java
5

» JFC
» The Java Foundation Classes (JFC) are a set of
GUI components which simplify the
development of desktop applications.
» The javax.swing package provides classes for
java swing API such as JButton, JTextField,
JTextArea, JRadioButton, JCheckbox,
Jmenu,JColorChooser etc.
Features of Swing 6

» Platform Independent:
» It is platform independent, the swing components
that are used to build the program are not
platform specific.
» It can be used at any platform and anywhere.
Features of Swing.. 7

» Lightweight:
» Swing components are lightweight which helps in creating the UI
lighter.
» A Swing component is said to be a lightweight component
because it written entirely in Java and does the high-level
display work itself, rather than relying on code provided by
your computer's operating system.
» Swings component allows it to plug into the operating system user
interface framework that includes the mappings for screens or
device and other user interactions like key press and mouse
movements.
Features of Swing.. 8

» Plugging:
» It has a powerful component that can be extended
to provide the support for the user interface that
helps in good look and feel to the application.
» It refers to the highly modular-based architecture
that allows it to plug into other customized
implementations and framework for user interfaces.
Features of Swing.. 9

» Manageable:
» It is easy to manage and configure.
» Its mechanism and composition pattern allows
changing the settings at run time as well.
» The uniform changes can be provided to the user
interface without doing any changes to application
code.
Features of Swing.. 10

» MVC:
» They mainly follows the concept of MVC that is
Model View Controller.
» With the help of this, we can do the changes in
one component without impacting or touching
other components.
» It is known as loosely coupled architecture as
well.
Features of Swing.. 11

» Customizable
» Swing controls can be easily customized. It can be
changed and the visual appearance of the swing
component application is independent of its internal
representation.

» Rich Controls
» Swing provides a rich set of advanced controls like Tree,
TabbedPane, slider, colorpicker, and table controls.
Hierarchy of Java Swing classes

12
The Model-View-Controller Architecture 13

» Swing uses the model-view-controller architecture


(MVC) as the fundamental design behind each of its
components
» MVC breaks GUI components into three elements.
» Each of these elements plays a crucial role in how the
component behaves.
» The Model-View-Controller is a well known software
architectural pattern ideal to implement user interfaces
on computers by dividing an application into three
interconnected parts
14

» Main goal of Model-View-Controller, also known as


MVC, is to separate internal representations of an
application from the ways information are
presented to the user.
» MVC was designed for desktop GUI applications
but it’s quickly become an extremely popular
pattern for designing web applications too.
15

» MVC pattern has the three components :


» Model that manages data, logic and rules of
the application
» View that is used to present data to user
» Controller that accepts input from the user
and converts it to commands for the Model or
View.
16

» The Model receives commands


and data from the Controller.
» It stores these data and updates
the View.
» The View lets to present data
provided by the Model to the user.
» The Controller accepts inputs from
the user and converts it to
commands for the Model or the
View.
Swing Controls 17

» Every user interface considers the following three main


aspects −
» UI Elements − These are the core visual elements the
user eventually sees and interacts with.
» Layouts − They define how UI elements should be
organized on the screen and provide a final look and feel
to the GUI (Graphical User Interface).
» Behavior − These are the events which occur when the
user interacts with UI elements.
18
19

» Every SWING controls inherits properties from the following


Component class hierarchy.
» Component is the abstract base class for the non menu
user-interface controls of SWING. Component represents
an object with graphical representation
» Container is a component that can contain other SWING
components
» JComponent is a base class for all SWING UI components.
In order to use a SWING component that inherits from
JComponent, the component must be in a containment
hierarchy whose root is a top-level SWING container
The list of commonly used controls while designing GUI using SWING 20

» JLabel
» A JLabel object is a component for placing text in a
container.
» JButton
» This class creates a labeled button.
» JColorChooser
» A JColorChooser provides a pane of controls
designed to allow a user to manipulate and select a
color.
The list of commonly used controls while designing GUI using SWING 21

» JCheck Box
» A JCheckBox is a graphical component that can be
in either an on (true) or off (false) state.
» JRadioButton
» The JRadioButton class is a graphical component
that can be in either an on (true) or off (false)
state. in a group.
» JList
» A JList component presents the user with a scrolling
list of text items.
The list of commonly used controls while designing GUI using SWING 22

» JComboBox
» A JComboBox component presents the user with a
to show up menu of choices.
» JTextField
» A JTextField object is a text component that allows
for the editing of a single line of text.
» JPasswordField
» A JPasswordField object is a text component
specialized for password entry.
The list of commonly used controls while designing GUI using SWING 23

» JTextArea
» A JTextArea object is a text component that allows
editing of a multiple lines of text.
» ImageIcon
» A ImageIcon control is an implementation of the
Icon interface that paints Icons from Images
» JScrollbar
» A Scrollbar control represents a scroll bar
component in order to enable the user to select
from range of values.
The list of commonly used controls while designing GUI using SWING 24

» JOptionPane
» JOptionPane provides set of standard dialog boxes
that prompt users for a value or informs them of
something.
» JFileChooser
» A JFileChooser control represents a dialog window
from which the user can select a file.
» JProgressBar
» As the task progresses towards completion, the
progress bar displays the task's percentage of
completion.
The list of commonly used controls while designing GUI using SWING 25

» JSlider
» JSlider lets the user graphically select a value by
sliding a knob within a bounded interval.
» Jspinner
» A JSpinner is a single line input field that lets the
user select a number or an object value from an
ordered sequence.
Components & Containers
COMPONENTS

» A component is an independent visual control, such as a


push button or slider.
» A container holds a group of components.
» a container is a special type of component that is
designed to hold other components.
» Swing components inherit from the
javax.Swing.JComponent class,which is the root of the
Swing component hierarchy.
3

» Swing components are derived from the


JComponent class.
» JComponent provides the functionality that is
common to all components.
» For example, JComponent supports the pluggable
look and feel.
4

» JComponent inherits the AWT classes Container


and Component.
» Thus, a Swing component is built on and
compatible with an AWT component.
» All of Swing’s components are represented by
classes defined within the package javax.swing.
Class names for Swing components 5

» Japplet » JRootPane » JEditorPane


» JColorChoose » JSlider » JInternalFram
r » Jtable e
» JDialog » JTogglebutton » JList
» JFrame » JViewport » JOptionPane
» JLayeredPane » JButton » JProgressBar
» JMenuItem » JComboBox
» JPopupMenu
CONTAINERS 6

» Swing defines two types of containers.


» The first are top-level containers:
» JFrame,
» JApplet,
» JWindow, and
» JDialog.
» These containers do not inherit JComponent. They
inherit the AWT classes Component and Container.
CONTAINERS 7

» The second type container are lightweight and the


top-level containers are heavyweight.
» This makes the top-level containers a special case
in the Swing component library.
8
9

» Commonly used containers while designed GUI using SWING.


» Panel
» JPanel is the simplest container. It provides space in which
any other component can be placed, including other
panels.
» Frame
» A JFrame is a top-level window with a title and a border.
» Window
» A JWindow object is a top-level window with no borders
and no menubar
10
11

EVENT HANDLING IN SWINGS


» The functionality of Event Handling is what is the
further step if an action performed.
» Java foundation introduced “Delegation Event
Model” i.e describes how to generate and control
the events.
» The key elements of the Delegation Event Model
are as source and listeners.
» The listener should have registered on source for
the purpose of alert notifications.
» All GUI applications are event-driven
Java Swing event object 14

» When something happens in the application, an event


object is created.
» For example, when we click on the button or select an
item from a list.
» There are several types of events, including ActionEvent,
TextEvent,FocusEvent, and ComponentEvent.
» Each of them is created under specific conditions.
» An event object holds information about an event that
has occurred.
SWING LAYOUT MANAGERS 15

» Layout refers to the arrangement of components


within the container.
» Layout is placing the components at a particular
position within the container.
» The task of laying out the controls is done
automatically by the Layout Manager.
» The layout manager automatically positions all the
components within the container.
16

» Even if you do not use the layout manager, the


components are still positioned by the default layout
manager.
» It is possible to layout the controls by hand, however,
it becomes very difficult
» Java provides various layout managers to position the
controls.
» Properties like size, shape, and arrangement varies
from one layout manager to the other.
Following classes that represents the layout managers: 17

» java.awt.BorderLayout » javax.swing.BoxLayout
» java.awt.FlowLayout » javax.swing.GroupLay
» java.awt.GridLayout out
» java.awt.CardLayout » javax.swing.ScrollPane
Layout
» java.awt.GridBagLayo
ut » javax.swing.SpringLay
out etc.
18
19
20
21
22
23

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy