package com.fun.animator.input;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import com.fun.animator.AnimatorInitializer;
import com.fun.animator.LifeCycle;

public class ImageTransformerFrame extends JFrame implements LifeCycle {

    private ImagePanel depthImagePanel;
    private ImagePanel transformedImagePanel;
    private BufferedImage depthImage;
    private BufferedImage transformedImage;

    ImageTransformerFrame() {
        super("ImageTransformationTest");
    }

    @Override
    public void createComponents() {
        depthImagePanel = new ImagePanel("DepthImage", Color.GREEN);
        transformedImagePanel = new ImagePanel("TransformedImage", Color.GREEN);
    }

    @Override
    public void createLayout() {
        getContentPane().setLayout(new BorderLayout());
        JPanel imagesPanel = new JPanel();
        BoxLayout layout = new BoxLayout(imagesPanel, BoxLayout.LINE_AXIS);
        imagesPanel.setLayout(layout);
        imagesPanel.add(wrapImagePanel(depthImagePanel));
        imagesPanel.add(wrapImagePanel(transformedImagePanel));
        getContentPane().add(imagesPanel, BorderLayout.CENTER);
    }

    @Override
    public void registerHandlers() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void initialize() {
        InputStream resourceAsStream = getClass().getResourceAsStream("/kinect-depth.png");
        try {
            depthImage = ImageIO.read(resourceAsStream);
            resourceAsStream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        transformedImage = new DefaultDepthImageTransformers().convertDepthImage(depthImage);
        depthImagePanel.setImage(depthImage);
        transformedImagePanel.setImage(transformedImage);
    }

    private JPanel wrapImagePanel(ImagePanel imagePanel) {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new LineBorder(Color.BLACK, 2)));
        panel.add(imagePanel);
        return panel;
    }

    public static void main(String [] argv) {
        ImageTransformerFrame frame = new ImageTransformerFrame();
        AnimatorInitializer.init(frame);
        frame.pack();
        frame.setSize(800, 320);
        frame.setVisible(true);
    }
}

@@ -41,24 +41,96 @@
 java.awt.*;%0A
+import java.awt.event.WindowAdapter;%0Aimport java.awt.event.WindowEvent;%0A
 import java.
@@ -209,16 +209,182 @@
 tStream;
+%0Aimport java.util.*;%0Aimport java.util.Timer;%0Aimport java.util.concurrent.Executor;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;
 %0A%0Aimport
@@ -871,16 +871,70 @@
 edImage;
+%0A    private java.util.Timer taskRunner = new Timer();
 %0A%0A    Im
@@ -1775,16 +1775,240 @@
 CLOSE);%0A
+        addWindowListener(new WindowAdapter() %7B%0A            @Override%0A            public void windowClosing(WindowEvent e) %7B%0A                taskRunner.cancel();%0A                taskRunner.purge();%0A            %7D%0A        %7D);%0A
     %7D%0A%0A 
@@ -2533,24 +2533,263 @@
 rmedImage);%0A
+        taskRunner.scheduleAtFixedRate(new TimerTask() %7B%0A            @Override%0A            public void run() %7B%0A                depthImagePanel.repaint();%0A                transformedImagePanel.repaint();%0A            %7D%0A        %7D, 1000, 20);%0A
     %7D%0A%0A    p

Use a timer to continually refresh images