Ajp 2
Ajp 2
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
S H
VI
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
S H
VI
A R Msbtebook.blogspot.com
PDFelement
VI
Unit Title R U A Total
No
Level Level Level Marks
Abstract Windowing Tool
1 2 4 6 12
Kit (AWT)
2 Swing 2 2 6 10
3 Event Handling 2 2 8 12
4 Networking Basics 2 4 4 10
Interacting with
5 2 4 6 12
Database
6 Servlets 4 4 6 14
Total 14 20 36 70
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL Distribution of Marks
SH Unit
VI No
Unit Title R U A
Level Level Level Total Marks
2 Swing 2 2 6 10
3 Event Handling 2 2 8 12
4 Networking Basics 2 4 4 10
6 Servlets 4 4 6 14
Total 14 20 36 70
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
S H 2.1. Introduction to Swings: Swing Features, Difference
VI between AWT & Swings.
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL Package : javax.swing.*
S H
VI Swing is set of classes which provides more powerful and flexible
components as compare to AWT.
Build on top of AWT API and acts as replacement of AWTAPI.
Swing component follows a Model-View-Controller
Swing Components are implemented using Java and so they are
platform independent.
Called lightweight components
100 % Java implementations of components.
Use MVC architecture.
Model represents the data
View as a visual representation of the data
Controller takes input and translates it to changes in data
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
S H
VI
A R Msbtebook.blogspot.com
PDFelement
AV
CH
ALNo Java AWT Java Swing
S H
VI 1) AWT components are platform-dependent. Java swing components are platform-
independent.
2) AWT components are heavyweight. Swing components are lightweight.
3) AWT doesn't support pluggable look and feel. Swing supports pluggable look and feel.
4) AWT provides less components than Swing. Swing provides more powerful
components such as tables, lists, scrollpanes,
colorchooser, tabbedpane etc.
5) AWT doesn't follows MVC(Model View Controller) Swing follows MVC.
AWT uses Applet and Frame while Swing uses JApplet and JFrame
for GUI.
Swing has bigger collection of classes and interfaces as compare to AWT.
In Swing extra feature to Button: Provide Image.
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
Abstract Button
S H ButtonGroup
VI ImageIcon
JApplet
JButton
JCheckBox
JComboBox
JLabel
JRadioButton
JScrollPane
JTabbedPane
JTable
JTextField
JTree
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
SH
Extends JApplet/JFrame class.
VI Design UI in init() or Constructor method.
Add all components on Container instead on
JApplet/JFrame.
getContentPane() method returns the container object.
Call container add() method to add components.
For JFrame close operation: setDefaultCloseOperation()
Parameters:
DISPOSE_ON_CLOSE
EXIT_ON_CLOSE
DO_NOTHING_ON_CLOSE
A R Msbtebook.blogspot.com
PDFelement
V
A Small display area for text, image or both.
VI JLabel(Icon i)
JLabel(String s)
JLabel(String s, Icon i, int align)
align argument is either LEFT, RIGHT, CENTER,
ImageIcon:
ImageIcon(String filename)
ImageIcon(URL url)
The ImageIcon class implements the Icon interface that declares the methods
int getIconHeight( )
int getIconWidth( )
Other methods:
Icon getIcon( ) 1
String getText( ) 1
void setIcon(Icon i) https://www.gunwantmankar.com
Msbtebook.blogspot.com / Vishal Chavare 1
void setText(String s)
E Remove Watermark Wondershare
A R Msbtebook.blogspot.com
PDFelement
AV
CH java.lang.Object
AL
S H java.awt.Component
V I java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
Constructor
JTextField( )
JTextField(int cols)
JTextField(String s, int cols)
JTextField(String s)
A R Msbtebook.blogspot.com
PDFelement
AV
Combination of text field and drop down list.
H
CSubclass of JComponet
AL
ItemEvent is generated.
Implements ItemListener interface
Override: itemStateChnaged(ItemEvent ie) method defined by
ItemListener.
A R Msbtebook.blogspot.com
PDFelement
AV
C H
Swing provide Icon with Button text.
A L Swing buttons are subclasses of the AbstractButton class, which extends
S H Jcomponent.
VI AbstractButton contains many methods that allow you to
control the behavior of buttons, check boxes, and radio buttons.
Setter and Getter:
String getText( )
void setText(String s)
Constructors:
JButton(Icon i)
JButton(String s)
JButton(String s, Icon i)
Msbtebook.blogspot.com Vishal Chavare
https://www.gunwantmankar.com
/ 14
E Remove Watermark Wondershare
A R Msbtebook.blogspot.com
PDFelement
V
Ajava.lang.Object
CH java.awt.Component
AL
java.awt.Container
javax.swing.JComponent
S H javax.swing.AbstractButton
VI javax.swing.JToggleButton
javax.swing.JCheckBox
Constructor
JCheckBox(Icon i)
JCheckBox(Icon i, boolean state)
JCheckBox(String s)
JCheckBox(String s, boolean state)
JCheckBox(String s, Icon i)
JCheckBox(String s, Icon i, boolean state)
void setSelected(boolean state)
ItemEvent is generated.
ItemListener interface is needed to handle ItemEvent.
Public itemStateChanged() used to override.
A R Msbtebook.blogspot.com
PDFelement
AV java.lang.Object
CH java.awt.Component
AL
java.awt.Container
javax.swing.JComponent
S H javax.swing.AbstractButton
VI javax.swing.JToggleButton
javax.swing.JRadioButton
JRadioButton(Icon i)
JRadioButton(Icon i, boolean state)
JRadioButton(String s)
JRadioButton(String s, boolean state)
JRadioButton(String s, Icon i)
JRadioButton(String s, Icon i, boolean state)
ButtonGroup class is used to add radio button in group.
ActionEvent is generated.
ActionListener Listener interface is needed to handle ActionEvent.
public void actionPerofrmed() used to override.
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL A tabbed pane is a component that appears as a group of folders in
SH
V I a file cabinet.
Each folder has a title.
When a user selects a folder, its contents become visible.
Only one of the folders may be selected at a time.
Subclass of Jcomponent
Tabs are defined via the following method :
void addTab(String str, Component comp)
A R Msbtebook.blogspot.com
PDFelement
AV
CHA scroll pane is a component that presents a rectangular area in
AL which a component may be viewed.
S H Subclass of JComponent
VI
Constructor:
JScrollPane(Component comp)
JScrollPane(int vsb, int hsb)
JScrollPane(Component comp, int vsb, int hsb)
Comp: Component, vsb and hsb: Scrollbar constant
HORIZONTAL_SCROLLBAR_ALWAYS
HORIZONTAL_SCROLLBAR_AS_NEEDED
VERTICAL_SCROLLBAR_ALWAYS
VERTICAL_SCROLLBAR_AS_NEEDED
.
A R Msbtebook.blogspot.com
PDFelement
AV
CH
•LCheck box is selected or deselected, an item event is
A
H
S generated.
I
V • For handling implements ItemListener interface
• ItemListener interface is defines itemStateChanged( )
method.
• ItemEvent object is supplied as the argument.
• getState() : Get Status about checkbox.
A R Msbtebook.blogspot.com
PDFelement
AV
CHA tree is a component that presents a hierarchical view of data.
AL Trees are implemented in Swing by the JTree class, which extends
S H JComponent.
VI Constructors:
JTree(Hashtable ht)
JTree(Object obj[ ])
JTree(TreeNode tn)
JTree(Vector v)
A JTree object generates events when a node is expandedor collapsed.
The addTreeExpansionListener( ) and removeTreeExpansionListener( ) methods allow
listeners to register and unregister for these notifications.
Signature for these methods:
void addTreeExpansionListener(TreeExpansionListener tel)
void removeTreeExpansionListener(TreeExpansionListener tel)
A R Msbtebook.blogspot.com
PDFelement
AV
CHTo create a hierarchy of tree nodes, the add( ) method of
AL DefaultMutableTreeNode can be used.
A R Msbtebook.blogspot.com
PDFelement
AV
CHA table is a component that displays rows and columns of data.
AL You can drag the cursor on column boundaries to resize columns.
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL Software design pattern for software development.
SH
VI Model:
Major function of this layer to maintain the data.
Database and logic.
View:
Used to display full or partial data.
User Interface
Controller:
Control the interaction and communication between Model and view.
Communication logic/integration logic
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
S H
VI
A R Msbtebook.blogspot.com
PDFelement
AV
CH
AL
S H
VI