Java Programming. Events and Listeners

Size: px
Start display at page:

Download "Java Programming. Events and Listeners"

Transcription

1 Java Programming Events and Listeners Alice E. Fischer April 19, 2015 Java Programming - Events and Listenersldots 1/12

2 Events and Listeners An event is generated when The user clicks a GUI button or CheckBox or RadioButton The human user types a key. The human user uses the mouse, An internal timer dings. A window is opened or closed An observable object changes. These events are caught by the Java System, which will notify YOUR code of the event if a listener is registered for it. Java Programming - Events and Listenersldots 2/12

3 Catching Events A program can react to an event by registering a listener and an event handler. Any object in your widget tree can be used as a listener. An event handler is a method inside the listener class. For button and timer events, you need a method handle( ActionEvent ev) For mouse events, you need a method handle( MouseEvent ev) For key events, you need a method handle( KeyEvent ev) Java Programming - Events and Listenersldots 3/12

4 Event Handlers An event handler is a method that defines what the program should do to respond to the event. The parameter to the handle() method will be the event that happened. The parameter name can be used inside the method to get information about the event, such as the key that was typed or the position of a mouse click. Using that information, your program should make some appropriate response. Commonly, something is added to a scene, removed from a scene, or some feature of the scene is changed (color, position, text). Java Programming - Events and Listenersldots 4/12

5 Listeners A program can react to an event by creating a listener and a handler for it. There are at least four ways to create a handler for an event. Define an inner class that contains a method for handle. Define an anonymous inner class that contains a method for handle. Define a lambda-handler. Register the Application as a listener and define a handle function. Java Programming - Events and Listenersldots 5/12

6 Choosing a Listener A Pane, or anything you can put into a Pane can be used to listen for events. Sometimes you want the pane to listen. Sometimes you want a visible object inside the pane to listen. Java Programming - Events and Listenersldots 6/12

7 For each event you want to use, a handler must be created and a listener must be registered. This is often done in the same line of code, and there are several ways to do it. The event handler can be an instance of an inner class. The Listener can be an instance of an anonymous inner class. You can use a Lambda-handler, which is a simplified syntax for the anonymous inner class. If you have only one kind of event, you can register this to handle it. The registration methods use different syntax but all work the same way. Java Programming - Events and Listenersldots 7/12

8 Use an Inner Class: Egg Suppose you have an object named egg in your scene and want to respond when the mouse is clicked in it. At the end of your controller class, define an inner class with a handle() method. class DoClick implements EventHandler<MouseEvent> { public void handle( MouseEvent e ){ egg.setfill(color.gold); xclick = e.getx(); yclick = e.gety(); } } The registration syntax is: egg.setonmouseclicked ( new DoClick() ); Java Programming - Events and Listenersldots 8/12

