CSC207H: Software Design Lecture 11

Similar documents
Graphics. Lecture 18 COP 3252 Summer June 6, 2017

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

Sri Vidya College of Engineering & Technology

CS 251 Intermediate Programming GUIs: Components and Layout

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

GUI in Java TalentHome Solutions

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

Laying Out Components. What is Widget Layout?

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!

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

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

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

Frameworks. CS151 Chris Pollett Oct. 26, 2005.

Programming graphics

Programming Mobile Devices J2SE GUI

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

The AWT Package, An Overview

Java Programming Lecture 6

Essential Series. Springer-Verlag London Ltd.

Output in Window Systems and Toolkits

Introduction to the JAVA UI classes Advanced HCI IAT351

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Java Applets / Flash

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

Graphical User Interface (GUI)

CSC207H: Software Design Lecture 6

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

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

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

Unit 7: Event driven programming

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Graphical User Interface (GUI)

Chapter 12 Advanced GUIs and Graphics

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

Graphics and Painting

Week 5: Images & Graphics. Programming of Interactive Systems. JavaFX Images. images. Anastasia Bezerianos. Anastasia Bezerianos

Human-Computer Interaction IS4300

Mobile MOUSe JAVA2 FOR PROGRAMMERS ONLINE COURSE OUTLINE

Graphics and Java 2D Introduction OBJECTIVES. One picture is worth ten thousand words.

G51PRG: Introduction to Programming Second semester Applets and graphics

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA. Assignment No. 4

Graphical User Interfaces. Comp 152

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

John Cowell. Essential Java Fast. How to write object oriented software for the Internet. with 64 figures. Jp Springer

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

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

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

PIC 20A GUI with swing

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

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

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill

Human-Computer Interaction IS4300

Layout. Dynamic layout, Swing and general layout strategies

How to draw and create shapes

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

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

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

Object Oriented Design & Patterns. Part 1

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

Basicsof. JavaGUI and SWING

HTML p. 1 Introduction to HTML p. 1 Getting Started p. 1 The Structure of an HTML Page p. 1 HTML Basics p. 3 The Weather Forecast Page p.

Class Meeting 05 (Lecture 04) Objectives for this class meeting. Conduct vote on basic style of game for class project

Introduction to Java Programming

Part I: Learn Common Graphics Components

Packages: Putting Classes Together

Java. GUI building with the AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT

User interfaces and Swing

Windows and Events. created originally by Brian Bailey

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

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

Introduction to Java Programming

CS11 Java. Fall Lecture 4

Objectives This tutorial demonstrates how to use feature objects points, arcs and polygons to make grid independent conceptual models.

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

CS 349 Midterm Exam Spring 2014

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

Graphical User Interfaces (GUIs)

Lecture 5: Java Graphics

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. 2.4 Event Dispatch 1

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. Event Architecture. A pipeline: Event Capture

TWO-DIMENSIONAL FIGURES

Lecture 18 Java Graphics and GUIs

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Event Dispatch. Dispatching events to windows and widgets.

BASICS OF GRAPHICAL APPS

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

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

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Motic Images Plus 3.0 ML Software. Windows OS User Manual

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

UI Software Organization

Introduction p. 1 Java Features p. 2 Java Expansion p. 4 Getting, Setting Up, and Using Java p. 5 The Java Language p. 5 Java Swing Components p.

Java - Applets. public class Buttons extends Applet implements ActionListener

Containers and Components

cs Java: lecture #5

Transcription:

CSC207H: Software Design Lecture 11 Wael Aboelsaadat wael@cs.toronto.edu http://ccnet.utoronto.ca/20075/csc207h1y/ Office: BA 4261 Office hours: R 5-7 Acknowledgement: These slides are based on material by Prof. Karen Reid (University of Toronto), Prof. Chris North (Virginia Tech), and Prof. Birchfield (Clemson Univ.)

Software house: what happens inside? Understand the requirements Design the program Write the program Test the program Write Documentation Package/Sell/Market program Project Managers Group Architects Group Development/Programmer Group QA Group Documentation Group Marketing/Sales Group

Program Architecture GUI Layer Logic Layer Data Layer 3 separate teams Different skill sets Different quality criteria

GUI Layer

Typical command line program Non-interactive Linear execution program: main() { code; code; code; code; code; code; code; code; code; code; code; code; }

Interactive command line program program: User input commands main() { decl data storage; initialization code; Non-linear execution Unpredictable order Much idle time } loop { get command; switch(command) { command1: code; command2: code; } }

Interactive Graphical User Interface

