Download presentation
Presentation is loading. Please wait.
Published byLoreen Wilson Modified over 9 years ago
1
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 University West Lafayette, IN, USA http://www.cs.purdue.edu/homes/apm/courses/CS180Fall2010/ 1.Quiz 2.GUI review 3.Menus 10/25 This Week: 1.MenuListener 2.KeyListener 3.Methods 10/27
2
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
3
Special Sessions Lab Help: Tuesday October 26, 5:30-7:30pm LWSN B158 Project 3 Due: Wednesday Oct 27, 2010 Class: Sunday November 7, 4-6pm LWSN 3102AB 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
4
Lunch meeting When: Thursday October 28, 2010. Noon-1:30pm Where: Ford Dining Hall Meet: Upstairs in the separate dining room Attendees:All are welcome Look forward to seeing you! 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
5
Quiz: 10/25/2010 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
6
Q1. ActionListener is (a)An object (b)A variable (c)An interface (d)A method 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
7
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 actionPerformed() method (d)Any one method in the interface 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
8
10/27/2010 Q3. MouseListener is (a)An object (b)A variable (c)An interface (d)A method ©Aditya Mathur. CS 180. Fall 2010. Week 10
9
Q4. A method used to find the object that generated an ActionEvent is 10/27/2010 (a)actionPerformed() (b)addActionListener() (c)getSource() (a)addMouseListener() ©Aditya Mathur. CS 180. Fall 2010. Week 10
10
Q5. JTextField message=new JTextField(“10”); creates a text field named message 10/27/2010 (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 consisting of 10 spaces ©Aditya Mathur. CS 180. Fall 2010. Week 10
11
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 actionPerformed() method (d)Any one method in the abstract class 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
12
Feedback: I am a CS major and plan to stay in CS. 10/27/2010 (a)Yes (b)No (c)Not applicable to me [I am not a CS major] ©Aditya Mathur. CS 180. Fall 2010. Week 10
13
Feedback: So far I am liking the course (10 liking a lot, 1 not liking at all). 10/27/2010 (a)8-10 (b)4-7 (c)1-3 ©Aditya Mathur. CS 180. Fall 2010. Week 10
14
End of Quiz: 10/25/2010 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
15
Back to GUIs 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
16
Review 10/27/2010 Widgets: frame, panel, button, text field ActionListener and MouseListener action Performed() mouseEntered(), mouseExited(), mouseClicked(), mousePressed(), mouseReleased getSource() ImageIcon Interface and abstract class ©Aditya Mathur. CS 180. Fall 2010. Week 10
17
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. ©Aditya Mathur. CS 180. Fall 2010. Week 10
18
10/27/2010 Problem 1: GUI: Menu Items: College ©Aditya Mathur. CS 180. Fall 2010. Week 10
19
10/27/2010 Problem 1: GUI: Menu Items: Major ©Aditya Mathur. CS 180. Fall 2010. Week 10
20
10/27/2010 Live demo: Example 1 ©Aditya Mathur. CS 180. Fall 2010. Week 10
21
10/27/2010 Problem 2 Modify the previous program so that the GUI now responds to menu selection 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. ©Aditya Mathur. CS 180. Fall 2010. Week 10
22
10/27/2010 MenuListener The following methods must be implemented: menuSelected(MenuEvent m) menuDeselected(MenuEvent m) menuCanceled(MenuEvent m) ©Aditya Mathur. CS 180. Fall 2010. Week 10
23
10/27/2010 Live demo: Example 2 ©Aditya Mathur. CS 180. Fall 2010. Week 10
24
10/27/2010 Problem 3 Write a program that creates three text boxes. Box 1 has the initial 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. ©Aditya Mathur. CS 180. Fall 2010. Week 10
25
10/27/2010 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. ©Aditya Mathur. CS 180. Fall 2010. Week 10
26
10/27/2010 Live demo: Example 3 ©Aditya Mathur. CS 180. Fall 2010. Week 10
27
10/27/2010 Problem 4 [Try on your own] 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. ©Aditya Mathur. CS 180. Fall 2010. Week 10
28
10/27/2010 Live demo: Example 4 ©Aditya Mathur. CS 180. Fall 2010. Week 10
29
10/27/2010 Problem 4 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. ©Aditya Mathur. CS 180. Fall 2010. Week 10
30
Week 10: October 25-29, 2010 Hope you enjoyed this week! Questions? Contact your recitation instructor. Make full use of our office hours. 10/27/2010 ©Aditya Mathur. CS 180. Fall 2010. Week 10
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.