1 / 15

CSSE221: Software Dev. Honors Day 9

This CSSE221 honors class covers GUI programming using Java's Swing library, focusing on event-driven programming and the use of listeners. Students will learn how to respond to user input, implement event listeners, and design GUIs using UML. The class also emphasizes the importance of iterative enhancement plans and provides hands-on coding exercises.

greear
Download Presentation

CSSE221: Software Dev. Honors Day 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSSE221: Software Dev. Honors Day 9 • Announcements • HW3 passed back, follow link from HW3 to its solution. • Questions on GUIs? • No baby yet…

  2. Capsule Deliverables • Please email the quiz, key, and summary to me by 7:30 am on the day you are presenting. • Send .doc files • (If you get them to me by 3pm on a weekday before you present, I’ll still print them) • Lessons from week 1: • Nice research and summarization! • Proofread your stuff. Everyone else will see it. • 1-page quizzes are good (or staple) • Summaries don’t have to be verbose, just dense with info.

  3. This week: Fifteen assignment • Monday: • GUIs using Java’s Swing library • Tuesday: • Fifteen specification • EventListeners: responding to user input • Intro to UML as a design tool • Time to work on project • Thursday: • Anonymous classes (capsule) • Function objects and comparators (capsule)

  4. “Fifteen” Questions on Specification?

  5. Fifteen Teams Repos is csse221-200810-<usr1>-<usr2>. If solo, use your personal repos. • beltonj1-fishmad • bennetrn-leveyjr • bennindp-speyerea • crockeea-morrisps • devorejd-priestjs • lundgrpb-skilessa • johnsoad-smithny • sullivja-wentztj • mcginnda Discuss how to pair-program

  6. Event-driven Programming: What? • We want our program to respond to events • Mouse motion, mouse clicks, button presses, menu selections, … • The Java window manager generates a huge number of events • Whenever any of these happen • We need to listen for specific events class Foo implements MouseListener { … }

  7. Event-driven Programming: How? • Implement the BlahListener interface class Foo implements MouseMotionListener { … // We promise to implement these. void mouseDragged(MouseEvent e) { System.out.println(“Hey, stop pulling me!”); } void mouseMoved(MouseEvent e) { System.out.println(“The mouse is moving!”); System.out.println(e.getX() + “ “ + e.getY()); } }

  8. Event-driven Programming: Which? Interface, that is… • MouseMotionListener • For receiving mouse motion events (movement and dragging) on a component. • MouseListener • For clicks and other mouse events (click and double-click, mouse enters component) • ActionListener • For component-defined actions (such as pressing a button) • KeyboardListener • ChangeListener • For components in which we only care about change (like sliders) See the API spec. for which methods you need to write

  9. Listeners • Need 3 things! • Responder implements ActionListener interface • This means it implements actionPerformed method: public void actionPerformed(ActionEvent e) { // what happens when button is pressed } • The responder must add the listener: Say a frame has a button. this.button.addActionListener(this); Listens Responds (this is the frame, but could be a panel or even the button itself)

  10. E.g. Button in a Panel • Button is the event source • Panel has to respond to the event and therefore must listen for events. public TopPanel extends JPanel implements ActionListener { private JButton changeColor; … public TopPanel(){ this.changeColor = new JButton(“Click to change color”); this.changeColor.addActionListener(this); //Add the listener to the source this.add(changeColor); } public void actionPerformed(ActionEvent e){ //Change the background color of the panel } }

  11. Do I have to write a whole separate class in its own file, just for an actionPerformed method? • No! You could use an anonymous class or a function object • More on those next class • Funny that that’s the ordering of topics…

  12. Finish demo together • Draw the UML for all classes so far • Add the listeners. • What other connections do I need? • Look at its Iterative Enhancement Plan together • Code • Sliders are similar, I used the Java Swing Tutorial for some ideas.

  13. Start Fifteen Spec now • You need to do 2 things before you start coding: • Show us your UML • Show us your Iterative Enhancement Plan

  14. UML ideas • List of components • For each component • Extends a class? • Implements interfaces? • Creates instances of other components? • Has instances of other components? • For which objects can I use the default Java version and which do I need to extend? • Frames, panels: extend • Text boxes: use Java’s • Buttons: it depends • Do now with another team (so groups of 4) on a whiteboard.

  15. Iterative enhancement plan • Iterative enhancement plan: • A series of stages (and substages) • by which to develop the application, • with each stage testable by running the application • Such a plan ensures that you always have code that works • Each stage must be testable by running the application • No looking at code! • So “implement the Dud class” is NOT part of an iterative enhancement plan • It is OK for some stages to include throw-away code • The stages should be about the same size/difficulty

More Related