Tonga Institute of Higher Education

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Welcome to CIS 083 ! Events CIS 068.
Event Driven Programming
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Introduction to Windows Programming
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Interactive Programs Java API. Terminology Event—an action or occurrence, not part of a program, detected by the program. Events can be Event—an action.
Object Oriented Programming.  Interface  Event Handling.
CS324e - Elements of Graphics and Visualization Timing Framework.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Event Handling Tonga Institute of Higher Education.
Graphical User Interfaces Tonga Institute of Higher Education.
Creating a GUI Class An example of class design using inheritance and interfaces.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
CSC 205 Programming II Lecture 5 AWT - I.
Events and Event Handling
CompSci 230 S Programming Techniques
Visual Basic Fundamental Concepts
Scratch for Interactivity
A First Look at GUI Applications Radio Buttons and Check Boxes
Event Loops and GUI Intro2CS – weeks
PYGAME.
Chapter 12 Event-Driven Programming
Web Design & Development Lecture 11
A First Look at GUI Applications
Introduction to Event-Driven Programming
Event-driven programming
Event loops 16-Jun-18.
Processing Timer Events
Graphical User Interface (pronounced "gooey")
RAD Certification Checkpoint #2 Introducing RadStudio (Hello World)
Understand Windows Forms Applications and Console-based Applications
Lesson 1: Buttons and Events – 12/18
Ellen Walker Hiram College
Windows Desktop Applications
Chap 7. Building Java Graphical User Interfaces
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Event Driven Programming
Event Driven Programming
EE 422C Java FX.
Visual Basic..
Basic Elements of The GUI
Chapter 15 Event-Driven Programming and Animations
Event loops.
Event Driven Programming
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Events, Event Handlers, and Threads
Constructors, GUI’s(Using Swing) and ActionListner
Event loops 8-Apr-19.
Chapter 5 Processing Input with Applets
Event loops.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

Tonga Institute of Higher Education Event Handling Tonga Institute of Higher Education

Event Driven Programs Event Driven Programs – The program responds to a user event Event - An action or occurrence detected by a program User Clicking a mouse button Pressing a key System Running out of memory An error occurring For example, your program might work like this: Show a form with a welcome message. The form will also contain a textbox, OK button and instructions to enter their name and click the Ok button. Wait for the user to respond When the user performs an action, If the user clicks the X in the top right corner, quit the program If the user typed in their name and pressed the OK button, show a message that you are happy to meet them Gives more freedom to the user. It reacts to the user’s actions Gives user the impression that they are in control Frames are event driven!

Current Situation We learned how to display a graphical user interface However, it doesn’t do anything Event – Something that is triggered by the user of a GUI Listener – Code that can detect and respond to events Register – To associate a listener with a GUI object

Button Listener Class Need to import packages Need to make a class To handle events. Don’t forget to implement ActionListener! Handles 2 buttons This is the text of the button that will be handled The only code you should change has a yellow background

Setting Up Button Listeners Declare and Initialize the Listeners Same listener Must use this method Register the Listeners (Connect the listener to the button)

Demonstration GUI

Button Listener Class that Accepts a Frame This listener keeps track of the frame so it can change the frame. Pass in the frame through the constructor This changes the text for the button on the frame. The only code you should change has a yellow background

Setting Up Listeners that Passes a Frame Declare and Initialize the Listeners Pass this frame in the constructor Register the Listeners (Connect the listener to the button)

Demonstration GUI2

Frame Listener Class Only change code that is inside of the brackets Everything else should be the same!

Setting up a Form Listener This is the constructor Use the word this to add a listener Same listener

Demonstration GUI3