Shaun Conlon CS 211 Section 6 3/6/2003 Notes Topics for this week: -P1 Questions -A4 Questions -Event Model -Timer 1) P1 Questions: Questions on the prelim will be: 1 - Short Answer 2 - Induction 3 - Inheritance 4 - Recursion 5 - Parsing 6 - Lists Bonus - ??? You should make sure you understand the lecture notes and assignments, using the textbook to supplement any unclear material. 2) A4 Questions You should pay close attention to the examples posted on the Assignments page. The Example1 and Example2 files have the basics of your animation written for you. By adapting his code to the puzzle, you shouldn't have too much trouble. I would recommend getting the puzzle to work completely with clicking the pieces before you add the solve functionality. 3) Event Model Here are some important points about the event model: -Many, many things in a GUI will generate an event (e.g. clicking a button, clicking the mouse, moving the mouse, dragging the mouse, moving the window, resizing the window, closing the window, etc.) -When an event occurs, Java sends information about the event to appropriate listeners that have already registered to receive that event -If no listener is assigned to receive a particular event, nothing will happend when it occurs (e.g. nothing happens when the mouse is clicked in the background of your GUI because there is no listener for that event) -When writing code, you only need to create listeners for the events that matter to your application There are multiple ways to create listeners: 1) Use the GUI class itself as a listener (e.g. addActionListener(this)) 2) Use another class as a listener (e.g. addActionListener(new MyListener()) 3) Use an anonymous class as a listener (e.g. addActionListener(new ActionListener() {...) The most popular approaches are 1 and 3, because 2 requires many other classes to be written for substantial GUIs. Your listeners will usually be implementing certain interfaces from the java.awt.event package (e.g. ActionListener, WindowListener, etc.). The API also has some classes that are designed for convenient GUI design (e.g. WindowAdapter). 4) Timer Because of the way Java is implemented, you cannot have your solve method simply solve the puzzle completely in one pass if you want to have an interrupt button. So, for the solve animation, you have to use either Timer or another way. Note: you don't have to use Timer for the animation. Using threads is also allowed (although Timer is probably easiest for most people). A Timer works by sending an event to a specified listener again and again with a specified delay between sucessive events. You can use this for the solve animation for the puzzle - you will create a timer that generates an event that does one move of the solution. The interrupt button will stop your Timer. Email me (sc235) with any questions.