Unformatted text preview:

Software Design10.1Toward a GUI-programming modelz We want to adhere to language-independent ideals¾ Concepts move from GUIs in Java to …¾ javax.swing and java.awt offer thousands of choices• Too many to have to understand/find comfort in, but …z We want to write reasonable, robust , GUI applications¾ Actually write code, not simply adhere to lofty ideals¾ Show me the code!z Simple, extensible, re-usable conceptual framework¾ How to develop GUIs, how to extend¾ Ask QuestionsSoftware Design10.2One GUI Conceptual Frameworkz Create a JPanel for the GUI contentPane¾ Provide a BorderLayout, organize hierarchically¾ Ok to use GridLayout, FlowLayout, … nestedz Create Buttons, Menu-items, and other widgets¾ Bind each event-generator to a listener¾ Do not dispatch within a listener on event source• No "if event-generator is button A do this"z Use anonymous inner classes, or named inner classes¾ Process events, created and attached close-to-source¾ Make a button, make a button-listenerSoftware Design10.3Click on a button, display the clickActionListener textDisplayer = new ActionListener(){public void actionPerformed(ActionEvent e){showText(e.getActionCommand());}};z What does an ActionListener do?¾ Listens for an event, e.g., from Button, Menu, …¾ Processes the command/eventz How do anonymous classes work?¾ Note: ActionListener is an interface, but object created!¾ See what Eclipse refactoring will do with thisSoftware Design10.4Making a Move: View and ControllerActionListener moveMaker = new ActionListener(){public void actionPerformed(ActionEvent e){int val = Integer.parseInt(e.getActionCommand());myControl.makeMove(new PuzzleMove(val));}};z We know this will be bound to a specific type of button¾ Not generic, completely application specific¾ Turns swing/GUI event into application event: Movez Controllers should be programmed abstractly¾ Don't base code on a GUI toolkit, separate


View Full Document

Duke CPS 108 - Lecture

Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?