無名クラスの中で無名クラスを使いつつ,初期化用のメソッドまで呼んでいる分かりにくいコードを書いてみた.
xpane.add(delTabButton = new JButton(){ // "Del Tab" ボタン
JButton init(){
setText("Del Tab");
addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
delTab();
}
});
return this;
}
}.init());
init() が this をリターンしているのが鍵ですな.
- Newer: AWK - はじめ