0% found this document useful (0 votes)
14 views49 pages

Chapter 04

Uploaded by

Leonardo Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views49 pages

Chapter 04

Uploaded by

Leonardo Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 49

Faculty of Computer Science

Subject: Advance JAVA


Lecturer: Ajmal Rahmati
Java Programming Chapter 04

CHAPTER#-04
Java Programming Chapter 04

Swing Controls
Java Programming Chapter 04

• Swing Controls
• Every user interface considers the following three main aspects:
• UI elements : These are the core visual elements the user eventually sees
and interacts with.
• SWING provides a huge list of widely used and common elements varying
from basic to complex which we will cover in this tutorial.
• Layouts: They define how UI elements should be organized on the screen
and provide a final look and feel to the GUI (Graphical User Interface). This
part will be covered in Layout chapter.
• Behavior: These are events which occur when the user interacts with UI
elements. This part will be covered in Event Handling chapter.
Java Programming Chapter 04

Swing Controls
Java Programming Chapter 04

Event
What is an Event?
• Change in the state of an object is known as event i.e. event
describes the change in state of source.
• Events are generated as result of user interaction with the graphical
user interface components.
• For example, clicking on a button, moving the mouse, entering a
character through keyboard , selecting an item from list, scrolling the
page are the activities that causes an event to happen
Java Programming Chapter 04

Event
Types of Event
The events can be broadly classified into two categories:
• Foreground Events - Those events which require the direct interaction of user.
• They are generated as consequences of a person interacting with the graphical components
in Graphical User Interface.
• For example, clicking on a button, moving the mouse, entering a character through
keyboard, selecting an item from list, scrolling the page etc.
• Background Events - Those events that does not require the interaction of end user are
known as background events.
• Operating system interrupts, hardware or software failure, timer expires, an operation
completion are the example of background events.
Java Programming Chapter 04

What is Event Handling?


• Event Handling is the mechanism that controls the event and decides what should
happen if an event occurs.
• This mechanism have the code which is known as event handler that is executed when
an event occurs.
• Java Uses the Delegation Event Model to handle the events.
• This model defines the standard mechanism to generate and handle the events.Let's
have a brief introduction to this model.
• The Delegation Event Model has the following key participants namely:
• Source - The source is an object on which event occurs. Source is responsible for
providing information of the occurred event to it's handler. Java provide as with classes
for source object.
Java Programming Chapter 04

What is Event Handling?


• Listener - It is also known as event handler.Listener is responsible for generating response to an
event.
• From java implementation point of view the listener is also an object. Listener waits until it
receives an event. Once the event is received , the listener process the event an then returns.
• The benefit of this approach is that the user interface logic is completely separated from the logic
that generates the event.
• The user interface element is able to delegate the processing of an event to the separate piece of
code.
• In this model ,Listener needs to be registered with the source object so that the listener can
receive the event notification.
• This is an efficient way of handling the event because the event notifications are sent only to
those listener that want to receive them.
Java Programming Chapter 04

Steps involved in event handling


• The User clicks the button and the event is generated.
• Now the object of concerned event class is created automatically and
information about the source and the event get populated with in same object.
• Event object is forwarded to the method of registered listener class.
• the method is now get executed and returns
Java Programming Chapter 04

Swing JLabel Class


• The class JLabel can display either text, an image, or both.
• Label's contents are aligned by setting the vertical and horizontal
alignment in its display area.
• By default, labels are vertically centered in their display area.
• Text-only labels are leading edge aligned, by default; image-only
labels are horizontally centered, by default.
Java Programming Chapter 04

Swing JLabel Class


Java Programming Chapter 04

Swing JButton Class


• The class JButton is an implementation of a push button.
• This component has a label and generates an event when pressed.
• It can have Image also.
Java Programming Chapter 04

Swing JButton Class


Java Programming Chapter 04

Swing JCheckBox Class