Combo Box Interactive Graphical User Interface What s make a GUI GUI? Windows Selection controls: drop-downs, radio-buttons, check boxes, menus,.. Activation controls: buttons, icons Input controls: text fields, text areas Structure information visually: lists, grids, trees, labels Label Text field Check Box Radio Button Button

Input Events Operating System OS Event Queue Keyboard Driver Mouse Driver

Input Events Operating System OS Event Queue Keyboard Driver Mouse Driver

Input Events Operating System OS Event Queue Keyboard Driver Mouse Driver

Input Events: programming model 1. Use an infinite loop to keep checking the event queue 2. When you find the event you are interested in, execute the relevant code Your program Operating System OS Event Queue Keyboard Driver Mouse Driver

Event loop pseudo code int main() { return WinMain(); } WinMain() { while (true) { // loop forever, waiting for an event if (event_exists) { //there is an event, figure out what to do if (event == keydown_a) display( user pressed the A key ); else if (event == window_resize) display( window resized ); else if (event == repaint) display( need to repaint window ); else if (event == keydown_escape) exit_program(); } } }

Input Events: programming model Use an intermediate GUI library: specify specific events you are interested in. specify method/function in your code that should be called when an event you are interested in is received Your program GUI Library Operating System OS Event Queue Keyboard Driver Mouse Driver

Observer Pattern Subject attach (Observer) detach (Observer) Notify () Concrete Subject GetState() SetState() subjectstate observers For all x in observers{ x Update(); } subject Observer Update() Concrete Observer Update() observerstate observerstate= subject getstate();

Java GUI program Java program: Event loop automatic in separate program Class{ main() { decl data storage; initialization code; } create GUI objects; register listeners; listener1() { do stuff; } listener2() { do stuff; }

Creating a GUI in Java 1. import Java libraries - swing, awt 2. construct a frame object 3. declare widgets - instance variables 4. choose, construct and set the layout in a container 5. add widgets to container 6. attach listeners to widgets Order doesn t matter here 7. implement the listeners

Frames vs. Dialogs Frame Dialog

AWT Class Hierarchy: containers

AWT Class Hierarchy

AWT Class Hierarchy: event classes

Event Types & Sources Source Event Type User Action Object Generated Click a button Button ActionEvent Click a check box CheckBox/radio ItemEvent, ActionEvent Press return on a text field TextField ActionEvent Window opened, closed, etc. Window WindowEvent Mouse pressed, released, etc. Component MouseEvent Key released, pressed, etc. Component KeyEvent

Java Coordinate System x (0, 0) X Axis Y Axis y Y Axis (x, y) Java Coordinate System Traditional Coordinate System (0, 0) X Axis (0,0) (width,0) (0,height) (width, height)

Component Hierarchy & Containers You must add components to a container Each component has its own subwindow Subwindow = rectangular area within parent component Has own coordinate system Button (0,0) Panel (0,0) Button (w b, h b ) (w p, h p )

Example 1 Button Button TextArea

Layout Manager Heuristics null FlowLayout GridLayout none, programmer sets x,y,w,h Left to right, Top to bottom BorderLayout n CardLayout GridBagLayout w c e One at a time JButton s

Example 2: Layout Manager

Example 3

AWT Class Hierarchy: helper classes

Graphics Handle The Graphics object g is created automatically by the JVM for every visible GUI component. This object controls how information is drawn. You can use various drawing methods defined in the Graphics class to draw strings and geometric figures.

Painting & Screen Pixels

Color All the components we have examined have methods to set the background and foreground colours using setbackground(color) and setforeground(color) The Color object allows various ways of specifying a colour There are a set of predefined colours Color.blue etc You can specify the RGB values for the colour Color c=new Color(10,10,10); Red, green,blue

Graphics Primitives Point (x,y) Line (pt1,pt2) PolyLine (pt list) Arc Oval (pt, w,h) Rectangle (pt, w,h) RoundRectangle Polygon (pt list) Image (file, x,y) Text (string, x,y) Draw label Fill

Color Font Stroke attributes: Graphics Attributes Line width, dash, end caps, joins, miter Paint attributes: Color, gradient, texture Composite: Blending Transforms: Translate, rotate, flip, shear, scale

Painting in Java import java.awt.graphics public paint (Graphics graphic ) { // put your painting code here }

Drawing Geometric Figures and Strings Drawing Lines, e.g. graphics.drawline(50,50,100,200); Drawing Rectangles, e.g. graphics.drawrect(20,20,100,50) Drawing Ovals, e.g. graphics.drawoval(30,30,50,50); Drawing Strings, e.g. graphics.drawstring(hello, 50,50);

Example 4