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

Similar documents
Graphical User Interfaces (GUIs)

CS 251 Intermediate Programming GUIs: Components and Layout

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

Original GUIs. IntroGUI 1

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

2110: GUIS: Graphical User Interfaces

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Graphic User Interfaces. - GUI concepts - Swing - AWT

Window Interfaces Using Swing Objects

Introduction to the JAVA UI classes Advanced HCI IAT351

MIT AITI Swing Event Model Lecture 17

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

SENG 310: Human Computer Interaction. Lecture 2. The history of Human Computer Interaction

Window Interfaces Using Swing Objects

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

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!

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

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

AP CS Unit 11: Graphics and Events

Lecture 5: Java Graphics

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

Graphical User Interface (GUI)

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

Swing from A to Z Some Simple Components. Preface

Graphical User Interfaces

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

Java. GUI building with the AWT

Chapter 12 GUI Basics

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

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Graphical User Interfaces. Comp 152

CS11 Java. Fall Lecture 4

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

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

PIC 20A GUI with swing

Swing. By Iqtidar Ali

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

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

Packages: Putting Classes Together

CS 11 java track: lecture 3

Programming Languages and Techniques (CIS120e)

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

Programming Languages and Techniques (CIS120)

Swing: Building GUIs in Java

Swing: Building GUIs in Java

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

Basicsof. JavaGUI and SWING

Jonathan Aldrich Charlie Garrod

CS11 Java. Fall Lecture 3

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

Chapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved.

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

Graphical interfaces & event-driven programming

(Incomplete) History of GUIs

Lecture 3: Java Graphics & Events

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

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Part I: Learn Common Graphics Components

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

CompSci 230 S Programming Techniques. Basic GUI Components

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

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

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

COMPSCI 230. Software Design and Construction. Swing

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

Class 30: Language Construction

Object-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09

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

SD Module-1 Advanced JAVA

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

SD Module-1 Advanced JAVA. Assignment No. 4

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

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

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Systems Programming Graphical User Interfaces

Lecture 18 Java Graphics and GUIs

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

Chapter 12 GUI Basics. Motivations. The design of the API for Java GUI programming

Introduction. Introduction

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

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

Programming Languages and Techniques (CIS120)

Design of Graphical User Interfaces

CHAPTER 2. Java Overview

Swing - JButton. Adding buttons to the main window

Graphical User Interface (GUI)

Class 16: The Swing Event Model

Programming graphics

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

Programming Languages and Techniques (CIS120)

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

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

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

CS Exam 1 Review Suggestions

Building Graphical User Interfaces. GUI Principles

CS 2113 Software Engineering

Object-Oriented Technology. Rick Mercer

Transcription:

cs2220: Engineering Software Class 22: Graphical User Interfaces Plan for Today History of Interactive Computing Building GUIs in Java Xerox Star Fall 2010 UVa David Evans Design Reviews this week! Univac 1956 IBM 705 (1954) Sketchpad Ivan Sutherland, 1963 (PhD thesis supervised by Claude Shannon) Interactive drawing program, light pen Computer as Clerk : Augmenting Human Intellect In such a future working relationship between human problemsolver and computer 'clerk, the capability of the computer for executing mathematical processes would be used whenever it was needed. However, the computer has many other capabilities for manipulating and displaying information that can be of significant benefit to the human in nonmathematical processes of planning, organizing, studying, etc. Every person who does his thinking with symbolized concepts (whether in the form of the English language, pictographs, formal logic, or mathematics) should be able to benefit significantly. Douglas Engelbart, Augmenting Human Intellect (1962) http://www.cl.cam.ac.uk/techreports/ucam-cl-tr-574.pdf

Engelbart s Demo (1968) First Mouse Papers and folders Videoconferencing Email Hypertext Collaborative editing Doug Engelbart s Mouse (1968) http://www.sri.com/news/storykits/1968video.html We see the quickest gains emerging from (1) giving the human the minute-by-minute services of a digital computer equipped with computerdriven cathode-ray-tube display, and (2) developing the new methods of thinking and working that allow the human to capitalize upon the computer s help. By this same strategy, we recommend that an initial research effort develop a prototype system of this sort aimed at increasing human effectiveness in the task of computer programming. Claude Shannon, Theseus (1950) Medal of Technology 2000 Douglas Engelbart, Augmenting Human Intellect (1962) Xerox Alto Apple Lisa 1983 Xerox PARC, 1973