• The class JCheckBox is an implementation of a check box - an item
that can be selected or deselected, and which displays its state to the
user.
Java Programming Chapter 04

Swing JCheckBox Class


Java Programming Chapter 04

Swing JRadioButton Class


• The class JRadioButton is an implementation of a radio button - an
item that can be selected or deselected, and which displays its state
to the user.
Java Programming Chapter 04

Swing JRadioButton Class


Java Programming Chapter 04

Swing JComboBox Class


• The class JComboBox is a component which combines a button or
editable field and a drop-down list.
Java Programming Chapter 04

Swing JComboBox Class


Java Programming Chapter 04

Swing JTextField Class


• The class JTextField is a component which allows the editing of a
single line of text.
Java Programming Chapter 04

Swing JTextField Class


Java Programming Chapter 04

JPasswordField Class
The class JPasswordField is a component which is specialized to handle
password functionality and allows the editing of a single line of text.
Java Programming Chapter 04

JPasswordField Class
Java Programming Chapter 04

Swing JTextArea Class


The class JTextArea is a multi-line area to display plain text.
Java Programming Chapter 04

Swing JTextArea Class


Java Programming Chapter 04

Swing ImageIcon Class


The class ImageIcon is an implementation of the Icon interface that
paints Icons from Images.
Java Programming Chapter 04

Swing ImageIcon Class


Java Programming Chapter 04

Swing JScrollBar Class


The class JScrollBar is an implementation of scrollbar.
Java Programming Chapter 04

Swing JScrollBar Class


Java Programming Chapter 04

Swing JOptionPane Class


The class JOptionPane is a component which provides standard
methods to pop up a standard dialog box for a value or informs user of
something.
Java Programming Chapter 04

Swing JOptionPane Class


Java Programming Chapter 04

Swing JList Class


The class JList is a component which displays a list of objects and
allows the user to select one or more items. A separate model,
ListModel, maintains the contents of the list.
Java Programming Chapter 04

Swing JList Class


Java Programming Chapter 04

Swing JColorChooser Class


• The class JColorChooser provides a pane of controls designed to
allow a user to manipulate and select a color.
Java Programming Chapter 04

Swing JColorChooser Class


Java Programming Chapter 04

Swing JFileChooser Class


• The class JFileChooser is a component which provides a simple
mechanism for the user to choose a file.
Java Programming Chapter 04

Swing JFileChooser Class


Java Programming Chapter 04

Swing JSlider Class


• The class JSlider is a component which lets the user graphically select
a value by sliding a knob within a bounded interval.
Java Programming Chapter 04

Swing JSlider Class


Java Programming Chapter 04

Swing JSpinner Class


• The class JSpinner is a component which lets the user select a
number or an object value from an ordered sequence using an input
field.
Java Programming Chapter 04

Swing JSpinner Class


Java Programming Chapter 04

SWING - JProgressBar Class


• The class JProgressBar is a component which visually displays the
progress of some task.
Java Programming Chapter 04

SWING - Menu Classes


• As we know that every top-level window has a menu bar
associated with it.
• This menu bar consists of various menu choices available
to the end user.
• Further, each choice contains a list of options, which is
called drop-down menus.
• Menu and MenuItem controls are subclass of
MenuComponent class.
Java Programming Chapter 04

SWING - Menu Classes


Java Programming Chapter 04

SWING - JProgressBar Class


• The class JProgressBar is a component which visually displays the
progress of some task.
Java Programming Chapter 04

Suggested Reading for Lecture:


Introduction to Java Programming By: Y. Daniel Liang 8th edition
java how to program By: Paul Deitel and Harvey Deitel 9th edition
Review Questions:
‫‪Thank You‬‬
‫‪For Your Patience‬‬

‫‪Thought of Day‬‬
‫الزم نیست حتما عالی باشی تا شروع کنی‪ ،‬ولی حتما‬
‫‪.‬باید شروع کنی تا بتوانی عالی باشی‬

You might also like