comparison game/IDMContainer.java @ 49:e6da5c71be28

Add more code to IDM widgets, do preliminary work for integrating them.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Feb 2011 10:52:08 +0200
parents
children 496e616ff09d
comparison
equal deleted inserted replaced
48:f13bab4cccd3 49:e6da5c71be28
1 /*
2 * Ristipolku IDM widget container
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
4 */
5 package game;
6
7 import java.awt.*;
8 import java.awt.event.*;
9 import java.util.*;
10
11
12 public class IDMContainer extends IDMWidget
13 {
14 ArrayList<IDMWidget> widgets;
15
16 public IDMContainer()
17 {
18 widgets = new ArrayList<IDMWidget>();
19 }
20
21 public void add(IDMWidget widget)
22 {
23 widgets.add(widget);
24 }
25
26 public void paint(Graphics2D g)
27 {
28 for (IDMWidget widget : widgets)
29 widget.paint(g);
30 }
31
32 public void mousePressed(MouseEvent e)
33 {
34 for (IDMWidget widget : widgets)
35 {
36 if (widget.contains(e.getPoint()))
37 widget.mousePressed(e);
38 }
39 }
40
41 public void mouseReleased(MouseEvent e)
42 {
43 for (IDMWidget widget : widgets)
44 {
45 widget.mousePressed(e);
46 }
47 }
48
49 public boolean keyPressed(KeyEvent e)
50 {
51 for (IDMWidget widget : widgets)
52 {
53 if (widget.keyPressed(e))
54 return true;
55 }
56 return false;
57 }
58 }