Unit-II Swing and MVC Architecture
Unit-II Swing and MVC Architecture
by
Amol S. Gaikwad
Lecturer,
Government Polytechnic Gadchiroli
Advanced Java Programming
Unit-II
Swings and MVC
Architecture
Welcome!
Are you excited for a fun
learning session?
Unit Outcomes
Differentiate between AWT and Swing on the given aspect
Develop Graphical User Interface (GUI) programs using swing component for given
problems
Swing
Swing is used for creating More powerfull and more
Graphical User Interface flexible components
(GUI)
Container contains
Container group of components
label
TextField etc.
AWT
Platform dependant Platform independant
Swing
Heavyweight code
lightweight code
JApplet class
If your applet uses swing then it must be subclass of JApplet class
contentPane.add(componet)
ImageIcon class and Icon interfacce
ImageIcon class is used to create icons (image)
JLabel(String s, Icon i, int align) - creates label using both string and icon and
also aligns the label to right,center,leading or trailing
Labels - JLabel class
Functions in JLabel class :
void setRolloverIcon(Icon i) - displays icon when mouse positioned over other icon
String getText() - returns text of a button
void setText() - changes text of button
Buttons - JButton class
It is used to create push buttons
JCheckBox(String s, boolean state) - creates checkbox with the string and state
JCheckBox(String s, Icon i) - creates checkbox with the both string and icon
JRadioButton(String s, boolean state) - radio button with the string and state
JRadioButtonString s, Icon i) - creates radio button with the both string and icon
void addTab(String str, Component comp) - adds component to a tab, str is title of a
tab and comp is component to be added to the tab
Tabbed Panes - JTabbedPane class
Procedure to create tabbed pane in applet
Scroll pane is created using JScrollPane class, which sublcass (child) of JComponent
class
JScrollPane(int vsb, int hsb) - creates vertical and horizontal scroll bar
JScrollPane(Component comp, int vsb, int hsb) - adds component and creates
vertical and horizontal scroll bar
Scroll Panes - JScrollPane class
Constants in JScrollPane class :
JTree(Hashtable ht) - creates tree with each element in hash table is child node
JTree(Object obj[ ]) - creates tree with each element in array obj is child node
TreePath class also stores information about path or location of tree node
TreeNode interface has methods that gives information about tree node
MutableTreeNode interface has methods that can insert and remove child nodes
and change parent node also
Tables are created using JTable class , JTable class is sublcass (child) JComponent
class
In MVC, Controller decides how to the component react to user. Example - when
we click on checkbox,controller changes the model to show user choice ( checked
or unchecked )
Swing uses modified version of MVC which combines view and control into single
entity called UI delegate
Model
Model
View + Controller
https://www.javatpoint.com/free-java-
projects
Summary of Class
1 2 3
Lesson Recap 1 Lesson Recap 2 Lesson Recap 3
Swing vs GUI Using Buttons in GUI
AWT Swing
4 3
Lesson Recap 4
Develop GUI
using swing
components
Refrences
The Complete Reference Java Seventh Edition - Herbert
Schildt,McGraw Hill Publication
Thank You
For Attending!