Event Driven Programming

Similar documents
Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Window Interfaces Using Swing Objects

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Widgets. Widgets Widget Toolkits. User Interface Widget

Introduction to the JAVA UI classes Advanced HCI IAT351

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

Window Interfaces Using Swing Objects

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Graphical User Interface (GUI)

CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal

Chapter 6: Graphical User Interfaces

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Summary Chapter 25 GUI Components: Part 2

Part 3: Graphical User Interface (GUI) & Java Applets

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Chapter 12 GUI Basics

CS 251 Intermediate Programming GUIs: Components and Layout

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

Graphic User Interfaces. - GUI concepts - Swing - AWT

CSE 1325 Project Description

Widget Toolkits CS MVC

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Java Swing Introduction

Java Programming Lecture 6

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

1005ICT Object Oriented Programming Lecture Notes

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

Programming graphics

Widget. Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Java IDE Programming-I

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

CS111: PROGRAMMING LANGUAGE II

2110: GUIS: Graphical User Interfaces

Lecture 18 Java Graphics and GUIs

Java: Graphical User Interfaces (GUI)

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

BASICS OF GRAPHICAL APPS

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...

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

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Packages: Putting Classes Together

More Swing. CS180 Recitation 12/(04,05)/08

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

Graphical User Interfaces. Comp 152

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

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

JTcl and Swank. Bruce A. Johnson, Tom Poindexter, & Dan Bodoh. What s new with Tcl and Tk on the JVM. Wednesday, October 26, 11

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

Chapter 14. More Swing

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p.

Today. cisc3120-fall2012-parsons-lectiii.3 2

WIMP Elements. GUI goo. What is WIMP?

Layout. Dynamic layout, Swing and general layout strategies

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

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

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

Window Interfaces Using Swing. Chapter 12

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Introduction to concurrency and GUIs

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

More Swing. Chapter 14. Chapter 14 1

ITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity

Is image everything?

JLayeredPane. Depth Constants in JLayeredPane

Basicsof. JavaGUI and SWING

Building Graphical User Interfaces. GUI Principles

Graphical User Interfaces

Building Graphical User Interfaces. Overview

Visit for more.

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

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation

GUI Design. Overview of Part 1 of the Course. Overview of Java GUI Programming

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Lecture 5: Java Graphics

A Tool for Automated GUI Program Grading

Lecture 3: Java Graphics & Events

Graphics User Defined Forms, Part I

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

CSE 331 Software Design & Implementation

Chapter 13 Lab Advanced GUI Applications

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

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

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

Chapter 2. Network Chat

Transcription:

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 window Suitable for simple textual I/O, but not very user-friendly Most of the programs we use daily have Graphical User Interfaces Modern Operating Systems usually have GUI interfaces If we can learn to write programs with GUIs, we have a much larger range of possible programs 2

Interacting with console and GUI programs Console interaction is typically quite limited MS-DOS only has about 100 commands Some command line programs have far fewer Such as projects 1 and 2 GUIs have incredibly large number of possible interactions NetBeans Microsoft Office products 3

Events Wide range of actions with GUI programs Moving the mouse Closing a window Clicking on a button Typing into a dialog box All of these types of interactions have a generic name, event An event is a user interaction with a program with a graphical user interface Setting-up and managing events is a major part of GUI programming 4

Event Handling These events mean little unless our program reacts to them We will need to decide which events having meaning to us, and which are unimportant event handling - The act of responding to an event. 5

How to handle an event Programs respond to events by calling methods Java defines which method responds to which event by declaring Listeners Listener - An object that has the responsibility to respond to an event generated by a user interaction. 6

GUI Program Structure Interaction with a GUI program is controlled by the main event loop This is an infinite loop with a large switch statement When an interaction occurs, the main event loop checks the switch statement for the type of event Inside a case statement for a given event is an indication of which Listener method to call Once the listener method has completed its actions, control goes back to the main event loop In Java, the compiler generates the main event loop. We provide that code that implements the Listener methods. 7

Components and Containers Java GUIs consist of components arranged in containers Component: A single user interface element Button Menu item Text field Container: a GUI element that is used to group together and organize other components At least one container is always needed JFrame Combines content area and menu bar Very common type of top-level container Demo: Button.java 8

Some important methods Button.java frame.getcontentpane().add(button) Adds the JButton to the container Specifically the content pane portion of the container (not the menu bar) frame.pack() Organizes the components that are inside the JFrame Causes the JFrame to change shape to accommodate the JButton JButton would not be visible without this method call frame.setvisible(true) Tells Java to show the GUI on the screen You won t see anything without this method call 9

JLabel Other Important Components Displays textual labels User cannot change the label The program can communicate with the following components to get user input/ineraction JTextField Displays single line of text User can change the text Optionally non-editable JTextArea Displays multiple lines of text Designed for plain text entry only Demo: Label.java, TextField.java, TextArea.java 10

Containers GUI programs don t usually have a single component Containers help us organize multiple components Containers can also contain other containers 11

Heavyweight vs. Lightweight There are two categories of containers Heavyweight Have their own window Should try to have only one per window displayed Carries extra baggage Examples: JFrame Lightweight Must be displayed in a Heavyweight container Examples: JPanel: the content pane of the demo program. This is returned by frame.getcontentpane() in our demo programs. Other examples: JMenuBar: a container itself, contains JMenu containers (which contain JMenuItems) 12

JFrame, JPanel, and JMenuBar (JMenuBar) (JPanel) From page 716 of the Tymann text 13

Properties of Containers Some containers have special properties JSplitPane Used to split a space shared by two components JScrollPane Includes scrollbars for when components are too large for the window JTabbedPane Creates an interface for multiple components using the same space These components are accessed via a row of tabs across the top of bottom of the screen 14

Containers in Excel What containers exist in Excel as shown below? 15

Futility of shaking sticks at Java Components and Containers There are a large number of different components and containers in Swing Most of these are the classes that start with J Say it with me, Read the API Being able to find and learn how to use new methods, components, and containers found in the API documentation is an important skill 16

READ the API Download the documentation so you don t need network access to get to the API http://java.sun.com/j2se/1.5.0/download.jsp Scroll down to J2SE 5.0 Documentation and click on download Unzip the file you downloaded. Open your browser, and choose Open File in the file menu. Then, browse to the docs\api directory inside the directory that you saved the contents of the zip file into. 17