Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Events. Java Events Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows.

Similar presentations


Presentation on theme: "Java Events. Java Events Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows."— Presentation transcript:

1

2 Java Events

3 Important definitions
Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows Adapters

4 Overridden method: is an action that happens between a base(super) class and its child when they have the same method

5

6 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.

7 An Interface can only have variables which are constants
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.

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

9 Event Handling 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.

10 Components of the Event
1. Event Sources 2. Event classes 3. Event Listeners 4. Event Adapters

11 An object that generates an event.
Event Sources Event 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.

12 Event Classes Almost every event source generates an event and is named by some Java class.

13 Example Event it generates Component ActionEvent
Button, TextFiels, List, Menu WindowEvent Frame ItemEvent Checkbox,Choice,List AdjustmentEvent Scrollbar MouseEvent Mouse(hardware) KeyEvent Keyboard(hardware)

14 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

15 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.

16

17 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.

18 Event Adapter 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.

19

20

21


Download ppt "Java Events. Java Events Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows."

Similar presentations


Ads by Google