// APS101, Winter 2009: Lecture 7 (Jan. 22) // // Review: last time you started writing your own programs. // We wrote a customized JFrame class. // We also learned learned a lot of new terminology: ? What are the three types of methods? function: returns a data type constructor: creates an object and returns it procedure: does something, but doesn't return any data ? What's the difference between an argument and a parameter? argument: the exact value that is being passed into a method parameter: an abstract definition of the input that the method takes in ? When would you use "this"? "this" is used to refer to the current object. you put "this." in front of all instance variables and instance methods ? What's the process of writing a program? you start with a .java file, then compile it, then get .class file Be careful about .java~ backups! // let's review the methods we have already written OurJFrame ow = new OurJFrame("This is OUR JFrame!"); ow.doubleWidth() ow.doubleWidth() ow.getOurTitle() // let's initialize the value of instance variable ourTitle OurJFrame ow = new OurJFrame("This is OUR JFrame!"); ow.getOurTitle() // let's write a 2nd constructor method & a procedure called flip() OurJFrame ow = new OurJFrame("This is OUR JFrame!", 500, 100); ow.flip() // let's write a procedure called makeSquare() OurJFrame ow = new OurJFrame("This is OUR JFrame!", 500, 100); ow.makeSquare() // let's write a 3rd constructor method OurJFrame ow = new OurJFrame(); ow.getOurTitle() // IMPORTANT RULES TO FOLLOW: // (1) make instance variables private, unless otherwise specified (use public "getter" methods to access private variables) // (2) make instance methods public, unless it's a "helper method", which is intended to be used only inside the class. A a = new A(); a.x a.x = 6; a.x B b = new B() b.y // 2 MORE IMPORTANT RULES: // (3) always put "this." in front of all instance variables and methods // (4) when declaring a new variable, always specify its type i.e., "int n = 5" vs. "n = 5"