Lecture 20 April 13, 2000
Review for Exam All Exercises and Sample Code from Lectures Object Based Programming Object Oriented Programming String and StringBuffer Operations Input/Output Exception Management Event Management GUI Design
Object Based Programming Reference Variables Objects hold instance fields and a reference to the class object. Class objects hold static fields, pointers to both static and instance methods, and a reference to the direct superclass object. Static, instance, local, and block-local variables. Public, private, and package access.
Object Oriented Programming Class Hierarchies –The “isa” relationship –Inheritance of methods and fields Exercise 5 –The super keyword –The super() method –Protected access Classes and Interfaces –Defining vs Declaring –Abstract Classes
String and StringBuffer Operations Exercises 6a and 6b Mutable or not Relative Efficiency Methods Available
Input/Output Class java.io.File Classes for reading/writing characters –BufferedReader, FileReader –BufferedWriter, FileWriter Classes for reading/writing bytes –FileInputStream –FileOutputStream Need to close output files.
Exception Management An Exception is … –The Exception class hierarchy. –Checked/Unchecked exceptions. The throw, throws, try, catch, and finally keywords. javadoc tag.
Event Management An Event is … –Event classes Event Listener Interfaces Event Adapter Classes Callback Methods Using anonymous classes to define listener objects.
GUI Design Classes –JFrame –JMenuBar –JMenu –JMenuItem
Action Listener Strategies Simple is Better … –Separate Listeners for Each Active Component Simple: Each actionPerformed() method deals only with events from a particular component. Complex: There can be a lot of actionPerformed() methods, each with its own (anonymous) class. –One Listener for All Events Simple: Only one actionPerformed() method. Complex: The actionPerformed() method must test each ActionEvent to see which component it came from, and then branch to the appropriate code for that component. [ ActionListener_ex.java ]ActionListener_ex.java