Advance Java PDF
Advance Java PDF
https://www.gunwantmankar.com
/ 1
https://www.gunwantmankar.com
/ 2
Online Exam pattern are as follows:
Total questions are: 42 Time:- 90 Minutes
Detail online exam pattern are as follows with chapter wise questions
Distribution of Marks
Unit
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
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
https://www.gunwantmankar.com
/ 4
2.1. Introduction to Swings: Swing Features, Difference
between AWT & Swings.
https://www.gunwantmankar.com
/ 5
Package : javax.swing.*
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
https://www.gunwantmankar.com
/ 6
https://www.gunwantmankar.com
/ 7
No Java AWT Java Swing
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.
https://www.gunwantmankar.com
/ 8
Abstract Button
ButtonGroup
ImageIcon
JApplet
JButton
JCheckBox
JComboBox
JLabel
JRadioButton
JScrollPane
JTabbedPane
JTable
JTextField
JTree
https://www.gunwantmankar.com
/ 9
Extends JApplet/JFrame class.
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
https://www.gunwantmankar.com
/ 10
Small display area for text, image or both.
Extends Jcomponent.
Constructors:
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
/ 1
void setText(String s)
java.lang.Object
java.awt.Component
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)
https://www.gunwantmankar.com
/ 12
Combination of text field and drop down list.
Subclass of JComponet
Only one entry can view at a time.
Constructor:
JComboBox( )
JComboBox(Vector v)
void addItem(Object obj): Used to add object in Combobox
ItemEvent is generated.
Implements ItemListener interface
Override: itemStateChnaged(ItemEvent ie) method defined by
ItemListener.
https://www.gunwantmankar.com
/ 13
Swing provide Icon with Button text.
Swing buttons are subclasses of the AbstractButton class, which extends
Jcomponent.
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)
https://www.gunwantmankar.com
/ 14
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
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.
https://www.gunwantmankar.com
/ 15
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
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.
https://www.gunwantmankar.com
/ 16
A tabbed pane is a component that appears as a group of folders in
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)
https://www.gunwantmankar.com
/ 17
A scroll pane is a component that presents a rectangular area in
which a component may be viewed.
Subclass of JComponent
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
.
https://www.gunwantmankar.com
/ 18
• Check box is selected or deselected, an item event is
generated.
• For handling implements ItemListener interface
• ItemListener interface is defines itemStateChanged( )
method.
• ItemEvent object is supplied as the argument.
• getState() : Get Status about checkbox.
https://www.gunwantmankar.com
/ 19
A tree is a component that presents a hierarchical view of data.
Trees are implemented in Swing by the JTree class, which extends
JComponent.
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)
https://www.gunwantmankar.com
/ 20
To create a hierarchy of tree nodes, the add( ) method of
DefaultMutableTreeNode can be used.
void add(MutableTreeNode child)
Tree Expansion event described by class:
TreeExpansionEvent (Package: javax.swing.event)
The getPath( ) method of this class returns a TreePath.
TreePath getPath( )
TreeExpansionListener interface provides the following two methods
void treeCollapsed(TreeExpansionEvent tee)
void treeExpanded(TreeExpansionEvent tee)
https://www.gunwantmankar.com
/ 21
A table is a component that displays rows and columns of data.
You can drag the cursor on column boundaries to resize columns.
You can also drag a column to a new position.
Subclass of JComponent
Constructor:
JTable(Object data[ ][ ], Object colHeads[ ])
data is a two-dimensional array of the information
colHeads is a one-dimensional array with the column headings.
Steps to create Jtable
https://www.gunwantmankar.com
/ 22
Software design pattern for software development.
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
https://www.gunwantmankar.com
/ 23
https://www.gunwantmankar.com
/ 24
https://www.gunwantmankar.com
/ 25