Processing Timer Events

Slides:



Advertisements
Similar presentations
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Outline Graphics Applets Drawing Shapes Components and Containers Images.
Advertisements

Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 5: Keyboard I/O & Simple GUI’s Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002,
Events ● Anything that happens in a GUI is an event. For example: – User clicks a button, presses return when typing text, or chooses a menu item ( ActionEvent.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
Writing GUI Applications An introduction with Java.
Graphical User Interfaces
ITEC220 GUI Lecture – Part 1 References  Java Software Solutions,” by Lewis & Loftus  Chapter 3  Chapter 4  Chapter 5  Chapter 6  Java Foundations-Introduction.
ELC 312 Day 6. © 2004 Pearson Addison-Wesley. All rights reserved4-2 Agenda Questions? Problem set two Posted in WebCT  Due Sept 30  On Page 153&154.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
Chapter 5: Enhancing Classes
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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,
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.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
GUIs and Events Rick Mercer.
CSC 205 Programming II Lecture 5 AWT - I.
CompSci 230 S Programming Techniques
Chapter 9: Graphical User Interfaces
Web Design & Development Lecture 11
A First Look at GUI Applications
Event loops 16-Jun-18.
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Chapter 4 Writing Classes.
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Timer class and inner classes
Chapter 4 Writing Classes.
Chapter 4 Writing Classes.
Event loops.
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Event loops 8-Apr-19.
Tonga Institute of Higher Education
4 Writing Classes Software Solutions Lewis & Loftus java 5TH EDITION
Event loops.
ITEC220 GUI Lecture – Part 2 References
Event loops 19-Aug-19.
TA: Nouf Al-Harbi NoufNaief.net :::
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Processing Timer Events is part of javax.swing helps manage activity over time Use it to set up a timer to generate an action event periodically When a timer event takes place, timer calls actionPerformed(ActionEvent event) part of the ActionListener interface (java.awt.event) Example: TimerTester.java

Inner classes Inner class Any class defined inside another is available to all the methods of the enclosing class Can access the members of the enclosing class Can reference the outer class using (Outerclass.this)

Anonymous inner classes Anonymous classes Often encountered within a method Combines the creation of an object with the definition Requires the inclusion of a semi-colon marking the end of expression containing the anonymous class Objects defined inside the method but outside of class Must be final before used inside anonymous class

Graphical Applications Java apps having graphical components Called GUI components GUI component An object representing a screen element Some are containers used to hold other components GUI related classes Defined in java.awt and javax.swing packages

GUI containers Frame Panel Used to display GUI-based Java application Displayed as a window with a title bar A heavyweight container Managed by the underlying operating system Panel Container that is not stand-alone Must be added to another container to be displayed Used to organize other components Lightweight container managed by the java program itself

Example: Authority Label Let us look at a program GUI component displaying a line of text Used to display information or to identify other components Let us look at a program Organizing two labels in a panel And displaying panel in a frame

GUI interfaces GUI revolves around Event Listener Components Events Listeners Event Represents some activity to which we may want to respond May be generated by a graphical component Listener Defines what happens when an event occurs

A corresponding listener Events and Listeners Event Component A component object may generate an event Listener A corresponding listener object is designed to respond to the event When the event occurs, the component calls the appropriate method of the listener, passing an object that describes the event © 2004 Pearson Addison-Wesley. All rights reserved

Example: PushCounter A push button The pushcounter example Allows the user to initiate an action By pressing a graphical button using the mouse is defined by JButton class The pushcounter example Displays a push button Increments a counter each time a button is pushed

Example: TextFields A text field Fahrenheit.java Allows the user to enter one line of input Generates an event when the enter key is pressed Fahrenheit.java Instantiates a listener and adds it to text field When user enters temperature in Fahrenheit The conversion into Celsius is performed