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

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Events and the AWT The objectives of this chapter are: To understand the principles of the Java 1.1 event model To understand how the event model is used.
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Inheritance using Java
Welcome to CIS 083 ! Events CIS 068.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
Event Handling. 2 GUIs are event driven –Generate events when user interacts with GUI e.g., moving mouse, pressing button, typing in text field, etc.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
Object Oriented Programming.  Interface  Event Handling.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Events (Chapter 11) Java Certification Study Group January 25, 1999 Mark Roth.
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
1 Lecture 8: User Interface Components with Swing.
UQC117S2 Graphics Programming Lecture 2 Event Handling Program as a sequence of instructions Event -driven program Need to detect the event and carry out.
Sep 181 Example Program DemoTranslateEnglishGUI.java.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
© Copyright by Pearson Education, Inc. All Rights Reserved. Appendix I GUI Components and Event Handling Android How to Program, 3/e.
GUI Programming using Java - Event Handling
CSC 205 Programming II Lecture 5 AWT - I.
Events and Event Handling
Chapter 14 Event-Driven Programming
Welcome To java
CompSci 230 S Programming Techniques
Chapter 15 Event-Driven Programming and Animations
CHAPTER Reacting to the user.
Chapter 12 Event-Driven Programming
Aum Amriteshwaryai Namah
Appendix I GUI Components and Event Handling
Responding to Events Event Handling in Java
Ellen Walker Hiram College
GUI Programming III: Events
UML Class Diagram: class Rectangle
Event Driven Programming and Graphical User Interface
Inheritance, Polymorphism, and Interfaces
Introduction to Computing Using Java
Interface.
GUI Programming using Java - Mouse Events
Interfaces.
Advanced Java Programming
CSE 1030: Implementing GUI Mark Shtern.
Web Design & Development Lecture 13
1/10/2019 JavaFX Events COSC 330.
Java Inheritance.
Events, Event Handlers, and Threads
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 14 Abstract Classes and Interfaces
Chapter 15 Event-Driven Programming and Animations Part 1
Presentation transcript:

Java Events

Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components 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 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)

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.

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

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.

Event Classes Almost 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.

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.