CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 9: Oct 18-22, 2010 Aditya Mathur Department of Computer Science Purdue.

Slides:



Advertisements
Similar presentations
Chapter 10 Introduction to Arrays
Advertisements

Computer Science 209 Graphics and GUIs. Working with Color The class java.awt.Color includes constants for typical color values and also supports the.
Object Oriented Programming Lecture 7: Algorithm animation using strategy and factory patterns, The Adapter design pattern
CS 180 Problem Solving and Object Oriented Programming Spring 2011 February 16, 2011 Aditya Mathur Department of Computer Science Purdue University West.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 13: Nov 14-18, 2011 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 10: Oct 24-28, 2011 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 8: Oct 10-14, 2011 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 4: September 12-16, 2011 Aditya Mathur/Tim Korb Department of Computer.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 13: Nov 15-19, 2010 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 16: Dec 6-10, 2010 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 9: Oct 17-21, 2011 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for the Final Lecture Dec 7, 2011 Aditya Mathur Department of Computer Science Purdue.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 3: September 5-9, 2011 Aditya Mathur Department of Computer Science Purdue.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Arrays Recitation – 10/(9,10)/2008 CS 180 Department of Computer Science, Purdue University.
Chapter 81 Exception Handling Chapter 8. 2 Reminders Project 5 due Oct 10:30 pm Project 3 regrades due by midnight tonight Discussion groups now.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Aalborg Media Lab 28-Jun-15 Software Design Lecture 8 “Arrays”
Unit 031 Interfaces What is an Interface? Interface Declaration Syntax Implementing Interfaces Using Interfaces as Types Interfaces and Inheritance Interfaces.
GUI. Swing Class Hierarchy Swing Components Swing Conatiners  JFrame – top-level window to store components.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 7: Oct 4-8, 2010 Aditya Mathur Department of Computer Science Purdue University.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 11: Oct 31-Nov 4, 2011 Aditya Mathur Department of Computer Science Purdue.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 3: September 6-10, 2010 Aditya Mathur Department of Computer Science Purdue.
More Event Handling Adapters Anonymous Listeners Pop menus Validating User Input.
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington More Interfaces.
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
 Definition: An event is an object thrown in response to a user of programmatic action  Definition: A listener is a series of methods that executes in.
