CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Introduction to Java 2 Programming
An Introduction to Visual Basic Terms & Concepts.
Graphical User Interfaces (Part IV)
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Graphic User Interfaces Layout Managers Event Handling.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Event Handling Events and Listeners Timers and Animation.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
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.
Chapter 7 GUI design. So far this semester Have programmed in a stop and wait mode Program displays dialog box and waits for user to respond This was.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
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.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
An Introduction to Visual Basic
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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.
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,
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
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 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.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
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.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
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.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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.
GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Review_6 AWT, Swing, ActionListener, and Graphics.
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.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
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.
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.
Chapter Topics 15.1 Graphical User Interfaces
Event loops 16-Jun-18.
Graphical User Interface (pronounced "gooey")
An Introduction to Visual Basic
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Event loops.
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Chapter 15: GUI Applications & Event-Driven Programming
Constructors, GUI’s(Using Swing) and ActionListner
Event loops 8-Apr-19.
Tonga Institute of Higher Education
Event loops.
Event loops 19-Aug-19.
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling

Event Driven Programming A "Programming Paradigm" – others: object-oriented, functional, data -flow, procedural, and more! Most early programs we write: – get data – perform computations – output results – CRUD programming (Create, Read, Update, Delete) That's not how most programs we use actually behave. 2

Event Driven Programming 3

GUIs and Events Most programs sit there and wait for the user to respond Flow of control is based on user actions User action is an event that the program responds to Different languages have different levels of support for doing event driven programming 4

Events Handling High level approach: – fixes set of events and can attach code to the event: android:onclick Low level approach – must write code to check if events have occurred and deal with them in other code – Big old switch statement 5

Java Event Handling Java is in between the high level and low level approaches Built in GUI components in Swing: – buttons, check box, combo box, lists, menus, radio buttons, sliders, spinners, text fields, password text fields, labels, trees, color chooser, file chooser, separators, progress bars, trees, tables, and more 6

Java Event Handling These built in components can be added to top level containers such as frames (menus) and panels – Position is handled via a layout manager – initially we will use default layout manager FlowLayout components added one after another in a line Components are drawn and generate events 7

New Sample Program Program with buttons – background color changes when button pressed Main program -> frame -> panel Panel has an instance variable currentColor When paint component called, background set to currentColor demo 8

Add Buttons Add Buttons to the panel 9

Result of Adding Buttons Notice order of buttons What happens if change order of names? What happens if add more buttons? What happens if resize Frame? What happens if Button pressed? 10

Listeners When the buttons are pressed events are being generated, but no one is listening In other words we don't have any code that responds to the events We need to create listeners for each button to listen for the event and respond by changing background color 11

ActionListener LOTS of kinds of listeners All extend or implement the EventListener interface We will create a class that implements the ActionListener interface 12

Try a Separate Class Create a ColorAction class – instance vars – constructor – actionPerformed method repaint -> request an entire component be repainted. Don't call paintComponent array of colors build ColorAction and attach to each button 13

ColorAction class 14

Change Panel Class create setColor method add array of colors change constructor – call addActionListener on each button and add an appropriate ColorAction 15

Changes to EventExamplePanel Demo -> Examine output of ActionPerformed Add more buttons and colors 16