Thinking in Objects
Outline The this Reference [Sample code] PressEnter.java
The this Reference Public class Foo { int i = 5; static double k = 0; void setI(int i) { this.i = i; } static void setK(double k) { Foo.k = k; } Suppose that f1 and f2 are two objects of Foo. Invoking f1.setI(10) is to execute this.i = 10, where this refers f1 Invoking f2.setI(45) is to execute this.i = 45, where this refers f2 ( The this keyword is name of a reference that refers to a calling object itself. )
程式練習 : (16 進位轉 10 進位 ) 1. 輸入一個 16 進位數, 例如 : F 2. 印出它的 10 進位數, F 15
程式範例 : ( 判斷鍵盤按下 Enter 鍵 ) PressEnter.java
GUI File Dialogs 程式範例 : ( 視窗介面檔案選擇 ) Listing 9.10 ReadFileUsingJFileChooser.java