Applications Development
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington More Interfaces.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
For (int i = 1; i
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
Understand the difference between applets and applications Identify meaningful applet resources for academic subjects Create and demonstrate a basic Java.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
CS 151: Object-Oriented Design October 31 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 12: Nov 8-12, 2010 Aditya Mathur Department of Computer Science Purdue.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 11: Nov 1-5, 2010 Aditya Mathur Department of Computer Science Purdue University.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 14: Nov 21-25, 2011 Aditya Mathur Department of Computer Science Purdue.
CS 151: Object-Oriented Design October 1 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
A cannon game ?. Simple version angle from command line, one shot only Coordinate system is “upside-down”: Use dy(int) method to transform y coordinate:
CS Lecture 04 Mice Lynda Thomas
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 10: Oct 25-29, 2010 Aditya Mathur Department of Computer Science Purdue.
Mouse Events GUI. Types of Events  Below, are some of the many kinds of events, swing components generate. Act causing EventListener Type User clicks.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Events and Event Handling
“Form Ever Follows Function” Louis Henri Sullivan
GUI III IS
Programming in Java Event Handling
Event-driven programming for GUI
CS360 Client/Server Programming Using Java
CS Problem Solving and Object Oriented Programming Spring 2019
CS Problem Solving and Object Oriented Programming Spring 2019
CS Problem Solving and Object Oriented Programming Spring 2019
CS Problem Solving and Object Oriented Programming Spring 2019
CS Problem Solving and Object Oriented Programming Spring 2019
CS Problem Solving and Object Oriented Programming Spring 2019
Presentation transcript:

CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 9: Oct 18-22, 2010 Aditya Mathur Department of Computer Science Purdue University West Lafayette, IN, USA 1.Quiz 2.Creating GUIs 3.Frames, Panels, Buttons 4.Text fields 5.Action listeners 10/18 This Week: 1.GUI review 2.Interfaces and abstract classes 3.MouseListener and MouseAdapters 4.Examples 10/20

Readings and Exercises for Week 9 Readings: GUI: 12.2, 12.3 Exercises: 12.1, 12.6, /20/2010©Aditya Mathur. CS 180. Fall Week 92

Special Sessions Lab Help: Tuesday October 26, 5:30-7:30pm LWSN B158 Class: Sunday November 7, 4-6pm LWSN 3102AB 10/20/2010©Aditya Mathur. CS 180. Fall Week 93

Lunch meeting When: Thursday October 28, Noon-1:30pm Where: Ford Dining Hall Meet: Upstairs in the separate dining room Attendees:All are welcome Look forward to seeing you! 10/20/2010©Aditya Mathur. CS 180. Fall Week 94

Programming Competition Round 1 10/20/2010©Aditya Mathur. CS 180. Fall Week 95

Quiz: 10/18/ /20/2010©Aditya Mathur. CS 180. Fall Week 96

Q1. float [] a=new float[100]; Number of elements in array a is (a)101 (b)100 (c)99 (d)102 10/20/2010©Aditya Mathur. CS 180. Fall Week 97

Q2. int [] a=new int[100]; Correct values of the index into a range from (a)0 to 100 (b)1 to 100 (c)0 to 99 (d)1 to 99 10/20/2010©Aditya Mathur. CS 180. Fall Week 98

Q3. boolean [][] a=new boolean [5][3]; Maximum number of values of type boolean that can be stored in a at any time is 10/20/2010©Aditya Mathur. CS 180. Fall Week 99 (a)5 (b)8 (c)3 (d)15

Q4. int [][] a=new int [5][]; Number of columns in a is 10/20/2010©Aditya Mathur. CS 180. Fall Week 910 (a)5 (b)undefined (c)0 (a)1

Q4. float [] a=new float [5]; for (int r=0; r<6; r++){ a[r]=7; } Which statement is correct? 10/20/2010©Aditya Mathur. CS 180. Fall Week 911 (a)Elements in a are initialized to 7 (b)There will be an index out of bounds exception (c)7 cannot be assigned to a variable of type float (d) r must be of type float

End of Quiz: 10/18/ /20/2010©Aditya Mathur. CS 180. Fall Week 912

GUIs 10/20/2010©Aditya Mathur. CS 180. Fall Week 913

10/20/2010©Aditya Mathur. CS 180. Fall Week 914 A simple GUI: Frame Title Color Border

10/20/2010©Aditya Mathur. CS 180. Fall Week 915 A simple GUI: Frame with a Panel and Four Buttons Button label Button Panel Background color

10/20/2010©Aditya Mathur. CS 180. Fall Week 916 Problem 1 Write a program to generate a GUI shown below. It has one button and one text box. The number of button clicks should be displayed in the text field.

10/20/2010©Aditya Mathur. CS 180. Fall Week 917 Live demo: Example 1

10/20/2010©Aditya Mathur. CS 180. Fall Week 918 Problem 2 Write a program to generate a GUI shown below. The GUI has two buttons labeled + and – and a text box. Clicking the plus button adds to the click count and clicking the minus button decrements it. The count is displayed in the text box.

10/20/2010©Aditya Mathur. CS 180. Fall Week 919 Live demo: Example 2

10/20/2010©Aditya Mathur. CS 180. Fall Week 920 Problem 3 Write a math game program to generate a GUI shown below. The GUI has two buttons labeled Div by 3 and Not Div By 3 and two text boxes. A random integer is displayed in one textbox and the player must decide whether or not it is divisible by 3. Score is displayed in the other text box. The game never ends unless the program is forcefully terminated.

10/20/2010©Aditya Mathur. CS 180. Fall Week 921 Live demo: Example 3

10/20/2010©Aditya Mathur. CS 180. Fall Week 922 Problem 3 based exercise Modify the Divide by 3 game so that it displays the total duration of the game in minutes and seconds in a separate text box.

10/20/2010©Aditya Mathur. CS 180. Fall Week 923 Project 2 performance Count: 237 Average: 85.2 Median: 96.0 Maximum: Standard Deviation: 30.79

10/20/2010©Aditya Mathur. CS 180. Fall Week 924 Method signatures, Interfaces and abstract classes More GUI

10/20/2010©Aditya Mathur. CS 180. Fall Week 925 Method signatures: name and parameters: Yes void move (double dx, double dy); signature void move (int dx, int dy); signature void sort (int[] a); signature void sort (double[] a); signature distinct

10/20/2010©Aditya Mathur. CS 180. Fall Week 926 Method signatures: return type: NO boolean move (double dx, double dy); int move (double dx, double dy); Not distinct Even though return types are different

10/20/2010©Aditya Mathur. CS 180. Fall Week 927 Classes, Interface, and Abstract Classes Class Constructor, methods; used to create objects Interface: Class with only method signatures (abstract methods) An interface does not implement any method Methods are implemented by a class that uses the interface Thus, multiple implementations could exist

10/20/2010©Aditya Mathur. CS 180. Fall Week 928 Interface: Example 1 interface Car{ void cruise(double speed); // cruise at speed void startEngine(); // Start car engine void slowDown(double speed); // Slow down to speed double getSpeed(); // Returns current speed String getLicense(); // Returns license plate number } Abstract methods; not implemented

10/20/2010©Aditya Mathur. CS 180. Fall Week 929 Interface: Example 2 interface ActionListener{ void actionPerformed(ActionEvent); } A user class implements an ActionListener.

10/20/2010©Aditya Mathur. CS 180. Fall Week 930 Interface: Example 3 interface MouseListener{ void mouseClicked(MouseEvent e) void mouseEntered(MouseEvent e) void mouseExited(MouseEvent e) void mousePressed(MouseEvent e) void mouseReleased(MouseEvent e) } A user class iimplements a MouseListener.

10/20/2010©Aditya Mathur. CS 180. Fall Week 931 Interface: Example 1 : Implementation public class MyCar implements Car{ public void cruise(double speed){ // cruise at speed // Code to get car into cruise mode } public void startEngine(){ // Start car engine // Code to start the engine } …… // Other methods } Methods implemented

10/20/2010©Aditya Mathur. CS 180. Fall Week 932 Interface: When and why? Use an interface to specify a contract between two parties. When a team is developing an application, a core group of people can specify interfaces while other groups are free to implement these as they consider appropriate. Example: A car manufacturer can specify an interface that will be used by software developers of all models made by this manufacturer. Interfaces allow specification of uniform and contractual obligations across several products.

10/20/2010©Aditya Mathur. CS 180. Fall Week 933 Abstract class Similar to interface but may: Implement zero or more methods Provides abstract methods An abstract method is one with only a signature but no implementation A Java class can extend an abstract class by implementing one or more of its abstract methods.

10/20/2010©Aditya Mathur. CS 180. Fall Week 934 Abstract class: Example public abstract class MouseAdapter{ void mouseClicked(MouseEvent e){} void mouseEntered(MouseEvent e){} void mouseExited(MouseEvent e){} void mousePressed(MouseEvent e) {} void mouseReleased(MouseEvent e) {} } Empty implementations that may be overridden A user class extends a MouseAdapter.

10/20/2010©Aditya Mathur. CS 180. Fall Week 935 Problem Write a program to generate a GUI that has two buttons labeled Rose and Hibiscus and a text box. When the mouse enters Rose, the text box should display “Rose entered” and similarly for Hibiscus. When the mouse exits a button a similar message should be displayed. When a button is clicked, the Display should be “Rose clicked” and similarly for Hibiscus.

10/20/2010©Aditya Mathur. CS 180. Fall Week 936 Live demo

Week 9: October 18-22, 2010 Hope you enjoyed this week! Questions? Contact your recitation instructor. Make full use of our office hours. 10/20/2010©Aditya Mathur. CS 180. Fall Week 937