9 Often you need more than one inner class. Now suppose you also want to respond when a key is pressed. You need another inner class named DoKey. class DoKey implements EventHandler<KeyEvent> { public void handle( KeyEvent e ){ // Put the key-event actions here. } } The registration syntax would be: egg.setonkeypressed(new DoKey()); Java Programming - Events and Listenersldots 9/12

10 Use an Anonymous Inner Class With this technique, the code that registers the listener is combined with the code that handles the event. Here is an example from the JackOLantern program: stopbut.setonaction(new EventHandler<ActionEvent>(){ public void handle(actionevent ev) { System.out.println("Time to quit."); Platform.exit(); } }); Java Programming - Events and Listenersldots 10/12

11 Use a Lambda Handler A lambda handler is a shortened syntax for the anonymous inner class. The code inside the braces is the body of handle. This example is from the Egg program: egg.setonmousepressed( ev -> { System.out.println("Mouse pressed"); egg.setfill( lightgreen ); }); You can use a lambda handler to call any method defined in the class. this example is from the EggCarton program: buybutton.setonaction ( ev -> { buy( ev ); }); Java Programming - Events and Listenersldots 11/12

12 Register this as a listener. The Application class can be the listener for events. This example is from the TicTacToe program. Declare that the class implements the right kind of handler: public class Game extends Application implements EventHandler<ActionEvent> Then the application needs to be registered as a listener for some action element: newbutton.setonaction( this ); Finally, the class must define a method for handle. public void handle( ActionEvent e ) { System.out.println( Starting a new game. ); outputfield.settext( Choose a square ); resetboard(); } Java Programming - Events and Listenersldots 12/12

Java Programming Lecture 7

Java Programming Lecture 7 Java Programming Lecture 7 Alice E. Fischer Feb 16, 2015 Java Programming - L7... 1/16 Class Derivation Interfaces Examples Java Programming - L7... 2/16 Purpose of Derivation Class derivation is used

More information

CS 112 Programming 2. Lecture 14. Event-Driven Programming & Animations (1) Chapter 15 Event-Driven Programming and Animations

CS 112 Programming 2. Lecture 14. Event-Driven Programming & Animations (1) Chapter 15 Event-Driven Programming and Animations CS 112 Programming 2 Lecture 14 Event-Driven Programming & Animations (1) Chapter 15 Event-Driven Programming and Animations rights reserved. 2 Motivations Suppose you want to write a GUI program that

More information

Event Handling in JavaFX

Event Handling in JavaFX Event Handling in JavaFX Event Driven Programming Graphics applications use events. An event dispatcher receives events and notifies interested objects. Event Listener Event EventQueue 1. ActionEvent 2.

More information

Chapter 15 Event-Driven Programming and Animations

Chapter 15 Event-Driven Programming and Animations Chapter 15 Event-Driven Programming and Animations 1 Motivations Suppose you want to write a GUI program that lets the user enter a loan amount, annual interest rate, and number of years and click the

More information

CST141 JavaFX Events and Animation Page 1

CST141 JavaFX Events and Animation Page 1 CST141 JavaFX Events and Animation Page 1 1 2 3 4 5 6 7 JavaFX Events and Animation CST141 Event Handling GUI components generate events when users interact with controls Typical events include: Clicking

More information

Event-Driven Programming with GUIs. Slides derived (or copied) from slides created by Rick Mercer for CSc 335

Event-Driven Programming with GUIs. Slides derived (or copied) from slides created by Rick Mercer for CSc 335 Event-Driven Programming with GUIs Slides derived (or copied) from slides created by Rick Mercer for CSc 335 Event Driven GUIs A Graphical User Interface (GUI) presents a graphical view of an application

More information

Lecture 19 GUI Events

Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous inner classes Proper interaction

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Spring 2017 GUI Event-Driven Programming 1 The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous

More information

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 4 Multi threaded Programming, Event Handling OOC 4 th Sem, B Div 2017-18 Prof. Mouna M. Naravani Event Handling Complete Reference 7 th ed. Chapter No. 22 Event Handling Any program that uses a

More information

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

CSE 331 Software Design and Implementation. Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression testing

More information

Chapter 15. Event-Driven Programming and Animations

Chapter 15. Event-Driven Programming and Animations Chapter 15 Event-Driven Programming and Animations 1 GUIs are event driven 2 In console applications the program is in charge of the flow of control, but in a GUI application it is the user that dictates

More information

Events Chris Piech CS106A, Stanford University. Piech, CS106A, Stanford University

Events Chris Piech CS106A, Stanford University. Piech, CS106A, Stanford University Events Chris Piech CS106A, Stanford University Catch Me If You Can We ve Gotten Ahead of Ourselves Source: The Hobbit Start at the Beginning Source: The Hobbit Learning Goals 1. Write a program that can

More information

Event Driven Programming

Event Driven Programming Event Driven Programming 1. Objectives... 2 2. Definitions... 2 3. Event-Driven Style of Programming... 2 4. Event Polling Model... 3 5. Java's Event Delegation Model... 5 6. How to Implement an Event

More information

1. (5 points) In your own words, describe what an instance is.

1. (5 points) In your own words, describe what an instance is. SE1021 Exam 2 Name: 1. (5 points) In your own words, describe what an instance is. 2. (5 points) Consider the Apple class in the UML diagram on the right. Write a couple lines of code to call the instance

More information

Composite Pattern Diagram. Explanation. JavaFX Subclass Hierarchy, cont. JavaFX: Node. JavaFX Layout Classes. Top-Level Containers 10/12/2018

Composite Pattern Diagram. Explanation. JavaFX Subclass Hierarchy, cont. JavaFX: Node. JavaFX Layout Classes. Top-Level Containers 10/12/2018 Explanation Component has Operation( ), which is a method that applies to all components, whether composite or leaf. There are generally many operations. Component also has composite methods: Add( ), Remove(

More information

Java Programming Layout

Java Programming Layout Java Programming Layout Alice E. Fischer Feb 22, 2013 Java Programming - Layout... 1/14 Application-Stage-Scene-Pane Basic GUI Construction Java Programming - Layout... 2/14 Application-Stage-Scene Application

More information

GUI Event Handlers (Part I)

GUI Event Handlers (Part I) GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event

More information

Java Programming Lecture 23

Java Programming Lecture 23 Java Programming Lecture 23 Alice E. Fischer April 19, 2012 Alice E. Fischer () Java Programming - L23... 1/20 April 19, 2012 1 / 20 Outline 1 Thread Concepts Definition and Purpose 2 Java Threads Creation

More information

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by

More information

Event-Driven Programming

Event-Driven Programming Lecture 10 1 Recall: JavaFX Basics So far we ve learned about some of the basic GUI classes (e.g. shapes, buttons) and how to arrange them in window(s) A big missing piece: interaction To have a GUI interact

More information

Java Foundations. 9-1 Introduction to JavaFX. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Java Foundations. 9-1 Introduction to JavaFX. Copyright 2014, Oracle and/or its affiliates. All rights reserved. Java Foundations 9-1 Copyright 2014, Oracle and/or its affiliates. All rights reserved. Objectives This lesson covers the following objectives: Create a JavaFX project Explain the components of the default

More information

Throughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.

Throughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031. SE1021 Exam 2 Name: You may have an 8.5x11 note sheet for this exam. No calculators or other study aids on this exam. Write your initials at the tops of the following pages and read through the exam before

More information

LAMBDA EXPRESSIONS. Summer 2018

LAMBDA EXPRESSIONS. Summer 2018 LAMBDA EXPRESSIONS Summer 2018 LAMBDA EXPRESSIONS USES Introduced in Java SE 8, lambda expressions are a way to create single-method classes in your code in a much less cumbersome manner than anonymous

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7 PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,

More information

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event

More information

C30b: Inner Class, Anonymous Class, and Lambda Expression

C30b: Inner Class, Anonymous Class, and Lambda Expression CISC 3115 TY3 C30b: Inner Class, Anonymous Class, and Lambda Expression Hui Chen Department of Computer & Information Science CUNY Brooklyn College 12/6/2018 CUNY Brooklyn College 1 Outline Discussed Concept

More information

Event-driven Programming: GUIs

Event-driven Programming: GUIs Dr. Sarah Abraham University of Texas at Austin Computer Science Department Event-driven Programming: GUIs Elements of Graphics CS324e Spring 2018 Event-driven Programming Programming model where code

More information

https://www.eclipse.org/efxclipse/install.html#for-the-lazy

https://www.eclipse.org/efxclipse/install.html#for-the-lazy CSC40232: SOFTWARE ENGINEERING Professor: Jane Cleland Huang Lecture 4: Getting Started with Java FX Wednesday, January 30 th and February 1 st sarec.nd.edu/courses/se2017 Department of Computer Science

More information

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised 1/15/10 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField, JTextArea,

More information

Chapter 14. Exception Handling and Event Handling

Chapter 14. Exception Handling and Event Handling Chapter 14 Exception Handling and Event Handling Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction to Event

More information

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted CS211 GUI Dynamics Announcements Prelim 2 rooms: A-M are in Olin 155 N-A are in Olin 255 Final exam: final exam 5/17, 9-11:30am final review session (TBA, likely Sun 5/15) Consulting: regular consulting

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

Programming Mobile Devices J2SE GUI

Programming Mobile Devices J2SE GUI Programming Mobile Devices J2SE GUI University of Innsbruck WS 2009/2010 thomas.strang@sti2.at Graphical User Interface (GUI) Why is there more than one Java GUI toolkit? AWT write once, test everywhere

More information

The AWT Event Model 9

The AWT Event Model 9 The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow

More information

Event-driven Programming, Separation of Concerns, the Observer pattern and the JavaFX Event Infrastructure

Event-driven Programming, Separation of Concerns, the Observer pattern and the JavaFX Event Infrastructure Java GUIs in JavaFX Event-driven Programming, Separation of Concerns, the Observer pattern and the JavaFX Event Infrastructure 1 GUIs process inputs and deliver outputs for a computing system Inputs Click

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : An interface defines the list of fields

More information

CS 251 Intermediate Programming GUIs: Event Listeners

CS 251 Intermediate Programming GUIs: Event Listeners CS 251 Intermediate Programming GUIs: Event Listeners Brooke Chenoweth University of New Mexico Fall 2017 What is an Event Listener? A small class that implements a particular listener interface. Listener

More information

Week 12 Thursday. For milestone #2 and #3, also submit a screenshot of your GUI once it is launched.

Week 12 Thursday. For milestone #2 and #3, also submit a screenshot of your GUI once it is launched. Week 12 Thursday D-Teams have been created Create your A-Team by Friday, or let me know to assign you earlier. Team Project: Tournament-Bracket (D-Team 30 pts) Milestone #1: due before 10pm THIS Friday,

More information

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes

More information

BASICS OF GRAPHICAL APPS

BASICS OF GRAPHICAL APPS CSC 2014 Java Bootcamp Lecture 7 GUI Design BASICS OF GRAPHICAL APPS 2 Graphical Applications So far we ve focused on command-line applications, which interact with the user using simple text prompts In

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer June 8, 2015 OOPP / C++ Lecture 7... 1/20 Program Errors Error Handling Techniques Exceptions in C++ Exception Definition Syntax Throwing

More information

Android Programming Lecture 2 9/7/2011

Android Programming Lecture 2 9/7/2011 Android Programming Lecture 2 9/7/2011 Creating a first app 1. Create a new Android project (a collection of source code and resources for the app) from the Eclipse file menu 2. Choose a project name (can

More information

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1 DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1 Objectives 1 6.1 Methods 1 void or return 1 Parameters 1 Invocation 1 Pass by value 1 6.2 GUI 2 JButton 2 6.3 Patterns

More information

DEMYSTIFYING PROGRAMMING: CHAPTER FOUR

DEMYSTIFYING PROGRAMMING: CHAPTER FOUR DEMYSTIFYING PROGRAMMING: CHAPTER FOUR Chapter Four: ACTION EVENT MODEL 1 Objectives 1 4.1 Additional GUI components 1 JLabel 1 JTextField 1 4.2 Inductive Pause 1 4.4 Events and Interaction 3 Establish

More information

GUI Widget. Lecture6

GUI Widget. Lecture6 GUI Widget Lecture6 AnalogClock/Digital Clock Button CheckBox DatePicker EditText Gallery ImageView/Button MapView ProgressBar RadioButton Spinner TextView TimePicker WebView Android Widgets Designing

More information

2.6 Error, exception and event handling

2.6 Error, exception and event handling 2.6 Error, exception and event handling There are conditions that have to be fulfilled by a program that sometimes are not fulfilled, which causes a so-called program error. When an error occurs usually

More information

GUI in Java TalentHome Solutions

GUI in Java TalentHome Solutions GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator

More information

Final Assignment for CS-0401

Final Assignment for CS-0401 Final Assignment for CS-0401 1 Introduction In this assignment you will create a program with an Graphical User Interface that will help customers to decide what car and car features that they want. In

More information

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA Assignment No. 4 SD Module-1 Advanced JAVA R C (4) V T Total (10) Dated Sign Title: Transform the above system from command line system to GUI based application Problem Definition: Write a Java program

More information

SD Module-1 Advanced JAVA. Assignment No. 4

SD Module-1 Advanced JAVA. Assignment No. 4 SD Module-1 Advanced JAVA Assignment No. 4 Title :- Transform the above system from command line system to GUI based application Problem Definition: Write a Java program with the help of GUI based Application

More information

PART ONE CREATING THE BOARD AND MAIN SPRITES

PART ONE CREATING THE BOARD AND MAIN SPRITES PART ONE CREATING THE BOARD AND MAIN SPRITES SETTING UP THE WINDOW Create a new basic JavaFX application. Use a Group for the main layout. When setting the scene, ensure the basic window is 800 by 600.

More information

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved.

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved. } Radio buttons (declared with class JRadioButton) are similar to checkboxes in that they have two states selected and not selected (also called deselected). } Radio buttons normally appear as a group

More information

Side Trip into Java: Enumeration Types. CS61B Lecture #36. Making Enumerals Available Elsewhere. Enum Types in Java. import static checkers.piece.

Side Trip into Java: Enumeration Types. CS61B Lecture #36. Making Enumerals Available Elsewhere. Enum Types in Java. import static checkers.piece. CS61B Lecture #36 Today: A Brief Side Trip: Enumeration types. DSIJ, Chapter 10, HFJ, pp. 489 516. Threads Communication between threads Synchronization es Coming Up: Graph Structures: DSIJ, Chapter 12

More information

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example

More information

CP122 CS I. Abstract Interfaces, Graphical User Interfaces, Inheritance

CP122 CS I. Abstract Interfaces, Graphical User Interfaces, Inheritance CP122 CS I Abstract Interfaces, Graphical User Interfaces, Inheritance AirPods now available for order Tech News! Tech News! AirPods now available for order Google reportedly stopping work on its own self-driving

More information

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)

More information

Chapter 5: Enhancing Classes

Chapter 5: Enhancing Classes Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions for AP* Computer Science 3rd Edition by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by

More information

References. Chapter 5: Enhancing Classes. Enhancing Classes. The null Reference. Java Software Solutions for AP* Computer Science A 2nd Edition

References. Chapter 5: Enhancing Classes. Enhancing Classes. The null Reference. Java Software Solutions for AP* Computer Science A 2nd Edition Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published

More information

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

Graphical User Interface (Part-1) Supplementary Material for CPSC 233 Graphical User Interface (Part-1) Supplementary Material for CPSC 233 Introduction to Swing A GUI (graphical user interface) is a windowing system that interacts with the user The Java AWT (Abstract Window

More information

We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really

We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really Week 9: Methods 1 We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really long and hard to read Sometimes you

More information

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class.

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class. Anonymous Classes A short-cut for defining classes when you want to create only one object of the class. Why Anonymous Class? Sometime we must define a class just to create only one instance of the class.

More information

Advanced Java for Bioinformatics Winter 2017/18. Prof. Daniel Huson

Advanced Java for Bioinformatics Winter 2017/18. Prof. Daniel Huson Advanced Java for Bioinformatics, WS 17/18, D. Huson, November 8, 2017 1 1 Introduction Advanced Java for Bioinformatics Winter 2017/18 Prof. Daniel Huson Office hours: Thursdays 17-18h (Sand 14, C310a)

More information

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Starting Out with Java: From Control Structures Through Objects Sixth Edition Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes

More information

CS 170 Java Programming 1. Week 9: Learning about Loops

CS 170 Java Programming 1. Week 9: Learning about Loops CS 170 Java Programming 1 Week 9: Learning about Loops What s the Plan? Topic 1: A Little Review ACM GUI Apps, Buttons, Text and Events Topic 2: Learning about Loops Different kinds of loops Using loops

More information

CS180 Recitation. More about Objects and Methods

CS180 Recitation. More about Objects and Methods CS180 Recitation More about Objects and Methods Announcements Project3 issues Output did not match sample output. Make sure your code compiles. Otherwise it cannot be graded. Pay close attention to file

More information

Jonathan Aldrich Charlie Garrod

Jonathan Aldrich Charlie Garrod Principles of Software Construction: Objects, Design, and Concurrency (Part 3: Design Case Studies) Introduction to GUIs Jonathan Aldrich Charlie Garrod School of Computer Science 1 Administrivia Homework

More information

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 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 user. But how do GUIs interact with users? How do applications

More information

Events. Dispatch, event-to-code binding. Review: Events Defined 1/17/2014. occurrence.

Events. Dispatch, event-to-code binding. Review: Events Defined 1/17/2014. occurrence. Events Dispatch, event-to-code binding Review: Events Defined 1. An observable occurrence, phenomenon, or an extraordinary occurrence. 2. A message to notify an application that something happened. Examples:

More information

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 4 Multi threaded Programming, Event Handling OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Event Handling Any program that uses a graphical user interface, such as a Java application written

More information

Java. Error, Exception, and Event Handling. Error, exception and event handling. Error and exception handling in Java

Java. Error, Exception, and Event Handling. Error, exception and event handling. Error and exception handling in Java Computer Science Error, Exception, and Event Handling Java 02/23/2010 CPSC 449 228 Unless otherwise noted, all artwork and illustrations by either Rob Kremer or Jörg Denzinger (course instructors) Error,

More information

Java FX. Threads, Workers and Tasks

Java FX. Threads, Workers and Tasks Java FX Threads, Workers and Tasks Threads and related topics Lecture Overview...but first lets take a look at a good example of Model - View - Controler set up This and most of the lecture is taken from

More information

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN CSSE 220 Event Based Programming Check out EventBasedProgramming from SVN Interfaces are contracts Interfaces - Review Any class that implements an interface MUST provide an implementation for all methods

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing. COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization

More information

Developing BPEL processes. Third part: advanced BPEL concepts and examples

Developing BPEL processes. Third part: advanced BPEL concepts and examples Developing BPEL processes Third part: advanced BPEL concepts and examples Web Languages Course Faculty of Science Academic Year: 2008/2009 Table of contents BPEL: Sequence BPEL:Terminate BPEL:Empty BPEL:

More information

Single processor CPU. Memory I/O

Single processor CPU. Memory I/O Lec 17 Threads Single processor CPU Memory I/O Multi processes Eclipse PPT iclicker Multi processor CPU CPU Memory I/O Multi-core Core Core Core Core Processor Memory I/O Logical Cores Multi-threaded

More information

Chapter 14. Exception Handling and Event Handling ISBN

Chapter 14. Exception Handling and Event Handling ISBN Chapter 14 Exception Handling and Event Handling ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction

More information

46 Advanced Java for Bioinformatics, WS 17/18, D. Huson, December 21, 2017

46 Advanced Java for Bioinformatics, WS 17/18, D. Huson, December 21, 2017 46 Advanced Java for Bioinformatics, WS 17/18, D. Huson, December 21, 2017 11 FXML and CSS A program intended for interactive use may provide a large number of user interface (UI) components, as shown

More information

Beautiful User Interfaces with JavaFX

Beautiful User Interfaces with JavaFX Beautiful User Interfaces with JavaFX Systémes d acquisition 3EIB S. Reynal September 20, 2017 The current document is dedicated to giving you a small and quick insight into the JavaFX API, an extra Java

More information

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class. Q1. If you add a component to the CENTER of a border layout, which directions will the component stretch? A1. The component will stretch both horizontally and vertically. It will occupy the whole space

More information

Event Binding. Different Approaches Global Hooks. 2.5 Event Binding 1

Event Binding. Different Approaches Global Hooks. 2.5 Event Binding 1 Event Binding Different Approaches Global Hooks 2.5 Event Binding 1 Event Dispatch vs. Event Binddling Event Dispatch phase addresses: - Which window receives an event? - Which widget processes it? Positional

More information

event driven programming user input Week 2 : c. JavaFX user input Programming of Interactive Systems

event driven programming user input Week 2 : c. JavaFX user input Programming of Interactive Systems Programming of Interactive Systems Week 2 : c. JavaFX user input Anastasia.Bezerianos@lri.fr Anastasia.Bezerianos@lri.fr (part of this class is based on previous classes from Anastasia, and of T. Tsandilas,

More information

Adapter. Comp-304 : Adapter Lecture 23. Alexandre Denault Computer Science McGill University Fall 2007

Adapter. Comp-304 : Adapter Lecture 23. Alexandre Denault Computer Science McGill University Fall 2007 Adapter Comp-304 : Adapter Lecture 23 Alexandre Denault Computer Science McGill University Fall 2007 Transactions Atomicity : Either all the tasks in the transactions are done, or none of them are. Consistency

More information

Mouse / Keyboard Events & Anonymous Functions. Lecture 19

Mouse / Keyboard Events & Anonymous Functions. Lecture 19 Mouse / Keyboard Events & Anonymous Functions Lecture 19 Announcements Hack110 - Friday, November 17th starting at 7pm ending at 7am! Encouraged if you're loving programming, doing well in 110, and considering

More information

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features: Lecture 28 Exceptions and Inner Classes Goals We are going to talk in more detail about two advanced Java features: Exceptions supply Java s error handling mechanism. Inner classes ease the overhead of

More information

CS 525M Mobile and Ubiquitous Computing Seminar. Michael Theriault

CS 525M Mobile and Ubiquitous Computing Seminar. Michael Theriault CS 525M Mobile and Ubiquitous Computing Seminar Michael Theriault A Context Aware User Interface for a Ubiquitous Computing environment at WPI After struggling to build a sensor network, I decided to switch

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber GUI are event driven (i.e. when user interacts with a GUI component, the interaction (event) derives the program to perform a task). Event: click button, type in text field,

More information

CS 116x Winter 2015 Craig S. Kaplan. Module 03 Graphical User Interfaces. Topics

CS 116x Winter 2015 Craig S. Kaplan. Module 03 Graphical User Interfaces. Topics CS 116x Winter 2015 Craig S. Kaplan Module 03 Graphical User Interfaces Topics The model-view-controller paradigm Direct manipulation User interface toolkits Building interfaces with ControlP5 Readings

More information

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours: CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Thursday 12:00 PM 2:00 PM Friday 8:30 AM 10:30 AM OR request appointment via e-mail

More information

Check out FilesAndExceptions from SVN. Exam 2 Review File I/O, Exceptions Vector Graphics Project

Check out FilesAndExceptions from SVN. Exam 2 Review File I/O, Exceptions Vector Graphics Project Check out FilesAndExceptions from SVN Exam 2 Review File I/O, Exceptions Vector Graphics Project Exam 2 review File I/O and Exceptions Vector Graphics project kickoff Exam is in class tomorrow Test on

More information

CS 106A, Lecture 14 Events and Instance Variables

CS 106A, Lecture 14 Events and Instance Variables CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons

More information

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014 Introduction to GUIs Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2014 Slides copyright 2014 by Jonathan Aldrich, Charlie Garrod, Christian

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Quality Assurance User Interface Modeling

Quality Assurance User Interface Modeling Quality Assurance User Interface Modeling Part II - Lecture 4 1 The University of Auckland New Zealand 254 18/09/ /2012 Interviewing Methods of the FBI 254 18/09/ /2012 Cognitive interview: method to enhance

More information

Event Driven Programming

Event Driven Programming Event Driven Programming Part 1 Introduction Chapter 12 CS 2334 University of Oklahoma Brian F. Veale 1 Graphical User Interfaces So far, we have only dealt with console-based programs Run from the console

More information

Do a domain analysis by hand-drawing three or more pictures of what the world program will look like at different stages when it is running.

Do a domain analysis by hand-drawing three or more pictures of what the world program will look like at different stages when it is running. How to Design Worlds The How to Design Worlds process provides guidance for designing interactive world programs using big-bang. While some elements of the process are tailored to big-bang, the process

More information

CS 11 java track: lecture 3

CS 11 java track: lecture 3 CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces

More information

Model-View-Controller Architecture

Model-View-Controller Architecture Model-View-Controller Architecture CS 5010 Program Design Paradigms Bootcamp Lesson 11.3 Mitchell Wand, 2012-2015 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International

More information

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7... Table of Contents Chapter 1 Getting Started with Java SE 7 1 Introduction of Java SE 7... 2 Exploring the Features of Java... 3 Exploring Features of Java SE 7... 4 Introducing Java Environment... 5 Explaining

More information