Source code: myComponents/ImagePanel.java
1 /* Evolvo - Image Generator
2 * Copyright (C) 2000 Andrew Molloy
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 package myComponents;
20
21 import java.awt.Image;
22 import java.awt.Graphics;
23 import java.awt.Dimension;
24 import java.awt.event.*;
25 import javax.swing.event.*;
26 import javax.swing.JFrame;
27 import javax.swing.JPanel;
28 import exptree.utilities.*;
29
30 public class ImagePanel extends JPanel implements ChangeListener
31 {
32
33 final Image image;
34
35 public ImagePanel(imageGenerator imgG)
36 {
37 super();
38 image = imgG.getImage();
39 imgG.addChangeListener(this);
40 }
41
42 public Dimension getPreferredSize()
43 {
44 return new Dimension(image.getWidth(this), image.getHeight(this));
45 }
46
47 public Image getImage()
48 {
49 return image;
50 }
51
52 protected void paintComponent(Graphics g)
53 {
54 super.paintComponent(g);
55 g.drawImage(image, 0, 0, this);
56 }
57
58 public void stateChanged(ChangeEvent e)
59 {
60 repaint(); // Schedule a paint()
61 }
62 }