SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Carl Alphonce A Progression of Events.

Slides:



Advertisements
Similar presentations
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Advertisements

Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Agenda –interfaces and realization –type hierarchy –introduction to graphics and event handling.
Things to mention public static void main(String [] args) imports comments –block comments /* … */ –single-line comments // –javadoc comments and tags.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Graphics without NGP The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns that are.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
F27SB2 Software Development 2 Lecture 4: Java GUIs 3.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
GUI programming Graphical user interface-based programming.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
CSE 501N Fall ‘09 20: Event Handling and Inner Classes 17 November 2009 Nick Leidenfrost.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Copyright © Curt Hill First Windows Program GUIs in Eclipse.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/15) MVC and Swing Joel Adams and Jeremy Frens Calvin College.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington More Interfaces.
For (int i = 1; i
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Anonymous Classes An anonymous class is a local class that does not have a name. An anonymous class allows an object to be created using an expression.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
(1) Introduction to Java GUIs Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
CS 415 N-Tier Application Development By Umair Ashraf June 25,2013 National University of Computer and Emerging Sciences Lecture # 4 Web Presentation Patterns.
6-Jan-16 Model-View-Controller. 2 Design Patterns The hard problem in O-O programming is deciding what objects to have, and what their responsibilities.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Creating a GUI Class An example of class design using inheritance and interfaces.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
Event Handling CS 21a: Introduction to Computing I First Semester,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
Lecture 15 Basic GUI programming
Lecture 15.1 Event Delegation.
Modular Event Handling
GUIs and Events Rick Mercer.
CompSci 230 S Programming Techniques
JButton Chapter 11 Lecture 3.
A First Look at GUI Applications
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Event-driven programming for GUI
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
EE 422C Java FX.
Graphical user interface-based programming
Introduction to Event Handling
PC02 Consolidation %WITTY_QUOTE%. PC02 Consolidation %WITTY_QUOTE%
Events, Event Handlers, and Threads
Constructors, GUI’s(Using Swing) and ActionListner
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Carl Alphonce A Progression of Events

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Course CS1 Objects-first Java-based Design patterns introduced

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Background (what students have been taught) object type (class/interface) reference variable –assignment method –parameters –return type

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Experience (what students know how to do)

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering EVENT HANDLING Objective: be able to apply observer pattern for event handling –start with specific case (JButton/ActionListener) –broaden perspective to additional implementations of pattern –goal: students can apply pattern to a novel instantiation of it

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Lesson: Observer Pattern

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Lesson: Observer Pattern Event handling & Observer pattern progression A.show concrete example (fix: observable, observer, update) B.vary the update (same observable, observer) C.vary the concrete observable (the subject) D.vary the concrete observer Observer Subject ActionListenerMouseListenerKeyListener JButton 1, 24 Timer 3 JPanel 56

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example Problem statement –build a button which reacts to a click by printing “Stop that!” Procedure for solving problem 1.create button, add to container 2.create event handler (class implementing ActionListener) 3.override actionPerformed method to print “Stop that!” 4.attach event handler to button Walk through prototype solution Give similar problem Low E

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example: Container Code package sigcse2011; import javax.swing.JButton; import javax.swing.JFrame; public class GUI { public GUI() { JFrame _mainWindow = new JFrame("A simple application"); _mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); _mainWindow.pack(); _mainWindow.setVisible(true); } In course, code to create a JFrame is familiar from previous examples

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example: Container Code package sigcse2011; import javax.swing.JButton; import javax.swing.JFrame; public class GUI { public GUI() { JFrame _mainWindow = new JFrame("A simple application"); _mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton _button = new JButton("Some text on a button"); _mainWindow.pack(); _mainWindow.setVisible(true); } Step #1 Create button, add to container

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example: Container Code package sigcse2011; import javax.swing.JButton; import javax.swing.JFrame; public class GUI { public GUI() { JFrame _mainWindow = new JFrame("A simple application"); _mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton _button = new JButton("Some text on a button"); _mainWindow.getContentPane().add(_button); _mainWindow.pack(); _mainWindow.setVisible(true); } Step #1 Create button, add to container

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example: Event-Handler Code package sigcse2011; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class ButtonEventHandler implements ActionListener { public ButtonEventHandler() { public void actionPerformed(ActionEvent _) { } Step #2 create event handler (class implementing ActionListener)

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example: Event-Handler Code package sigcse2011; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class ButtonEventHandler implements ActionListener { public ButtonEventHandler() { public void actionPerformed(ActionEvent _) { System.out.println("Stop that!"); } Step #3 override actionPerformed method to print message

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example: Container Code package sigcse2011; import javax.swing.JButton; import javax.swing.JFrame; public class GUI { public GUI() { JFrame _mainWindow = new JFrame("A simple application"); _mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton _button = new JButton("Some text on a button"); _button.addActionListener(new ButtonEventHandler()); _mainWindow.getContentPane().add(_button); _mainWindow.pack(); _mainWindow.setVisible(true); } Step #4 attach event handler to button

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering First problem for students Problem statement –build a button which reacts to a click by printing a different message, “That tickles!” Procedure for solving problem 1.create button, add to container 2.create event handler (class implementing ActionListener) 3.override actionPerformed method to print “That tickles!” 4.attach event handler to button

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Worked Example: Event-Handler Code package sigcse2011; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class ButtonEventHandler implements ActionListener { public ButtonEventHandler() { public void actionPerformed(ActionEvent _) { System.out.println(”That tickles!"); } Step #3 override actionPerformed method to print message

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Second problem for students Problem statement –build a button which alternates between the two messages More involved example –instance variables –constructor –actionPerformed Procedure for solving problem 1.create button, add to container 2.create event handler (class implementing ActionListener) 3.solution steps a)declare instance variables for two messages, b)define constructor to initialize the variables c)override actionPerformed method to alternate between two messages (“swap” code, familiar to students from earlier) 4.attach event handler to button

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering package sigcse2011; // imports not shown to save space public class Swapper implements ActionListener { private String _current; private String _next; public Swapper(String a, String b) { _current = a; _next = b; public void actionPerformed(ActionEvent e) { System.out.println(_current); String tmp = _current; _current = _next; _next = tmp; } Still low E: Swap code done earlier in course too.

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Third problem for students Problem statement –build a button which changes title of JFrame (alternating between two different titles) More involved example –instance variables –constructor –actionPerformed –call setTitle on JFrame Procedure for solving problem 1.create button, add to container 2.create event handler (class implementing ActionListener) 3.solution steps a)declare needed instance variables b)define constructor to initialize instance variables c)override actionPerformed method to alternate between two titles (call setTitle on JFrame object) 4.attach event handler to button

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Observing more broadly Vary subject with ActionListener –Timer / ActionListener Vary observer –Timer w/ActionListener –JButton w/MouseListener –JPanel w/MouseListener –JPanel w/KeyListener –etc.

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Summary: “Faded guidance” Worked example Almost identical exercise (a partially-worked exercise) Similar exercise (less guidance, but same basic framework) Examples of later exercises –Timer w/ActionListener –JButton w/MouseListener –JPanel w/MouseListener –JPanel w/KeyListener Students eventually integrate in larger project

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Schedule 7:00 Introduction and Background (Michael) 7:20 Example 1: Presentation and Discussion (Carl) 7:40 Group work: Discuss/work out example in small groups 8:10 Present/Discuss a group work example 8:30 Refreshment break 8:50 Example 2: Presentation and Discussion (Dale) 9:10 Group work: Discuss/work out example in small groups 9:40 Present/Discuss a group work example 10:00 Wrap up

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Possible exercise: Objective: be able to correctly choose between inheritance and composition Assumptions: –inheritance – extension –composition – restriction Case study: java.util.Stack

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Possible exercise: Objective: be able to apply iterator pattern to process elements of a Collection –use existing iterator of Collection

SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Possible exercise: Objective: be able to apply iterator pattern to in new situation –implement the iterator pattern for some novel use –example: define an iterator to read characters from a file