對話框通常只會出現一下下, 用來提示使用者採取某些行動. 當使用者做完決定後, 這個對話框就會消失.
使用匿名類別顯示一個對話框, 亦即建立一個匿名的實體. 當運行完這個對話框後, 系統會自行回收這個匿名實體所佔用的記憶體空間, 從而讓程式在運行中不會佔到不必要的記憶體空間.
2010年5月20日 星期四
Java Nested Classes: this
http://mindprod.com/jgloss/this.html
"this" means the current object, the instance we are currently running a method on.
Beware, inside an (anonymous) inner class, "this" refers to the inner class, not the usual enclosing one. If the outer class were called MyOuter, you could get at its this with "MyOuter.this".
Example:
"this" means the current object, the instance we are currently running a method on.
Beware, inside an (anonymous) inner class, "this" refers to the inner class, not the usual enclosing one. If the outer class were called MyOuter, you could get at its this with "MyOuter.this".
Example:
public class MyClass { private String outerClassField = "some value"; public void outerClassMethod() { someObject.addMyListener(new MyListener() { public void processEvent(MyEvent e) { MyClass.this.outherClassField; } }); } }
訂閱:
文章 (Atom)