View Javadoc

1   /*
2    * AI Soccer Project - network gaming environment for AI warriors.
3    * Copyright (C) 2001-2004  Marcin Werla, Pawel Widera
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, you can find it here:
17   * http://www.gnu.org/licenses/gpl.html
18   */
19  
20  package aigames.soccer.observer;
21  
22  import java.awt.Graphics;
23  import java.awt.Image;
24  
25  import javax.swing.JPanel;
26  
27  
28  /***
29   * Panel for a field drawing.
30   * @version $Id: FieldPanel.java,v 1.4 2004/05/08 21:55:28 mwerla Exp $
31   */
32  public class FieldPanel extends JPanel {
33      private Image buffer = null;
34  
35      /***
36       * Panel constructor.
37       */
38      public FieldPanel() {
39          super();
40          setOpaque(true);
41      }
42  
43      /***
44       * Switch panel image.
45       * @param buffer
46       */
47      public void setImage(Image buffer) {
48          this.buffer = buffer;
49      }
50  
51      /***
52       * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
53       */
54      protected void paintComponent(Graphics g) {
55          if (null == buffer) {
56              super.paintComponent(g);
57          } else {
58              g.drawImage(buffer, 0, 0, getBackground(), this);
59          }
60      }
61  }