package class8_2_BlurringWithBufferedImage; import javax.swing.JPanel; import javax.swing.Timer; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * This panel represents a panel that runs steps on an image filter * and displays them to the user. */ public class VideoImagePanel extends JPanel { private Filterer filterer; private Timer timer; /** * Create the image panel. */ public VideoImagePanel() { setPreferredSize(new Dimension(512, 512)); // TODO: Use named constants or variables filterer = new ImageBlurrer(); timer = new Timer(16,new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filterer.doFilterStep(); repaint(); } }); } /** * Start the timer which will cause blurring to occur * (see action listener in constructor) */ public void startBlurring() { timer.start(); } /** * For Swing, we should override paintComponent instead of paint. * the actual paint calls paintComponent after painting the borders * and before painting the children. * @param g what to paint on */ @Override public void paintComponent(Graphics g) { setSize(512,512); super.paintComponent(g); Dimension size = super.getSize(); System.out.println("component size: " + size.getWidth() + "x" + size.getHeight()); boolean isDoneDrawing = g.drawImage(filterer.getImage(), 0, 0, null); if(!isDoneDrawing) { System.out.println("Warning: Not done drawing."); } } }