Graphical User Interface in JAVA

surajpandey54 1,224 views 26 slides Nov 27, 2018
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

Basic of GUI in Java


Slide Content

GUI

A graphical user interface (GUI) presents a pictorial
interface to a program, GUI's allow the user to work in a
more productive manner.
A GUI component is an object with which the user
interacts via the mouse or keyboard, below are some of
the Java GUI components

Some of the basic GUI components are
JLabelAn area where uneditable text or icons can be displayed
JTextFieldAn area where the user inputs data from the keyboard,
this area can also display data
JButtonAn area that triggers an event when clicked
JCheckBoxA GUI component that is either selected or not
selected
JComboBoxA drop-down list of items from which the user can
make a selection by clicking an item in the list or typing into the box
JListAn area where a list of items is displayed from which the user
can make a selection by clicking once on any element in the list.
Double-clicking an element in the list generates an action event,
Multiple elements can be selected
JPanelA container in which components can be placed

Java Layout Managers
The GUI is made up of a number of components, the
Layout Managers affect the content pane.
Layout Managers are provided to arrange GUI
components on a container for presentation purposes.
This allows the programmer to concentrate on the basic
"look and feel" and lets the layout managers process
most of the layout details

Several AWT and Swing classes provide layout managers
for general use:
1.BorderLayout
2.BoxLayout
3.CardLayout
4.FlowLayout
5.GridBagLayout
6.GridLayout
7.GroupLayout
8.SpringLayout

Here are 5 of the layout managers.

BorderLayout
The class BorderLayout arranges the components to fit
in the five regions: east, west, north, south and center.
Each region is can contain only one component and each
component in each region is identified by the
corresponding constant NORTH, SOUTH, EAST, WEST,
and CENTER.
Class declaration
Following is the declaration
for java.awt.BorderLayout class:
public class BorderLayout extends Object implements
LayoutManager2, Serializable

Here are the constructors defined by BorderLayout:
1.BorderLayout()
2.BorderLayout(int horz, int vert)
the first form creates a default border layout. The second
allows you to specify the horizontal and vertical space left
between components in horz and vert, respectively.
BorderLayout defines the following constants that specify
the regions.
BorderLayout.CENTER, BorderLayout.SOUTH,
BorderLayout.EAST, BorderLayout.WEST,
BorderLayout.NORTH

CardLayout
The class CardLayout arranges each component in the
container as a card. Only one card is visible at a time, and
the container acts as a stack of cards.
Class declaration
Following is the declaration
for java.awt.CardLayout class:
public class CardLayout extends Object implements
LayoutManager2, Serializable

CardLayout provides these two constructors:
1.CardLayout()
2.CardLayout(int horz, int vert)

FlowLayout 
The class FlowLayout components in a left-to-right
flow.
This is the most basic layout manager, components are
placed from left to right as they were added, when the
edge is reached the components are put on the next line.
You can align the components left, right or center
(default).
Class declaration
Following is the declaration
for java.awt.FlowLayout class:
public class FlowLayout extends Object implements
LayoutManager, Serializable

Here are the constructors for FlowLayout:
1.FlowLayout()
2.FlowLayout(int how)
3.FlowLayout(int how, int horz, int vert)
The first form creates the default layout, which centers
components and leaves five pixels of space between each
component. The second form lets you specify how each
line is aligned. Valid values of how are as follows:
FlowLayout.LEFT
FlowLayout.CENTER
FlowLayout.RIGHT

GridLayout 
Introduction
The class GridLayout arranges components in a
rectangular grid.
Class declaration
Following is the declaration
for java.awt.GridLayout class:
public class GridLayout extends Object implements
LayoutManager, Serializable

GridLayout are shown here:
1.GridLayout()
2.GridLayout(int numRows, int numColumns)
3.GridLayout(int numRows, int numColumns, int horz, int
vert)

GridBagLayout 
The class GridBagLayout arranges components in a
horizontal and vertical manner.
Class declaration
Following is the declaration
for java.awt.GridBagLayout class:
public class GridBagLayout extends Object implements
LayoutManager2, Serializable

GroupLayout 
GroupLayout is a layout manager that was developed for use
by GUI builder tools, but it can also be used
manually. GroupLayout works with the horizontal and vertical
layouts separately. The layout is defined for each dimension
independently. Consequently, however, each component
needs to be defined twice in the layout. The Find window
shown above is an example of a GroupLayout. .
Class declaration
Following is the declaration
for javax.swing.GroupLayout class:
public class GroupLayout extends Object implements
LayoutManager2

SpringLayout
SpringLayout is a flexible layout manager designed for use by
GUI builders. It lets you specify precise relationships between
the edges of components under its control. For example, you
might define that the left edge of one component is a certain
distance (which can be dynamically calculated) from the right
edge of a second component.SpringLayout lays out the
children of its associated container according to a set of
constraints, as shall be seen in
Class declaration
Following is the declaration
for javax.swing.SpringLayout class:
public class SpringLayout extends Object implements
LayoutManager2
Tags