Lisa Interface Any real progress since then? http://www.guidebookgallery.org/screenshots/lisaos10 Mac OSX Designing GUIs Nintendo Wii Microsoft Kinect Requires lots of skill Psychology, Cognitive Science User studies Good taste Read Donald Norman s and Ed Tufte s books Look at what SIS does and do the opposite! Microsoft Surface Building GUIs Like all Programming Encapsulation, Abstraction, Specification Testing: especially hard Unique-ish Aspects Event-Driven (network programming also like this) Multi-Threaded (network, others) Huge APIs Model-View-Controller Model: domain data and logic View: presents model Invented at PARC in 1970s (Smalltalk) Controller: receives input and alters model Goal: abstraction separate display from model separate control interface

Java GUI Toolkits java.lang.object java.awt.component Frames Main windows are JFrame objects java.awt.container java.awt.window AWT Abstract Window Toolkit Looks like Java Swing (since JDK 1.2) real reason for Swing coming later... java.awt.frame javax.swing.jframe Window Title JFrame Methods // inherited from java.awt.window public void pack() EFFECTS: Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. // inherited from java.awt.component public void setvisible(boolean b), display EFFECTS: If b, shows this. Otherwise, hides this. import javax.swing.*; Swing Application //Create and set up the window. public static void main(string args[]) { javax.swing.swingutilities.invokelater(new Runnable() { publicvoidrun() { showgui(); ); Based on Sun s Swing tutorials: http://java.sun.com/docs/books/tutorial/uiswing/learn/example1.html Adding to a Frame public java.awt.container getcontentpane() EFFECTS: Returns the contentpane object for this. in java.awt.containter: public Component add(component c) EFFECTS: Appends cto the end of this container. Container Window What can you add? Component JLabel in java.awt.container: public Component add(component c) JComponent AbstractButton Frame JPanel JButton JFrame...and hundreds(?) more subtypes in API

GUIs and Subtyping In the process of making the Sketchpad system operate, a few very general functions were developed which make no reference at all to the specific types of entities on which they operate. These general functions give the Sketchpad system the ability to operate on a wide range of problems. The motivation for making the functions as general as possible came from the desire to get as much result as possible from the programming effort involved. For example, the general function for expanding instances makes it possible for Sketchpad to handle any fixed geometry subpicture. The rewards that come from implementing general functions are so great that the author has become reluctant to write any programs for specific jobs. Each of the general functions implemented in the Sketchpad system abstracts, in some sense, some common property of pictures independent of the specific subject matter of the pictures themselves. Ivan Sutherland, Sketchpad: a Man-Machine Graphical Communication System, 1963 (major influence on Alan Kay inventing OOP in 1970s) Components in Sketchpad Adding Components Layout import javax.swing.*; //Create and set up the window. content.add(new JLabel ("Yo!")); content.add(new JButton ("Click Me")); public static void main(string args[]) {... What happened to Yo!? // in Container: public void setlayout(layoutmanager mgr) EFFECTS: sets the layout manager to mgr for this container. LayoutManager Implementations LayoutManager (interface) import javax.swing.*; import java.awt.flowlayout; Adding Components FlowLayout BoxLayout...about 30 more in API! BorderLayout //Create and set up the window. content.add(new JLabel ("Yo!")); content.add(new JButton ("Click Me")); http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

