CSC223 2004F, Class 20: Swing (2) Admin: * Sam Martin rules! * No classes for the rest of this week * Does every group have someone who has used Swing? * New homework! * Reading: (Object-Oriented Heuristics) Read the big hardcover book that's not design patterns (due Monday after break) * Programming: Build a series of "draw grid element" methods (due Friday after break) * Russ says: * "Oh shit, what did we do wrong now?" * "Good luck, I'm thinking about you." Overview: * Discussion of new homework * Some swing design issues * Examples * Exercise (maybe) /Drawing one portion of the world/ * Decisions: * Represent the world as a collection of "grid points" (x,y) * Each grid point is, let's say, 1cm by 1cm * Each grid point contains * Some pheremone (byte) or pheremones * Zero or more bugs * Zero or more Other objects * "Terrain" * How do we show the world to the user? Possibly at different scales * Goal: Draw one grid point * "Small" size (for big overview of the world) * "Large" size (for close-up overview of a portion of the world) * Question: What size should our world be? * 100 x 100 * Question: About how many bugs? * 50 to 500 per colony * Question: What happens when a bug goes "north" from a northernmost space? (Similarly, "west" from westernmost and so on and so forth) * Death! * Wrap around. * Blocked/fenced. [*** DA WINNAH ***] * Question: Can bugs from one colony detect the pheremones of bugs from another colony? * Yes, seems more real world * A question we will return to later * Question: Can bugs from one colony distinguish "our pheremones" vs. "their pheremones"? * A question we will return to later. * Some ants do realease "propaganda pheremones" to confuse their enemies * Sam's quickly ad-libbed stupid name GUBS: Grinnell Universal Bug Simulator * Pronunciation: "Foo" * Sam's oldest joke: What does ghoti spell? * Detour: FISH philosophy Questions about today's homework ... * How do we test removeRange, which is protected? * Flaw in homework? * Solution: Subclass vector and make public removeRange About swing: * Reminder: * Build containers * Build things like buttons to add to the containers * Build listeners to add to the individual objects * Some design issues * How do you write listeners? (Examples ButtonOne, ButtonTwo, ButtonThree) * Create an anonymous inner class (ButtonsOne) * Make the enclosing class a listener (ButtonsTwo) * Create a separate class for listeners (ButtonsThree) * What are the advantages and disadvantages of each strategy? * Create an anonymous inner class (ButtonsOne) * What they did in 152 * Can get giant and clunky (Disadvantage) * Can write one listener for many objects (advantage). * Make the enclosing class a listener (ButtonsTwo) * Can write one listener for many objects (advantage). * Easy access to fields of the enclosing class. * Create a separate class for listeners (ButtonsThree) * Compartmentalizes (advantage) * Can write one listener for many objects (advantage). * How do you create the main frame? * Explicitly, with new JFrame() (NewHello.java) * By subclassing JFrame() (HelloFrame.java) * What are the advantages and disadvantages of each strategy? HAVE A GREAT BREAK!