Event Driven Programming and Graphical User Interface

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

User Interfaces II GUI – Awt, Swing, Web
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Event Handling Events and Listeners Timers and Animation.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
GUI Programming in Java
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
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,
Graphical User Interface Components Chapter What You Will Learn Text Areas Text Areas Sliders Sliders Menus Menus –With frames –Pop up menus Look.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– 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.
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.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
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.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Swing / Session1 / 1 of 30 Module Introduction Distributed Computing in Java.
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.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
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,
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Lecture 8: User Interface Components with Swing.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements.
A Quick Java Swing Tutorial
Events and Event Handling
Chapter 14 Event-Driven Programming
Welcome To java
Provision for GUIs in Java
Chapter 12 Event-Driven Programming
Web Design & Development Lecture 11
Advanced User Interfaces
Provision for GUIs in Java
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Event-driven programming for GUI
Event Driven Systems and Modeling
Chapter 16 Event-Driven Programming
Events, Event Handlers, and Threads
Java 2 Swing B.Ramamurthy 5/1/2019 B.Ramamurthy.
Presentation transcript:

Event Driven Programming and Graphical User Interface B.Ramamurthy 11/11/2018 B.Ramamurthy

Types of Programs Control-driven: The order in the program code determines the sequence of events. The actions are predetermined. Event-driven: The operation of the program depends on what you do with the controls presented (usually by the GUI) Selecting menu items, pressing buttons, dialog interaction cause actions within the program. 11/11/2018 B.Ramamurthy

Events 1. Actions such as clicking a button, moving a mouse, are recognized and identified by the operating systems(OS) or JVM. 2. For each action, OS/JVM determines which of the many currently running programs should receive the signal (of the action) 3. The signals that the application receives from the OS/JVM as result of the actions are called events. 11/11/2018 B.Ramamurthy

Event Generation User Interface Mouse actions, Keystrokes Operating Systems JAVA API /Windows Events Methods and handlers Methods and handlers Application 1 Application 2 11/11/2018 B.Ramamurthy

Event Handlers An application responds to the events by executing particular code meant for each type of event. Not all events need to be handled by an application. For example, a drawing application may be interested in handling only mouse movements. As a designer of an event-driven application you will write classes/methods to handle the relevant events. 11/11/2018 B.Ramamurthy

Event Handling Process Source of an event is modeled as an object. Ex: button click’s object is a button Type of the event: ActionEvent, WindowEvent, MouseEvent etc. Ex: An ActionEvent object is passed to the application that contains information about the action. Target of an event: Listener object of the event. Passing the event to a listener results in calling a particular method of the listener object. 11/11/2018 B.Ramamurthy

JDK1.2 Additions JFC java2D(3D) AWT Drag&Drop Swing Accessibility (Speech, Sight API) Collection classes Bug fixes JDK1.2 changes 11/11/2018 B.Ramamurthy

Swing Component Two distinguishing characteristics are : 1. It supports pluggable Look and Feel. Besides run-anywhere, appearance of a component may be changed at run-time to look and feel like the system on which it is running. 2. Swing components are Lightweight components: they do not dependent on any native system classes. 11/11/2018 B.Ramamurthy

Swing Components (controls) JApplet JButton JCheckBox JTable JTextPane JSlider JTree JPopupMenu JToolTip JScrollPane JDialog JMenuBar etc. Demo: jdk1.2/demo/jfc/SwingSet/SwingSetApplet.java Note : J prefix to distinguish it from regular AWT components. 11/11/2018 B.Ramamurthy

Steps in GUI Application Development Extend the application class from JFrame Declare all the components needed. Define the constructor. Instantiate a ContentPane and Define layout. Instantiate objects for the components and set their values. Add them to the ContentPane object. Add any listeners/handlers to specific components and define action to be performed in actionPerformed method. Add a main method that instantiate the object created above and takes care of Window closing. 11/11/2018 B.Ramamurthy

Event Handling Three ways: Frame itself is a (mouse) listener, with an action performed method. Event handling delegated to an object specially instantiated for this purpose. Anonymous class/object to handle just one event. Note: last two methods use inner class. We will examine the last two ways in the next example. 11/11/2018 B.Ramamurthy

Example op1 op2 result Add Sub This is a representation of the GUI for Lab2. Lab2 illustrates all the concepts discussed above. 11/11/2018 B.Ramamurthy