java events

Post on 07-Jan-2016

22 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Java Events. Overridden method: is an action that happens between a base(super) class and its child when they have the same method. - PowerPoint PPT Presentation

TRANSCRIPT

Java Events

Important definitions

•Overridden meth

od•Class

vs. abstr

act class

vs. interf

ace

Event Handli

ng•Defini

tion•Main

component

s

Windows

Adapters

Overridden method: is an

action that happens between

a base(super) class and its child when they have

the same method

An Abstract class is the same as a regular class except it has one or more methods that are not implemented ie they are declared but have no executable code; so yes, they can have constructors.

An Interface can only have variables which are constants. Methods can be declared BUT can have no executable code. All interface methods are implicitly abstract. An Interface does not have a constructor; as you cannot create an instance of an Interface. They guarantee behavior, not how the behavior occurs.

In Java

you can only inherit from one class using the keyword (Extends) and inherit from one or more interface using the keyword (Implements)

Any program that uses GUI such as java applications

written for windows is event driven, event

describes the change of state of any object. Example: Pressing a button, entering a

character in a textbox.

Event Handling

Components of the Event

1 .Event Sources2. Event classes3. Event Listeners4. Event Adapters

Event SourcesEvent sources are

components, subclasses

of java.awt.Component, capable to generate

events. The event source can be

a button, TextField or a Frame etc.

An object that generates an event.

Event ClassesAlmost every event source generates an event and is named by some Java

class.

Example Event it generates

Component

ActionEvent Button, TextFiels, List, Menu

WindowEvent

Frame

ItemEvent Checkbox,Choice,List

AdjustmentEvent

Scrollbar

MouseEvent Mouse(hardware)

KeyEvent Keyboard(hardware)

The events generated by hardware components (like MouseEvent and KeyEvent) are known as low-level events and the events generated by software components (like Button, List) are known as semantic events

Event Listeners

The events generated by the GUI components are handled by a special group of interfaces known

as listeners. They’re an

interface. Every component has its

own listener. Listeners are from java.awt.event

package.

Event Adapter

When a listener includes many

abstract methods to override, the coding

becomes heavy to the programmer. For

example, to close the frame, you override

seven abstract methods

of WindowsListener, in which, in fact you are using only one

method .

To avoid this heavy coding, the designers

come with another group of classes known as

"adapters". Adapters are abstract classes

defined in java.awt.event package. Every listener that

has more than one abstract method has got a corresponding adapter

class.

Event Adapter

top related