import javax.swing.*; import java.awt.*; Don t try this at home? //Create and set up the window. content.add(frame); Exception in thread "AWT-EventQueue-0" java.lang.illegalargumentexception: adding container's parent to itself Making Buttons Do Something public void addactionlistener(actionlistenerl) EFFECTS: Adds an ActionListenerl to the button. java.awt.event interface ActionListener extends EventListener { void actionperformed(actionevent e) EFFECTS: anything Note: this method is called when an action occurs. importjavax.swing.*; import java.awt.*; import java.awt.event.*; class ButtonListener implements ActionListener{ System.out.println ("Got a button press: + e); content.add(new JLabel("Yo!")); JButton button = new JButton("Click Me"); button.addactionlistener(new ButtonListener()); content.add(button); Action Events Got a button press: java.awt.event.actionevent[action_performed,cmd=click Me, when=1163559916342,modifiers=button1] on javax.swing.jbutton[,27,5,82x26,alignmentx=0.0,alignmenty=0.5, border=javax.swing.plaf.borderuiresource$compoundborderuiresource@29ab3e,flags=296,maximumsize=,minimumsize=, preferredsize=,defaulticon=,disabledicon=,disabledselectedicon=, margin=javax.swing.plaf.insetsuiresource[top=2,left=14,bottom=2,right=14],paint Border=true,paintFocus=true, pressedicon=,rolloverenabled=true,rollovericon=,rolloverselectedicon=, selectedicon=,text=click Me,defaultCapable=true] class ButtonListener implements ActionListener { if(e.getactioncommand().equals ("On")) { System.out.println("On!"); else if(e.getactioncommand().equals("off")) { System.out.println("Off!"); else{ System.out.println("Unrecognized button press!"); ButtonListener bl = new ButtonListener(); JButton onbutton = new JButton("On"); onbutton.addactionlistener(bl); content.add(onbutton); JButton offbutton = new JButton("Off"); offbutton.addactionlistener(bl); content.add(offbutton); Activating/Deactivating // in JButton: void setenabled(boolean b) EFFECTS: If b, enables this. Otherwise, disables this.

class ButtonListener implements ActionListener { if(e.getactioncommand().equals ("On")) { System.out.println("On!"); else if(e.getactioncommand().equals("off")) { System.out.println("Off!"); else{ System.out.println("Unrecognized button press!"); ButtonListener bl = new ButtonListener(); JButton onbutton = new JButton("On"); onbutton.addactionlistener(bl); content.add(onbutton); JButton offbutton = new JButton("Off"); offbutton.addactionlistener(bl); content.add(offbutton); Can we make clicking On enable the Off button (and vice versa)? Inner Classes Added to JDK 1.1 (no JavaVMsupport) Define a classinside a scope It has access to variables in the containing scope including private instance variables! What deficiency in Java is this making up for? No lambda! There is no way in Java to dynamically construct a procedure. Inner classes provide a more cumbersome, less expressive (but easier to typecheck statically) substitute. final JButton onbutton = new JButton("On"); final JButton offbutton = new JButton("Off"); class ButtonListener implements ActionListener{ if(e.getactioncommand().equals ("On")) { onbutton.setenabled(false); offbutton.setenabled(true); else if(e.getactioncommand().equals("off")) { onbutton.setenabled(true); offbutton.setenabled(false); ; ButtonListener bl = new ButtonListener(); onbutton.addactionlistener(bl); content.add(onbutton); Anonymous Classes No need to give inner classes names! var= new Superclass( ) { // override methods here final JButton onbutton = new JButton("On"); final JButton offbutton = new JButton("Off"); ActionListener bl = new ActionListener() { if(e.getactioncommand().equals ("On")){ onbutton.setenabled(false); offbutton.setenabled(true); else if(e.getactioncommand().equals("off")) { onbutton.setenabled(true); offbutton.setenabled(false); What is the actual type of bl? ; onbutton.addactionlistener(bl); content.add(onbutton); Not just Buttons Component JComponent AbstractButton JToggleButton JButton JCheckBox JRadioButton http://java.sun.com/docs/books/tutorial/uiswing/components/button.html

Awkward design: JMenu is a button action is to popup JPopupMenu JMenu contains a list of JMenuItem s Why is JMenu a subtype of JMenuItem? JMenu JMenuItem AbstractButton JButton JRadioButtonMenuItem JMenuBar Menus Too... JComponent JCheckboxMenuItem http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html JPopupMenu Concurrency in GUIs Responsiveness of GUI depends on multiple threads Swing thread types: Initial threads(start program) One event dispatch thread(all event-handling code) Worker threads(do time-consuming tasks in background) Swingframework does most of the work programmer doesn t need to create threads Event Dispatch Worker Threads Why is there only one event dispatch thread? Hint: did we need to synchronize? One event thread means all compute-intensive work should be done in worker threads. (Otherwise interface freezes like ps4 ImageChop). class javax.swing.swingworker<t,v> Create a background thread to do computeintensive tasks http://download.oracle.com/javase/6/docs/api/javax/swing/swingworker.html (added to JDK 1.6) Charge GUI APIs are subtypingand inheritance paradises, concurrency morasses GUI APIs are huge and complex Java s is especially complex because of AWT + Swing, and portability Creating a simplergui requires more complex programming