NotesWeek10.Oct 25-29 - CS 180 Problem Solving and Object...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 180 Problem Solving and Object Oriented Programming Fall 2010 hMp://www.cs.purdue.edu/homes/apm/courses/CS180Fall2010/ This Week: Notes for Week 10: Oct 2529, 2010 Aditya Mathur 10/25 1. Quiz 2. GUI review 3. Menus MenuListener 2. KeyListener 3. Methods 10/27 1. Department of Computer Science Purdue University West LafayeMe, IN, USA Readings and Exercises for Week 10 Readings: GUI: 12.2, 12.3 Exercises: 12.16, 12.17, 12.22 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Special Sessions Lab Help: Tuesday October 26, 5:307:30pm LWSN B158 Project 3 Due: Wednesday Oct 27, 2010 Class: Sunday November 7, 46pm LWSN 3102AB 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Lunch meeang When: Thursday October 28, 2010. Noon1:30pm Where: Ford Dining Hall Meet: Upstairs in the separate dining room AMendees: All are welcome Look forward to seeing you! 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Quiz: 10/25/2010 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Q1. AcaonListener is (a) An object (b) A variable (c) An interface (d) A method 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Q2. When using an interface we must implement (a) all methods in the interface (b) Only the methods needed by the class (c) Only the acaonPerformed() method (d) Any one method in the interface 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Q3. MouseListener is (a) An object (b) A variable (c) An interface (d) A method 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Q4. A method used to find the object that generated an AcaonEvent is (a) acaonPerformed() (b) addAcaonListener() (c) getSource() (d) addMouseListener() 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Q5. JTextField message=new JTextField("10"); creates a text field named message (a) with 10 columns (b) with the default number of columns and displays an empty string (c) with 10 columns and displays 10 (d) with 10 columns and displays a string consisang of 10 spaces 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Q6. When using an abstract class we must implement (a) All methods in the abstract class (b) Only the methods needed by the class (c) Only the acaonPerformed() method (d) Any one method in the abstract class 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Feedback: I am a CS major and plan to stay in CS. (a) Yes (b) No (c) Not applicable to me [I am not a CS major] 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Feedback: So far I am liking the course (10 liking a lot, 1 not liking at all). (a) 810 (b) 47 (c) 13 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 End of Quiz: 10/25/2010 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Back to GUIs 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Review Widgets: frame, panel, buMon, text field AcaonListener and MouseListener acaon Performed() mouseEntered(), mouseExited(), mouseClicked(), mousePressed(), mouseReleased getSource() ImageIcon Interface and abstract class Aditya Mathur. CS 180. Fall 2010. Week 10 10/27/2010 Problem 1 Write a program to generate the GUI shown next. It has a menu bar with two menus labeled College and Major and one text box. College has three menu items: Purdue, IU, and Notre Dame. Major has two menu items: CS and History. The text box must display the item and the major selected. 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Problem 1: GUI: Menu Items: College 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Problem 1: GUI: Menu Items: Major 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Live demo: Example 1 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Problem 2 Modify the previous program so that the GUI now responds to menu selecaon events. The detected event is displayed in a message text field. The selected college is displayed in the College choice text field and the selected major in the Major choice text field. If Purdue is selected then add Computer Engineering to Majors. Delete this major if IU or Notre Dame are selected. 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 MenuListener The following methods must be implemented: menuSelected(MenuEvent m) menuDeselected(MenuEvent m) menuCanceled(MenuEvent m) 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Live demo: Example 2 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Problem 3 Write a program that creates three text boxes. Box 1 has the iniaal focus. When a string is typed in box 1 and enter pressed, the typed string is echoed in box 3 and the focus moves to box 2 When a string is typed in box 3, it is echoed in box 3 an the focus switches to box 1. 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 KeyListener The following methods must be implemented: keyTyped(KeyEvent m) keyPressed(KeyEvent m) keyReleased(KeyEvent m) If k is a KeyEvent object then k.getChar() returns the character typed. k.VK_ENTER is the code for the enter key. 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Live demo: Example 3 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Problem 4 [Try on your own] Write a math game program to generate a GUI shown below. The GUI has two buMons 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/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Live demo: Example 3 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Problem 3 based exercise Modify the Divide by 3 game so that it displays the total duraaon of the game in minutes and seconds in a separate text box. 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 Week 10: October 2529, 2010 Hope you enjoyed this week! Quesaons? Contact your recitaaon instructor. Make full use of our office hours. 10/27/2010 Aditya Mathur. CS 180. Fall 2010. Week 10 ...
View Full Document

This note was uploaded on 02/05/2012 for the course CS 180 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Ask a homework question - tutors are online