プログラマメモ2 - programmer no memo2

コントローラーを重ねる 2008/01/30

データオブジェクトを操作するためのクラスを積み重ねる。




import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

public class TestPanel extends JPanel {

private static final long serialVersionUID = 1L;

public static void main(String[] args) {
}

public TestPanel() {
super();
initialize();
addMouseListener(new Controllers());
}


private void initialize() {
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
}

class Controllers extends MouseAdapter{
List<Controller> list = new ArrayList<Controller>();

@Override
public void mousePressed(MouseEvent e) {
for (Controller controller : list) {
controller.mousePressed(e);
}
}
}

class Controller extends MouseAdapter{

}
}

: