Ajp 2 PPT
Ajp 2 PPT
By
Sangita B.Chavan
Lecturer in Computer Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Differentiate between AWT and Swing
on the given aspect.
Introduction of JFC (Swing):
By
Sangita B.Chavan
Lecturer in Computer Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Develop GUI programs using swing
components for the given problem.
Swing Components:
By
Sangita B.Chavan
Lecturer in Computer Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Develop GUI programs using swing
components for the given problem.
JLabel:-
Label are text string that can be used to label other UI
components.labels are passive controls.
To create labels,:-
JLabel():Creates a JLabel instance with no image and with an
empty string for the title.
JLabel(String text) :Creates a JLabel instance with the
specified text.
JLabel(String text,int horizontalAlignment):Creates a
JLabel instance with the specified text, and horizontal
alignment.
JLabel(String text,Icon icon,int
horizontalAlignment):Creates a JLabel instance with the
specified text, image, and horizontal alignment.
JLabel(Icon icon) Creates a JLabel instance with the
specified image.
Here,icon is the image to be displayed by the label
The horizontal alignments are stored as constants
defined in Swing constants:
LEFT,CENTER,RIGHT,LEADING or TRAILING.
JLabel label=new
JLabel(“text”,SwingConstants.LEFT);
or
JLabel label=new
JLabel(“text”,JLabel.LEFT);
Commonly used Methods:
Methods Description
Methods Description
By
Sangita B.Chavan
Lecturer in Computer Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Use the given type of button in Java based
GUI.
Buttons:-
Swing button are subclasses of the AbstractButton class.
AbstractButton is an abstract subclass of JComponent.
It includes JButton,JToggleButton such as JCheckBox
,JRadioButton
JButton:-
The JButton class is used to create a labeled button that has
platform independent implementation. (i.e The JButton class
creates a push button that generates an event when it is
pressed.)
It inherits AbstractButton class.
Commonly used Constructors:
JButton():It creates a button with no text and icon.
JButton(String s):It creates a button with the specified
text.
JButton(Icon i):It creates a button with the specified icon
object.
•Jbutton(String s,Icon i): It creates a button with
the specified text and icon.
By
Sangita B.Chavan
Lecturer in Computer Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Develop Graphical user interface(GUI)
programs using advanced swing
components for the given problem.
JTabbedPane:-
The JTabbedPane class is used to switch between a group
of components by clicking on a tab with a given title or
icon.
Tab/components are added to a TabbedPane object
by using the addTab() and insertTab() methods .
A tab is represented by an index corresponding to
the position it was added in,where the first tab has
an index equal to 0,and the last tab an index equal
to the tab count minus 1.
The following constructors are supported by this
class:
JTabbedPane():Creates an empty TabbedPane
with a default tab placement of JTabbedPane.Top.
JTabbedPane(int tabplacement):Creates an
empty TabbedPane with a specified tab placement.
JTabbedPane(int tabplacement,int
tablayoutpolicy):Creates an empty TabbedPane
with a specified tab placement and tab layout policy.
Tab placement is the placement for the tabs relative to
the content and may be either
JTabbedPane.TOP(default),
JTabbedPane.BOTTOM, JTabbedPane.LEFT or
JTabbedPane.RIGHT.
Tab layout policy is the policy for laying out tabs when
all tabs will not fit on one run and may be either:
JTabbedPane.WRAP_TAB_LAYOUT(default) or
JTabbedPane.SCROLL_TAB_LAYOUT.
Many methods are supported by JTabbedPane.
1)public void insertTab(string title,Icon
icon,Component component,String tip,int
index):Inserts a new tab for the given component, at
the given index, represented by the given title and/or
icon, either of which may be null.
2)public void addTab(String title,Icon
icon,Component component,String tip):Adds
a component and tip represented by a title and/or icon,
either of which can be null.
OR
3)public Component add(String title,
Component component):Adds
a component with the specified tab title.
4)public int getTabCount():Returns the number of
tabs in this tabbedpane.
5)public String getTitleAt(int index):Returns
the tab title at index.
Ex-jtabbedpane.java
JScrollPane:-
JScrollPane is used to give a scrollable view to your
component. When the screen size is small or limited, we can
use a scroll pane to showcase a large component or a
component whose size changes dynamically.
JScrollPane basically consists of JScrollBars and
JViewport.In addition ,a JScrollPane can have a column
header and row header.
JViewport object that you specify with
setRowHeaderView() and setColumnHeaderView()
methods
The column header viewport automatically scrolls left and
right.the row header acts in a similar fashion.
The JViewport class manages components that have to be
scrolled.
The JScrollPane class manages a single viewport in the centre
of its area
Some of its constructor are:
JScrollPane(): Creates an empty scroll pane
(no viewPort).
JScrollPane(Component comp): Creates a
scroll pane with the specified component. When
the component content is larger than the view,
then horizontal and vertical scrollbar appears.
JScrollPane(int vsb,int hsb): Creates a scroll
pane with the specified scroll policies.
JScrollPane(Component comp,int vsb,int
hsb) Creates a scroll pane with the specified
component and specified scroll policies.
vsb and hsb are int constants that defines when
vertical and horizontal scrollpane . These
constants are defined by the ScrollPaneConstants
interface.
Some examples of these constants are:
HORIZONTAL_SCROLLBAR_ALWAYS: Always
provide horizontal scrollbar
HORIZONTAL_SCROLLBAR_AS_NEEDED:
provide horizontal scrollbar,if needed.
VERTICAL_SCROLLBAR_ALWAYS: Always
provide vertical scrollbar
VERTICAL_SCROLLBAR_AS_NEEDED: provide
vertical scrollbar,if needed.
To create and set a viewport,if necessary,to used:
public void setViewportView(Component view)
Ex-jscrollpane.java
Modifier Method Description
By
Sangita B.Chavan
Lecturer in Computer Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Develop Graphical user interface(GUI)
programs using advanced swing
components for the given problem.
JTree:-
A tree is a component that presents a hierarchical view of
data.
It has a 'root node' at the top most which is a parent for all
nodes in the tree.
A user has the ability to expand or collapse individual
subtrees in this display.
An expanded node is one that displays its children.
A collapsed node is one that hides them.
Some of its constructors are shown :
JTree(): It creates a simple model for class JTree.
JTree(Object obj[ ]): Creates a JTree with every element
of the specified array as the child of a new root node.
JTree(TreeNode tn) Creates a JTree with the specified
TreeNode as its root, which displays the root node.
The MutableTreeNode interface extends
TreeNode.it declares methods that can insert and
remove child nodes or change the parent node.
The DefaultMutableTreeNode class implements the
MutableTreeNode interface.
Ex-jtreeevent.java
jtree.java
JTable:-
A table is a component that displays rows and columns of
data.
Tables are implemented by the JTable class,which extends
JComponent.
The JTable is used to display and edit regular two-dimensional
tables of cells.
The following constructors can be used to create a JTable
object:
JTable():Creates a table with empty cells.
By
Sangita B.Chavan
Lecturer in Computer Technology
Govt. Polytechnic,Ahmednagar
Learning Objective
Explain the Architecture of MVC.
MVC:
Swing architecture is rooted in the model-
view-controller (MVC).
MVC architecture calls for a visual
application to be broken up into three
separate parts:
◦ A model that represents the data for the
application
◦ The view that is the visual representation of
that data
◦ A controller that takes user input on the
view and translates that to changes in the
model.”
MVC Architecture
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
For example :Scrollbar
Summary
Explain the Architecture of MVC