Presentation is loading. Please wait.

Presentation is loading. Please wait.

Teaching Object-Oriented Concepts Through GUI Programming Jesse M. Heines Martin J. Schedlbauer Dept. of Computer Science Univ. of Massachusetts Lowell.

Similar presentations


Presentation on theme: "Teaching Object-Oriented Concepts Through GUI Programming Jesse M. Heines Martin J. Schedlbauer Dept. of Computer Science Univ. of Massachusetts Lowell."— Presentation transcript:

1 Teaching Object-Oriented Concepts Through GUI Programming Jesse M. Heines Martin J. Schedlbauer Dept. of Computer Science Univ. of Massachusetts Lowell Eleventh Workshop on Pedagogies and Tools for the Teaching and Learning of Object Oriented Concepts ECOOP, Berlin, Germany, July 30, 2007

2 2 The OOP Teaching Field The Starting Line Introducing OO concepts Working OO examples CS 1 and CS 2

3 3 The OOP Teaching Field The Starting Line Introducing OO concepts Working OO examples CS 1 and CS 2 The Finish Line Applying OO concepts Solving programming problems Advanced courses

4 4 The OOP Workshop Field 3 papers dealing with “Beginners,” “CS1& 2,” and “Novice Programmers” Schmolitzky Späh and Schmolitzky Ma, Ferguson, Roper, and Wood 2 papers on “Objects First” Ehlert and Schulte Shümmer and Kösters 2 papers on applying OO concepts Hadar and Hadar Heines and Schedlbauer

5 5 The OOP Cognitive Field Our experience is that regardless of how and when OO concepts are introduced, students have trouble applying those concepts in project- based courses Why? Lack of experience with large programs The real benefits of OO are difficult to see in the small programs typically used as examples Consequently, OO concepts do become part of the student’s cognitive field and programming style “I need an object” instead of “I need a routine”

6 6 OOP in Class vs. at Work Small programs Large programs 100s of lines 1000s of lines Standalone Hierarchies built programsusing previous code Single files Linked modules Coded solo Coded in teams Code is never Documentation is documented absolutely required Never reused Reused repeatedly By self or others By self and others

7 7 OOP and GUI Programming Excellent examples of class hierarchies Java Swing and.NET Students learn just by browsing Excellent tools for large programs NetBeans, Eclipse, Visual Studio, BlueJ Form designers and code generators (Mostly) excellent documentation Using the API is a critical skill Creating an API is even more critical Model for student-created documentation

8 8 OOP and GUI Programming Inclusion of design patterns Observers = MVC architecture & listeners Strategies = layout managers Composites = UI components & containers Decorators = scroll panes and borders Singletons = calendars Factories = borders Commands = menus

9 9 Lecture: Building Bridges Problem: Set the text of the root node of an existing JTree control Subproblem: There is no method of the JTree object to set a node’s text Solution: Build a bridge from the control’s model This requires understanding relationships between objects

10 10 Lecture: Building Bridges Step 1: Create a new root node DefaultMutableTreeNode root = new DefaultMutableTreeNode( "New Text" ); Step 2: Get reference to the tree model TreeModel myTM = myJTree.getModel(); Step 3: Cast the tree model reference DefaultTreeModel myDTM = (DefaultTreeModel) myTM; Step 4: Set the tree root myDTM.setRoot( root );

11 11 Lecture: Building Bridges Note that this is a very practical problem with code generators For example, NetBeans always calls the default JTree constructor myJTree = new JTree(); One could write “post-creation” code to set the root node text, but this is a static change, not a dynamic one Thus, this problem forces students to use the API and think about the objects involved and their relationships

12 12 Assignment: Object Comm. Problem: Pass data from a custom dialog box ( JFrame ) to its parent class Subproblem: Default member variable access method is private Solutions: Change access method Use Component. getParent() method Pass reference to parent in overloaded constructor

13 13 Exam: FocusTraversalPolicy Human Factors Issues  Why is it important to worry about what happens when the user presses the Tab key? Because an application in which pressing the Tab key causes focus to jump all over the place is confusing to the user and looks unprofessional.

14 14 Exam: FocusTraversalPolicy Use of the API  One way to set focus to a component is call the grabFocus() method. What class is grabFocus() a member of? JComponent

15 15 Exam: FocusTraversalPolicy Deprecated Code  The documentation says that “client code” should not use method grabFocus(). What method does the API recommend using instead of grabFocus() ? requestFocusInWindow()

16 16 Exam: FocusTraversalPolicy Class Relationships  A better way to implement your own focus traversal policy is to create a class that extends the built-in FocusTraversalPolicy class. Why must this be a separate class from your application’s main class, which typically extends JFrame ? Because a class can only extend one other class.

17 17 Exam: FocusTraversalPolicy Class Relationships  We have seen three ways to create an instance of a class that you might use for your own focus traversal policy. Name two that you might use to create a FocusTraversalPolicy class for use in your application. Create an anonymous class. Create a named inner class. Create a separate external class.

18 18 Exam: FocusTraversalPolicy Class Relationships and Use of API  Look up FocusTraversalPolicy and its methods in the Java API. You will see that five of the six methods are abstract. What implication does this have for the class that you create that is derived from the built-in FocusTraversalPolicy class? You must implement each of the abstract methods or you will not be able to instantiate your class.

19 19 Exam: FocusTraversalPolicy Application of the Concept  Once you have defined a focus traversal policy, you must associate it with your JFrame. What method performs this function, and what class is that method a member of? setFocusTraversalPolicy in class java.awt.Container

20 20 Additional Information Course websites Lecture notes, assignments, and examples teaching.cs.uml.edu/~heines See courses 91.461 and 91.462 on the Teaching page Contact us heines@cs.uml.edu mschedlb@cs.uml.edu Our websites http://www.cs.uml.edu/~heines http://www.cs.uml.edu/~mschedlb

21 21 Jesse M. Heines, Ed.D. Martin J. Schedlbauer, Sc.D. Dept. of Computer Science Univ. of Massachusetts Lowell Thank You


Download ppt "Teaching Object-Oriented Concepts Through GUI Programming Jesse M. Heines Martin J. Schedlbauer Dept. of Computer Science Univ. of Massachusetts Lowell."

Similar presentations


Ads by Google