Graphical User Interfaces (GUIs)

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

(Incomplete) History of GUIs

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

Swing from A to Z Some Simple Components. Preface

Swing. By Iqtidar Ali

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

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

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

Graphic User Interfaces. - GUI concepts - Swing - AWT

Swing from A to Z Using Focus in Swing, Part 2. Preface

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!

EPITA Première Année Cycle Ingénieur. Atelier Java - J5

Graphical User Interface (GUI)

Introduction to the JAVA UI classes Advanced HCI IAT351

Window Interfaces Using Swing Objects

Lecture 5: Java Graphics

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

CS11 Java. Fall Lecture 4

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Systems Programming Graphical User Interfaces

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

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

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Swing: Building GUIs in Java

Swing: Building GUIs in Java

CS 251 Intermediate Programming GUIs: Components and Layout

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

Java: Graphical User Interfaces (GUI)

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

Java Swing Introduction

Part I: Learn Common Graphics Components

Graphical User Interface (GUI)

Windows and Events. created originally by Brian Bailey

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

Lecture 3: Java Graphics & Events

Lecture 9. Lecture

CS 4300 Computer Graphics

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

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

Window Interfaces Using Swing Objects

Graphical User Interfaces. Comp 152

Original GUIs. IntroGUI 1

Java. GUI building with the AWT

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

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

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA. Assignment No. 4

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

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert

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

Jonathan Aldrich Charlie Garrod

Java IDE Programming-I

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

User interfaces and Swing

Agenda. Container and Component

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

Sketchpad. Plan for Today. Class 22: Graphical User Interfaces IBM 705 (1954) Computer as Clerk : Augmenting Human Intellect

Chapter 12 Advanced GUIs and Graphics

MODEL UPDATES MANIPULATES USER

Introduction. Introduction

Basicsof. JavaGUI and SWING

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

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

SINGLE EVENT HANDLING

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

Programming Language Concepts: Lecture 8

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

Example: CharCheck. That s It??! What do you imagine happens after main() finishes?

CSC207 Week 4. Larry Zhang

Sri Vidya College of Engineering & Technology

Object Oriented Design & Patterns. Part 1

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

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

H212 Introduction to Software Systems Honors

G51PRG: Introduction to Programming Second semester Applets and graphics

MVC: Model View Controller

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

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

Graphical interfaces & event-driven programming

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

CS11 Java. Fall Lecture 3

Packages: Putting Classes Together

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

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

CS415 Human Computer Interaction

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

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

Come & Join Us at VUSTUDENTS.net

CS 2113 Software Engineering

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

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

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

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

ASSIGNMENT NO 14. Objectives: To learn and demonstrated use of applet and swing components

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.

Transcription:

CMSC 132: Object-Oriented Programming II Graphical User Interfaces (GUIs) Department of Computer Science University of Maryland, College Park

Model-View-Controller (MVC) Model for GUI programming (Xerox PARC 78) Separates GUI into 3 components Model application data View visual interface Controller user interaction Model View Controller

MVC Model of GUI Design Model Should perform actual work Should be independent of the GUI But can provide access methods Controller View Lets user control what work the program is doing Design of controller depends on model Lets user see what the program is doing Should not display what controller thinks is happening (base display on model, not controller)

Programming Models Normal (control flow-based) Programming Approach Start at main() Continue until end of program or exit() Event-driven Programming Event Action or condition occurring outside normal flow of control of program (e.g., mouse clicks, keyboard input, etc.) Unable to predict time & occurrence of event Approach Start with main() Define system elements and register event listeners Await events (& perform associated computation) 4

Event Handling in Action Registered Event Handlers Events e1 e3 e2 Can handle an event of type e1 E1 E1 E2 E2 E3 E3 E4 E4 E5 E5 E6 E6 E7 E7 E8 E8 Execution Environment 5

GUIs are Event-Driven Software GUI User Events User events invoke event handlers E3 newdocactionperformed (java.awt.event.actionevent evt) E4 E5 filesaveactionperformed (java.awt.event.actionevent evt) E2 changefontsizeactionperformed (java.awt.event.actionevent evt) E1 Event Handlers 6

GUIs in Java Java Application Swing AWT Java 2D Java Runtime Environment Desktop Java Graphics APIs: From Filthy Rich Clients by Chet Haase and Romain Guy, Chap1, Page 12 ISBN-978-0-13-241393-0 Book Web Site: http://www.filthyrichclients.org/

GUIs in Java AWT (Abstract Window Toolkit) (java.awt.*) First graphical user interface toolkit for Java Old GUI framework for Java (Java 1.1) Reliance on native system libraries Platform independence problems Responsible for input event mechanisms Java 2D Graphics Library of Java Introduced in JDK 1.2 Basics and advance drawing operation, image manipulation, and drawing Handles Swing s Rendering operations Swing (javax.swing.*) GUI framework first introduced in JDK 1.2 Includes AWT features plus many enhancements Pure Java components (no reliance on native code) Pluggable look and feel architecture Some of this material is from Filthy Rich Clients (see reference in previous slide). 8

Steps for Creating a GUI in Java (Step 1) Define a container to hold components (e.g., JFrame, Japplet) (Step 2) Add GUI components to the container (JButton, JTextField, ) Use layout manager to determine positions (Step 3) Add actions to GUI Add (register) event listeners to GUI components Usually one event listener class per widget (item user sees) Inner class usually utilized to implement listener Example of Java listeners & Actions Causing Event ActionListener clicking button in GUI At run time Java generates event object when events occur Java then passes event object to event listener (Step 4) Schedule the GUI processing in the EDT (Event-Dispatching Thread)

Schedule GUI Processing in EDT What is a thread? Event Dispatching Thread (EDT) is a background thread to process GUI events These events are mainly updates that Cause components to redraw themselves Represent input events Swing uses a single-threaded painting model Event Dispatching Thread is the only valid thread for updating GUI components Avoid updating GUI components from other threads (a source of bugs) Java Code that allows current thread to execute GUI code in dispatching thread public static void main(string[] args) { javax.swing.swingutilities.invokelater(new Runnable() { public void run() { createanddisplaygui(); // actually creates GUI } }); }

Java Layout Manager Definition Arrangement of GUI components in container Layout manager Entity translating layout specifications into actual coordinates at runtime, depending on conditions Examples FlowLayout (lays out component from left to right) BorderLayout (designates portions of the container as North, South, East, West, and Center)

Examples Main Examples eventhandlingintro singleclassborderlayout timer textfilereadersingleclass (illustrates MVC) Additional Examples textfilereaderfont textfilerreaderfontslider textfilereaderfont tables

Beware of Long Computations in Swing Swing uses a single-threaded model Long computations in the EDT freezes the GUI Usually you place the computation is a separate thread We will talk about this matter once we have covered threads

Additional Resources Javadoc from the JDK Swing tutorial http://java.sun.com/docs/books/tutorial/uiswing/components/ Filthy Rich Clients http://filthyrichclients.org/