import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; /** * @author Prof. Wittie CS 203, Fall 2009 */ @SuppressWarnings("serial") /* * A component. This component holds one olive. The olive is instantiated * elsewhere so that it can be altered and repainted. */ public class OliveComponent extends JComponent { private Olive olive; // A constructor which takes an Olive object /** * Constructs an olive component * * @param olive * an olive to display */ public OliveComponent(Olive olive) { this.olive = olive; } /* * (non-Javadoc) * * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; olive.draw(g2); } }